Dear list, I cannot figure out what I am doing wrong here. If I remove \hbox, it works fine, but I would like to draw a table. \starttext \startluacode function draw_table(unicode_start,n_columns) for i=0,0xF do tex.print('\\dontleavehmode\\definedfont[Serif at 20pt]\\kern0pt') for j=0,n_columns do --tex.print('\\hbox{ \\char %d }', unicode_start+i*16+j) tex.print('\\hbox to 1.5em{\\hss %s \\hss}', unicode.utf8.char(unicode_start+i*16+j)) end tex.print('\\crlf') end end draw_table(0x00C0,4) \stopluacode \stoptext Any hints welcome. Thanks, Mojca
On Thu, Dec 23, 2010 at 1:57 PM, Mojca Miklavec
Dear list,
I cannot figure out what I am doing wrong here. If I remove \hbox, it works fine, but I would like to draw a table.
\starttext \startluacode function draw_table(unicode_start,n_columns) for i=0,0xF do tex.print('\\dontleavehmode\\definedfont[Serif at 20pt]\\kern0pt') for j=0,n_columns do --tex.print('\\hbox{ \\char %d }', unicode_start+i*16+j) tex.print('\\hbox to 1.5em{\\hss %s \\hss}', unicode.utf8.char(unicode_start+i*16+j)) end tex.print('\\crlf') end end
draw_table(0x00C0,4) \stopluacode \stoptext
Any hints welcome.
I don't know but for the moment this works \starttext \startluacode function draw_table(unicode_start,n_columns) for i=0,0xF do tex.print('\\dontleavehmode\\definedfont[Serif at 20pt]\\kern0pt') for j=0,n_columns do local d = string.format( "\\hbox to 1.5em{\\hss \%s \\hss}",unicode.utf8.char(unicode_start+i*16+j)) tex.print(d) end tex.print('\\crlf') end end draw_table(0x00C0,4) \stopluacode \stoptext -- luigi
On Thu, Dec 23 2010, Mojca Miklavec wrote:
tex.print('\\hbox to 1.5em{\\hss %s \\hss}',
tex.print() does not handle the %s. context() does. So just replace tex.print() by context(). Peter -- Contact information: http://pmrb.free.fr/contact/
On Thu, Dec 23, 2010 at 2:09 PM, Peter Münster
On Thu, Dec 23 2010, Mojca Miklavec wrote:
tex.print('\\hbox to 1.5em{\\hss %s \\hss}',
tex.print() does not handle the %s. context() does.
So just replace tex.print() by context(). Right, this also works
\starttext \startluacode function draw_table(unicode_start,n_columns) for i=0,0xF do tex.print('\\dontleavehmode\\definedfont[Serif at 20pt]\\kern0pt') for j=0,n_columns do context('\\hbox to 1.5em{\\hss %s \\hss}',unicode.utf8.char(unicode_start+i*16+j)) end tex.print('\\crlf') end end draw_table(0x00C0,4) \stopluacode \stoptext -- luigi
On 23-12-2010 2:36, luigi scarso wrote:
On Thu, Dec 23, 2010 at 2:09 PM, Peter Münster
wrote: On Thu, Dec 23 2010, Mojca Miklavec wrote:
tex.print('\\hbox to 1.5em{\\hss %s \\hss}',
tex.print() does not handle the %s. context() does.
So just replace tex.print() by context(). Right, this also works
\starttext \startluacode function draw_table(unicode_start,n_columns) for i=0,0xF do tex.print('\\dontleavehmode\\definedfont[Serif at 20pt]\\kern0pt') for j=0,n_columns do context('\\hbox to 1.5em{\\hss %s \\hss}',unicode.utf8.char(unicode_start+i*16+j)) end tex.print('\\crlf') end end
draw_table(0x00C0,4) \stopluacode \stoptext
without backslashes: function draw_table(unicode_start,n_columns) context.start() context.definedfont{"Serif at 20pt"} for i=0,0xF do context.dontleavehmode() for j=0,n_columns do -- context('\\hbox to 1.5em{\\hss %s\\hss}',unicode.utf8.char(unicode_start+i*16+j)) context.hbox(false,"to 1.5em") context.bgroup() context.hss() context(unicode.utf8.char(unicode_start+i*16+j)) context.hss() context.egroup() end context.crlf() end context.stop() end cleaner: function draw_table(unicode_start,n_columns) context.start() context.definedfont { "Serif at 20pt" } context.starttabulate { string.format("*{%s}{|w(1.5em)}|",n_columns+1) } for i=0,0xF do context.NC() for j=0,n_columns do context(unicode.utf8.char(unicode_start+i*16+j)) context.NC() end context.NR() end context.stoptabulate() context.stop() end Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On Thu, Dec 23, 2010 at 15:52, Hans Hagen wrote:
cleaner:
function draw_table(unicode_start,n_columns) context.start() context.definedfont { "Serif at 20pt" } context.starttabulate { string.format("*{%s}{|w(1.5em)}|",n_columns+1) }
Great, thanks! (I wanted to create a proper table at some point, but didn't take time to think about how to create an arbitrary number of columns.) But then I have another question: how can I use \HL and \VL? The following code doesn't create any line at all: function draw_table(unicode_start,n_columns) context.bgroup() context.definedfont { "Serif at 20pt" } context.starttable { string.format("*{%s}{|w(1.2em)}|", n_columns) } for i=0,0xF do context.VL() for j=0,n_columns-1 do context(unicode.utf8.char(unicode_start+i+16*j)) context.VL() end context.NR() context.HL() end context.stoptable() context.egroup() end Mojca PS: I still don't know the reason why my example fails, but I will ignore that for a moment since this does the job as well.
On Thu, Dec 23 2010, luigi scarso wrote:
PS: I still don't know the reason why my example fails
catcode , I suppose
Indeed. The %-sign starts a comment in TeX. \starttext \startluacode tex.print("\\hbox{ %s }", "a string") \stopluacode \stoptext is nearly the same as \starttext \hbox{ %s } a string \stoptext In both cases, the error message is: ! Missing } inserted. Cheers, Peter -- Contact information: http://pmrb.free.fr/contact/
participants (4)
-
Hans Hagen
-
luigi scarso
-
Mojca Miklavec
-
Peter Münster