Dear lists, Recently I've been working a bit on PGF/TikZ and many times I wished I had certain metrics that are available in regular programming languages. In particular I am missing: - A callback that is triggered when a macro is defined. This would allow me to trap when a cs is defined in the wrong place. That could probably be done by overriding `\def` but there are some gotchas with prefixes, e.g. `\long\def`. - A callback that is triggered when a token is expanded (or executed in the case of primitives). In conjunction with the previous request, this would allow me to measure code coverage by comparing which macros are defined and which ones are used. - Switches to trap on certain pathological events. For example I want to trap when TeX inserts a frozen \relax because a number couldn't be read. Another thing I want to trap is `Missing character: There is no <char> in font <font>!`. There are probably more silent TeX errors that I currently don't have in mind. Are these things possible in LuaTeX right now or could they be made possible in the future? Kind regards, Henri
On 12/28/2020 3:54 PM, Henri Menke wrote:
Dear lists,
Recently I've been working a bit on PGF/TikZ and many times I wished I had certain metrics that are available in regular programming languages. In particular I am missing:
- A callback that is triggered when a macro is defined. This would allow me to trap when a cs is defined in the wrong place. That could probably be done by overriding `\def` but there are some gotchas with prefixes, e.g. `\long\def`.
if you intercept for that reason you need to make the callback function situation aware which means that you can as well test things the tex which is way more efficient
- A callback that is triggered when a token is expanded (or executed in the case of primitives). In conjunction with the previous request, this would allow me to measure code coverage by comparing which macros are defined and which ones are used.
given the amount of expansion going on in the engine that would mean, for a reasonable large document, or for some complex macro package like pgf, many millions of Also, what exactly is 'expanded'. Some tokens are handled directly, some enter an expansion call, others are macros that themselves use expansion to even get started. Basically you want to check each token that is read or accessed from internal storage (lists). Adding granilarity means many callbacks (each one checking if it's defined, then setting up lua, call the function, and go back to tex). There's also a lot of pushback ging on. If you just hook into 'picking up a token', here are some numbers if we hook into that: making context lmtx format: 4M (million) simple tufte document with minimal font setup: 500K loading tikz (with patterns lib): 3M drawing simple pattern in tikz: 100K (1 cm circle with pdf pattern) 290 page luametatex manual: 105M (ok, latex is probably much more efficient than context but it gives an idea)
- Switches to trap on certain pathological events. For example I want to trap when TeX inserts a frozen \relax because a number couldn't be read. Another thing I want to trap is `Missing character: There is no <char> in font <font>!`. There are probably more silent TeX errors that I currently don't have in mind.
there is s missing glyph callback and with some juggling the 'no number' can be intercepted at the tex end ... you can set an error callback and look at the message
Are these things possible in LuaTeX right now or could they be made possible in the future? all is possile but this will not happen ... enabling callbacks like that would make luatex unuseable slow (which is probably not what you want because pgf is already kind of slow) (even checking for the callback being set takes time)
Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
participants (2)
-
Hans Hagen
-
Henri Menke