[NTG-context] Using luacode

Eric Gerard eric.b.gerard at gmail.com
Mon Jan 19 20:58:26 CET 2015

Dear list members

I think I don’t really understand the way to use a context command with luacode !
What I attempt to do is to write a function in lua which computes the position of one or several bottom tabs depending on : line number (1 is the lowest, 2 is above etc), number of tabs, horizontal position of the tab on the line.
The height of the tab is a Tex value \hauteuronglet
So I compute the x and y value and the width of the tab(s)
After that I want to define a layer with the tab(s) in a table
I can’t have the context.setlayer working properly.
For sure, this code should be cleaned after testing.

Here is the code I wrote

\definelayer[OngletBas][x=0mm, y=0mm, width=\paperwidth, height=\paperheight] 
% variables

%variables onglet gauche
%variables onglet bas

	function test(opt_1, arg_1)
		local table = lpeg.split(",",interfaces.tolist(opt_1))
		local labels = lpeg.split(",",arg_1)
		local NumLigne = table[1]
		local NbTotalOnglets = table[2]
		local PremierOnglet = table[3]
		local decalage = tex.sp("6.5pt")
		tex.dimen.ordonneeongletsbas = tex.dimen.paperheight - tex.dimen.hauteuronglet * NumLigne
		tex.dimen.largeurzoneongletsbas = tex.dimen.paperwidth - tex.dimen.backspace
		tex.dimen.largeurongletbas = tex.dimen.largeurzoneongletsbas / NbTotalOnglets
		tex.dimen.abscisseongletsbas = tex.dimen.backspace + tex.dimen.largeurongletbas * (PremierOnglet - 1)
		local x_ongletsbas = tex.dimen.abscisseongletsbas - decalage
		local y_ongletsbas = tex.dimen.ordonneeongletsbas
		local largeurongletbas = tex.dimen.largeurongletbas
		context.setupbackgrounds({"page"},{background = "OngletBas"}) 
		context.setlayer({"OngletBas"},{hoffset = x_ongletsbas, voffset = y_ongletsbas},
		context.setupTABLE({c},{1,2,3,4,5,6},{width = largeurongletbas})
	interfaces.definecommand {
		name = "test",
		arguments = {
		{ "option", "hash" },
		{ "content", "string" },
		macro = test,

I have to add also (I don’t understand why) but I need to add an offset of -6.5pt to adjust the position of the table.

Thanks in advance

Eric Gerard

More information about the ntg-context mailing list