The history of luaTEX 2006–2009 / v 0.50 - Pragma ADE
The history of luaTEX 2006–2009 / v 0.50 - Pragma ADE The history of luaTEX 2006–2009 / v 0.50 - Pragma ADE
By combining Lua with TEX, we can do the conversion from calculator math to TEX immediately, without auxiliary programs or complex parsing using TEX macros. tex In a ConTEXt source one can use the \calcmath command, as in: The strange formula \calcmath {sqrt(sin^2(x)+cos^2(x))} boils down to ... One needs to load the module rst, using: \usemodule[calcmath] Because the amount of code involved is rather small, eventually we may decide to add this support to the MkIV kernel. xml Coding math in TEX is rather efcient. In xml one needs way more code. Presentation MathML provides a few basic constructs and boils down to combining those building blocks. Content MathML is better, especially from the perspective of applications that need to do interpret the formulas. It permits for instance the ConTEXt content MathML handler to adapt the rendering to cultural driven needs. The OpenMath way of coding is like content MathML, but more verbose with less tags. Calculator math is more restrictive than TEX math and less verbose than any of the xml variants. It looks like: sqrt(sin^2(x)+cos^2(x)) test And in display mode: sqrt(sin^2(x)+cos^2(x)) test speed This script (which you can nd in the ConTEXt distribution as soon as the MkIV code variants are added) is the rst real TEX related Lua code that I wrote; so far I had only written some wrapping and spell checking code for the SciTE editor. It also made a nice demo for a couple of talks that I held at usergroup meetings. The script has a lot of expressions. These convert one string into another. They are less powerful than regular expressions, but pretty fast and adequate. The feature I miss most is alternation like (l|st)uck but it's a small price to pay. As the Lua manual explains: adding a posix compliant regexp parser would take more lines of code than Lua currently does. 24 An example: CalcMath
On my machine, running this rst version took 3.5 seconds for 2500 times typesetting the previously shown square root of sine and cosine. Of this, 2.1 seconds were spent on typesetting and 1.4 seconds on converting. After optimizing the code, 0.8 seconds were used for conversion. A stand alone Lua takes .65 seconds, which includes loading the interpreter. On a test of 25.000 sample conversions, we could gain some 20% conversion time using the LuaJIT just in time compiler. An example: CalcMath 25
- Page 1: MKII CONTEXT CONTEXT The history of
- Page 4 and 5: XXI The luacation of TEX and ConTEX
- Page 6 and 7: 4 Introduction
- Page 8 and 9: Keep in mind that the functionality
- Page 10 and 11: tricky part of this conversion is t
- Page 12 and 13: prologues := 1 ; mpprocset := 1 ; W
- Page 14 and 15: code. However, the signicantly larg
- Page 16 and 17: \input zip:///somezipfile.zip?name=
- Page 18 and 19: ecause we could move all kind of po
- Page 20 and 21: If an acrhive is not a real TEX tre
- Page 22 and 23: luatools --generate This command wi
- Page 24 and 25: I know that it sounds a bit messy,
- Page 28 and 29: 26 An example: CalcMath
- Page 30 and 31: collapser was written. In the (pre)
- Page 32 and 33: 30 Going utf
- Page 34 and 35: In practice we prefer a more abstra
- Page 36 and 37: of making that table accessible for
- Page 38 and 39: Therefore, it will be no surprise t
- Page 40 and 41: {"special","pdf: 1 0 0 rg"}, {"font
- Page 42 and 43: some neat feature of \TeX, once you
- Page 44 and 45: OPENTYPE 144 17.571.732 ENC 268 782
- Page 46 and 47: The font denition callback intercep
- Page 48 and 49: When processing a not so large le b
- Page 50 and 51: letter 105 i spacer 32 letter 116 t
- Page 52 and 53: egister 2 3190 dimen other_char 50
- Page 54 and 55: This example uses an active charact
- Page 56 and 57: function tex.printlist(data) callba
- Page 58 and 59: 56 Token speak
- Page 60 and 61: Interesting is that upto now I didn
- Page 62 and 63: do end local function nextbyte(f) r
- Page 64 and 65: \ctxlua{collectgarbage("setstepmul"
- Page 66 and 67: Collecting tokens can take place in
- Page 68 and 69: where TEX has to convert to and fro
- Page 70 and 71: When experimenting with the new imp
- Page 72 and 73: It will be clear that here we colle
- Page 74 and 75: 72 Nodes and attributes t={ attr={
By combining Lua with TEX, we can do the conversion from calculator math to TEX immediately,<br />
without auxiliary programs or complex parsing using TEX macros.<br />
tex<br />
In a ConTEXt source one can use the \calcmath command, as in:<br />
<strong>The</strong> strange formula \calcmath {sqrt(sin^2(x)+cos^2(x))} boils<br />
down to ...<br />
One needs to load the module rst, using:<br />
\usemodule[calcmath]<br />
Because the amount <strong>of</strong> code involved is rather small, eventually we may decide to add<br />
this support to the MkIV kernel.<br />
xml<br />
Coding math in TEX is rather efcient. In xml one needs way more code. Presentation<br />
MathML provides a few basic constructs and boils down to combining those building<br />
blocks. Content MathML is better, especially from the perspective <strong>of</strong> applications that<br />
need to do interpret the formulas. It permits for instance the ConTEXt content MathML<br />
handler to adapt the rendering to cultural driven needs. <strong>The</strong> OpenMath way <strong>of</strong> coding is<br />
like content MathML, but more verbose with less tags. Calculator math is more restrictive<br />
than TEX math and less verbose than any <strong>of</strong> the xml variants. It looks like:<br />
sqrt(sin^2(x)+cos^2(x)) test<br />
And in display mode:<br />
sqrt(sin^2(x)+cos^2(x)) test<br />
speed<br />
This script (which you can nd in the ConTEXt distribution as soon as the MkIV code variants<br />
are added) is the rst real TEX related Lua code that I wrote; so far I had only written<br />
some wrapping and spell checking code for the SciTE editor. It also made a nice demo<br />
for a couple <strong>of</strong> talks that I held at usergroup meetings. <strong>The</strong> script has a lot <strong>of</strong> expressions.<br />
<strong>The</strong>se convert one string into another. <strong>The</strong>y are less powerful than regular expressions,<br />
but pretty fast and adequate. <strong>The</strong> feature I miss most is alternation like (l|st)uck but<br />
it's a small price to pay. As the Lua manual explains: adding a posix compliant regexp<br />
parser would take more lines <strong>of</strong> code than Lua currently does.<br />
24 An example: CalcMath