I am trying to define a length, (not a dimension)—using Lua. But, I am having trouble with the syntax. I think I am supposed to be using the same structures/prototypes as glue_spec
in order to still be able to use standard LaTeX length
macros on those new lengths.
Question 1: What is the way to define and set new lengths with just Lua?
Question 2: Is it correct that all "lengths" in LaTeX are Skip Nodes / Glue Nodes, and not Dimensions—and can be used with all of the standard length
macros? (\addtolength
, \setlength
, etc.)
From the LuaTeX documentation:
tex.setskip (["global",] <number> n, <node> s)
tex.setskip (["global",] <string> s, <node> s)
<node> s = tex.getskip (<number> n)
<node> s = tex.getskip (<string> s)
The best I have been able to interpret everything I have read is:
local name = "MyLength";
local newLengthCommand =
"\\newlength{\\" .. name .. "}";
% *** Actually Creates a New Length ...
tex.sprint(newLengthCommand);
local setLengthCommand =
"\\setlength{\\" .. name .. "}{1in}";
% ***** Doesn't actually execute and set length ... why?
tex.sprint(setLengthCommand);
% ***** Debug to be sure syntax was right ...
-- tex.sprint("\\par\\verb|" .. newLengthCommand .. "|");
-- tex.sprint("\\verb|" .. setLengthCommand .. "|");
% **** Many Fails trying to hack registers ...
local gluespec = node.new(node.id("glue_spec"));
gluespec.width = tex.sp("1in");
tex.skip[name] = gluespec;
-- tex.setskip("global", name, gluespec);
-- tex.skip[name].width = value .. "in";
-- etc., etc..
tex.sprint
will only be seen after the Lua chunk has been processed.\directlua
two different files, synchronously, and it magically work? (If I separated out the\newlength
s from the\setlength
s?)\newlength
) which you can also do from Lua but that is rather different thing.\newlength
are skip registers although other things that latex calls lengths and that may be set with\setlength
are dimen registers eg\textwidth
tex.sprint
or some such thing. Are you saying that I could just use a\gdef
to define a length and it will work just like a length, like:token.set_macro("MyLength", "2in", "global")
. And, are you saying thatSkip Registers
are just wrappers aroundDimension Registers
?