ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Learning LuaTeX : Invoice
@ 2011-02-20 11:55 Henning Hraban Ramm
  2011-02-20 12:07 ` Henning Hraban Ramm
  2011-02-20 12:08 ` Wolfgang Schuster
  0 siblings, 2 replies; 19+ messages in thread
From: Henning Hraban Ramm @ 2011-02-20 11:55 UTC (permalink / raw)
  To: mailing ConTeXt users list for

Maybe similar to the "spreadsheet" question:
I'm trying to use Wolfgang's letter module for my invoices and would  
like to use Lua for the sums.
But I fail already at the beginning:

\startluacode
userdata = userdata or {}

userdata.invoice = userdata.invoice or { sum = 0 } -- global table for  
sums

function userdata.singlesum(hours, perhour)
	amount = hours * perhour
	userdata.invoice.sum = userdata.invoice.sum + amount
	global.context(string.gsub(string.format("\%.2f", amount), "%.", ","))
	return amount
end

\stopluacode

gives:

(virtual://viafile.1 unknown preamble key [the character )] unknown  
preamble key [the character )] unknown preamble key [the character )]
! LuaTeX error <main ctx instance>:1: '=' expected near '<eof>'.

system          > tex > error on line 11 in file invoice.tex: LuaTeX  
error  ...

  4     \startluacode
  5     userdata = userdata or {}
  6
  7     userdata.invoice = userdata.invoice or { sum = 0 }
  8
  9     function userdata.singlesum(hours, perhour)
10     	amount = hours * perhour
11 >>  	userdata.invoice.sum = userdata.invoice.sum + amount
12     	global.context(string.gsub(string.format("\%.2f", amount),  
"%.", ","))
13     	return amount
14     end


I can't see what's wrong!?

I tried local and usercode, but didn’t get further.


Greetlings from Lake Constance!
Hraban
---
http://www.fiee.net/texnique/
http://wiki.contextgarden.net
https://www.cacert.org (I'm an assurer)

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Learning LuaTeX : Invoice
  2011-02-20 11:55 Learning LuaTeX : Invoice Henning Hraban Ramm
@ 2011-02-20 12:07 ` Henning Hraban Ramm
  2011-02-20 12:08 ` Wolfgang Schuster
  1 sibling, 0 replies; 19+ messages in thread
From: Henning Hraban Ramm @ 2011-02-20 12:07 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Am 2011-02-20 um 12:55 schrieb Henning Hraban Ramm:

> But I fail already at the beginning:
>
> \startluacode

Sorry for the noise, the error was in the call, not in the definition.



Greetlings from Lake Constance!
Hraban
---
http://www.fiee.net/texnique/
http://wiki.contextgarden.net
https://www.cacert.org (I'm an assurer)

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Learning LuaTeX : Invoice
  2011-02-20 11:55 Learning LuaTeX : Invoice Henning Hraban Ramm
  2011-02-20 12:07 ` Henning Hraban Ramm
@ 2011-02-20 12:08 ` Wolfgang Schuster
  2011-02-20 12:58   ` Henning Hraban Ramm
  1 sibling, 1 reply; 19+ messages in thread
From: Wolfgang Schuster @ 2011-02-20 12:08 UTC (permalink / raw)
  To: mailing list for ConTeXt users


Am 20.02.2011 um 12:55 schrieb Henning Hraban Ramm:

> Maybe similar to the "spreadsheet" question:
> I'm trying to use Wolfgang's letter module for my invoices and would like to use Lua for the sums.
> But I fail already at the beginning:
> 
> \startluacode
> userdata = userdata or {}
> 
> userdata.invoice = userdata.invoice or { sum = 0 } -- global table for sums
> 
> function userdata.singlesum(hours, perhour)
> 	amount = hours * perhour
> 	userdata.invoice.sum = userdata.invoice.sum + amount
> 	global.context(string.gsub(string.format("\%.2f", amount), "%.", ","))
> 	return amount
> end
> 
> \stopluacode

\startluacode

userdata = userdata or {}

userdata.invoice = userdata.invoice or { sum = 0 } -- global table for sums

function userdata.singlesum(hours, perhour)
	local amount = hours * perhour
	userdata.invoice.sum = userdata.invoice.sum + amount
 	context(string.gsub(string.format("%.2f",amount),"%.",","))
end

\stopluacode

\starttext
\ctxlua{userdata.singlesum(3,4)}
\stoptext

Wolfgang

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Learning LuaTeX : Invoice
  2011-02-20 12:08 ` Wolfgang Schuster
@ 2011-02-20 12:58   ` Henning Hraban Ramm
  2011-02-20 13:29     ` Wolfgang Schuster
  2011-02-20 13:29     ` Henning Hraban Ramm
  0 siblings, 2 replies; 19+ messages in thread
From: Henning Hraban Ramm @ 2011-02-20 12:58 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Am 2011-02-20 um 13:08 schrieb Wolfgang Schuster:

> 	local amount = hours * perhour

Thank you - I guess you meant that "local". I tried that, but since my  
error was in the call... anyway.

Please consider the following nearly-minimal example:

\starttext

\startluacode
userdata = userdata or {}

userdata.invoice = { sum = 0, hours = 0, perhour = 100 }

function userdata.numberformat(amount)
	context(string.gsub(string.format("\%.2f", amount), "%.", ","))
end

function userdata.InvoiceLine(text, hours)
	context.NC()
	context(text)
	context.NC()
	userdata.numberformat(hours)
	context("\\,h")
	context.NC()
	context.NC()
	userdata.numberformat(hours * userdata.invoice.perhour)
	context("\\,€")
	context.NC()
	context.NR()
	userdata.invoice.sum = userdata.invoice.sum + hours *  
userdata.invoice.perhour
	userdata.invoice.hours = userdata.invoice.hours + hours
end

function userdata.InvoiceSumLine(text)
	context.HL()
	context.NC()
	context(text)
	context.NC()
	userdata.numberformat(userdata.invoice.hours)
	context("\\,h")
	context.NC()
	userdata.numberformat(userdata.invoice.perhour)
	context("\\,€/h")
	context.NC()
	userdata.numberformat(userdata.invoice.sum)
	context("\\,€")
	context.NC()
	context.NR()
end

\stopluacode

\starttabulate[|lw(8cm)|rg(,)w(2cm)|rg(,)w(2cm)|rg(,)w(3cm)|]
%\ctxlua{userdata.InvoiceLine("Play with \\LUATEX", 2.5)}
\ctxlua{userdata.InvoiceLine("Do some \\CONTEXT", 0.5)}
\ctxlua{userdata.InvoiceSumLine("Sum")}
\stoptabulate

\stoptext


That seems to work so far, but invoice.hours and invoice.sum are  
always doubled!
In my letter setup, it’s even quadrupled!
I guess my functions gets called several times, but how can I avoid  
that?


Greetlings from Lake Constance!
Hraban
---
http://www.fiee.net/texnique/
http://wiki.contextgarden.net
https://www.cacert.org (I'm an assurer)

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Learning LuaTeX : Invoice
  2011-02-20 12:58   ` Henning Hraban Ramm
@ 2011-02-20 13:29     ` Wolfgang Schuster
  2011-02-20 13:29     ` Henning Hraban Ramm
  1 sibling, 0 replies; 19+ messages in thread
From: Wolfgang Schuster @ 2011-02-20 13:29 UTC (permalink / raw)
  To: mailing list for ConTeXt users


Am 20.02.2011 um 13:58 schrieb Henning Hraban Ramm:

> \starttabulate[|lw(8cm)|rg(,)w(2cm)|rg(,)w(2cm)|rg(,)w(3cm)|]
> %\ctxlua{userdata.InvoiceLine("Play with \\LUATEX", 2.5)}
> \ctxlua{userdata.InvoiceLine("Do some \\CONTEXT", 0.5)}
> \ctxlua{userdata.InvoiceSumLine("Sum")}
> \stoptabulate

\startluacode
context.starttabulate({"|lw(8cm)|rg(,)w(2cm)|rg(,)w(2cm)|rg(,)w(3cm)|"})
userdata.InvoiceLine("Do some \\CONTEXT", 0.5)
userdata.InvoiceSumLine("Sum")
context.stoptabulate()
\stopluacode

> That seems to work so far, but invoice.hours and invoice.sum are always doubled!
> In my letter setup, it’s even quadrupled!
> I guess my functions gets called several times, but how can I avoid that?

The content of tabulate is processed twice to get the information for
“p” columns and you get therefore the wrong values in the last row.

Wolfgang

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Learning LuaTeX : Invoice
  2011-02-20 12:58   ` Henning Hraban Ramm
  2011-02-20 13:29     ` Wolfgang Schuster
@ 2011-02-20 13:29     ` Henning Hraban Ramm
  2011-02-20 13:41       ` Wolfgang Schuster
  1 sibling, 1 reply; 19+ messages in thread
From: Henning Hraban Ramm @ 2011-02-20 13:29 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Am 2011-02-20 um 13:58 schrieb Henning Hraban Ramm:

> That seems to work so far, but invoice.hours and invoice.sum are  
> always doubled!
> In my letter setup, it’s even quadrupled!
> I guess my functions gets called several times, but how can I avoid  
> that?

I found a better approach, but with the letter module involved, my  
"RegisterItem" is called twice!

\starttext
\usemodule[letter]

\startluacode
userdata = userdata or {}

userdata.invoice = { amount = 0, hours = 0, perhour = 100, items = {} }

function userdata.numberformat(amount)
	context(string.gsub(string.format("\%.2f", amount), "%.", ","))
end

function userdata.InvoiceLine(text, hours)
	context.NC()
	context(text)
	context.NC()
	userdata.numberformat(hours)
	context("\\,h")
	context.NC()
	context.NC()
	userdata.numberformat(hours * userdata.invoice.perhour)
	context("\\,€")
	context.NC()
	context.NR()
end

function userdata.InvoiceSumLine(text)
	context.HL()
	context.NC()
	context(text)
	context.NC()
	userdata.numberformat(userdata.invoice.hours)
	context("\\,h")
	context.NC()
	context("à ")
	userdata.numberformat(userdata.invoice.perhour)
	context("\\,€/h")
	context.NC()
	userdata.numberformat(userdata.invoice.amount)
	context("\\,€")
	context.NC()
	context.NR()
end

function userdata.RegisterItem(text, hours)
	for no, item in ipairs(userdata.invoice.items) do
		-- we need to check for double registering due to some call logic of  
ConTeXt and the letter module
		if item.text == text then
			--return -- commented to show double calling
		end
	end
	table.insert(userdata.invoice.items, {text=text, hours=hours})
end

function userdata.Invoice()
	local amountsum, hoursum = 0,0
	context("\\starttabulate[|lw(8cm)|rg(,)w(2cm)|rg(,)w(2cm)| 
rg(,)w(3cm)|]")
	for no, item in ipairs(userdata.invoice.items) do
		userdata.InvoiceLine(item.text, item.hours)
		hoursum = hoursum + item.hours
		amountsum = amountsum + item.hours * userdata.invoice.perhour
	end
	userdata.invoice.hours = hoursum
	userdata.invoice.amount = amountsum
	userdata.InvoiceSumLine("Sum")
	context.stoptabulate()
end

\stopluacode

\startletter[subject={INVOICE}]

\startluacode

userdata.RegisterItem("Do some \\CONTEXT ", 0.5)
userdata.RegisterItem("Do some \\LUATEX ", 1.5)

userdata.Invoice()

\stopluacode

\stopletter

\stoptext



Greetlings from Lake Constance!
Hraban
---
http://www.fiee.net/texnique/
http://wiki.contextgarden.net
https://www.cacert.org (I'm an assurer)

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Learning LuaTeX : Invoice
  2011-02-20 13:29     ` Henning Hraban Ramm
@ 2011-02-20 13:41       ` Wolfgang Schuster
  2011-02-20 14:49         ` Henning Hraban Ramm
  2011-02-20 15:09         ` Hans Hagen
  0 siblings, 2 replies; 19+ messages in thread
From: Wolfgang Schuster @ 2011-02-20 13:41 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Hans Hagen


Am 20.02.2011 um 14:29 schrieb Henning Hraban Ramm:

> I found a better approach, but with the letter module involved, my "RegisterItem" is called twice!

The letter modules does trialtypesetting of the content to get the content
of the \cc, \encl and \ps commands. To prevent that certain commands and
environments are preprocessed you can wrap them in

\iftrialtypesetting \else
...
\fi

or

\unless\iftrialtypesetting
...
\fi

@Hans: Is it possible to write the above like this

\startnotmode[trialtypesetting]
...
\stopnotmode

Wolfgang

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Learning LuaTeX : Invoice
  2011-02-20 13:41       ` Wolfgang Schuster
@ 2011-02-20 14:49         ` Henning Hraban Ramm
  2011-02-20 15:12           ` Hans Hagen
  2011-02-20 15:09         ` Hans Hagen
  1 sibling, 1 reply; 19+ messages in thread
From: Henning Hraban Ramm @ 2011-02-20 14:49 UTC (permalink / raw)
  To: mailing list for ConTeXt users


Am 2011-02-20 um 14:41 schrieb Wolfgang Schuster:

>
> Am 20.02.2011 um 14:29 schrieb Henning Hraban Ramm:
>
>> I found a better approach, but with the letter module involved, my  
>> "RegisterItem" is called twice!
>
> The letter modules does trialtypesetting of the content to get the  
> content
> of the \cc, \encl and \ps commands. To prevent that certain commands  
> and
> environments are preprocessed you can wrap them in
>
> \iftrialtypesetting \else
> ...
> \fi
>
> or
>
> \unless\iftrialtypesetting
> ...
> \fi


Thank you, but how does that map to Lua? I couldn't find  
"trialtypesetting" in the LuaTeX manual.
I tried
"if context.trialtypesetting() then return end"
but get only "undefined control sequence".

"""
context.iftrialtypesetting()
do
	return
end
context.fi()
"""
can't work, of course ("Incomplete \iffalse")

Greetlings from Lake Constance!
Hraban
---
http://www.fiee.net/texnique/
http://wiki.contextgarden.net
https://www.cacert.org (I'm an assurer)

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Learning LuaTeX : Invoice
  2011-02-20 13:41       ` Wolfgang Schuster
  2011-02-20 14:49         ` Henning Hraban Ramm
@ 2011-02-20 15:09         ` Hans Hagen
  2011-02-20 19:16           ` Henning Hraban Ramm
  1 sibling, 1 reply; 19+ messages in thread
From: Hans Hagen @ 2011-02-20 15:09 UTC (permalink / raw)
  To: Wolfgang Schuster; +Cc: mailing list for ConTeXt users

On 20-2-2011 2:41, Wolfgang Schuster wrote:
>
> Am 20.02.2011 um 14:29 schrieb Henning Hraban Ramm:
>
>> I found a better approach, but with the letter module involved, my "RegisterItem" is called twice!
>
> The letter modules does trialtypesetting of the content to get the content
> of the \cc, \encl and \ps commands. To prevent that certain commands and
> environments are preprocessed you can wrap them in
>
> \iftrialtypesetting \else
> ....
> \fi
>
> or
>
> \unless\iftrialtypesetting
> ....
> \fi
>
> @Hans: Is it possible to write the above like this
>
> \startnotmode[trialtypesetting]
> ....
> \stopnotmode

it's a system mode, so

\startnotmode[*trialtypesetting] ...

and in lua

if tex.systemmodes.trialtypesetting then ...

but, you need to use \settrialtypesetting (see syst-aux.mkiv) as there 
is more than the \if now (too late to get rid of the if)

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
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Learning LuaTeX : Invoice
  2011-02-20 14:49         ` Henning Hraban Ramm
@ 2011-02-20 15:12           ` Hans Hagen
  0 siblings, 0 replies; 19+ messages in thread
From: Hans Hagen @ 2011-02-20 15:12 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Henning Hraban Ramm

On 20-2-2011 3:49, Henning Hraban Ramm wrote:

> "trialtypesetting" in the LuaTeX manual.

things like this are not part of luatex but of context so you need the 
cld manual (or wait till more documentation shows up, or ask ..)

> context.iftrialtypesetting()
> do
> return
> end
> context.fi()
> """
> can't work, of course ("Incomplete \iffalse")

please not that kind of horrible misuse of the context.* namespace
as you don't want to end up with expandafter's at that 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
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Learning LuaTeX : Invoice
  2011-02-20 15:09         ` Hans Hagen
@ 2011-02-20 19:16           ` Henning Hraban Ramm
  2011-02-20 20:20             ` Philipp Gesang
  0 siblings, 1 reply; 19+ messages in thread
From: Henning Hraban Ramm @ 2011-02-20 19:16 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Am 2011-02-20 um 16:09 schrieb Hans Hagen:

> it's a system mode, so
>
> \startnotmode[*trialtypesetting] ...
>
> and in lua
>
> if tex.systemmodes.trialtypesetting then ...
>
> but, you need to use \settrialtypesetting (see syst-aux.mkiv) as  
> there is more than the \if now (too late to get rid of the if)

You mean, Wolfgang must set it in his module? I guess he did.

At least this works as expected:

function userdata.RegisterItem(text, hours)
	if tex.systemmodes.trialtypesetting then return end
	table.insert(userdata.invoice.items, {text=text, hours=hours})
end

Thank you!


Am 2011-02-20 um 16:12 schrieb Hans Hagen:

> On 20-2-2011 3:49, Henning Hraban Ramm wrote:
>
>> "trialtypesetting" in the LuaTeX manual.
>
> things like this are not part of luatex but of context so you need  
> the cld manual (or wait till more documentation shows up, or ask ..)

Ah, I guess the CLD manual was what I was looking for all the time ;-)

I suggest you mention tex.systemmodes.trialtypesetting in section 3.3.  
"trial typesetting" - the "return true" approach didn't help in my  
case (or I didn't understand it).


I'll wikify my invoice sample soon. LuaTeX docs in the wiki are a bit  
scattered ATM... (e.g. Lua, LuaTeX, CLD and MkIV all explain LuaTeX  
basics)


Greetlings from Lake Constance!
Hraban
---
http://www.fiee.net/texnique/
http://wiki.contextgarden.net
https://www.cacert.org (I'm an assurer)

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Learning LuaTeX : Invoice
  2011-02-20 19:16           ` Henning Hraban Ramm
@ 2011-02-20 20:20             ` Philipp Gesang
  2011-02-20 20:28               ` Wolfgang Schuster
  2011-02-22  9:47               ` Henning Hraban Ramm
  0 siblings, 2 replies; 19+ messages in thread
From: Philipp Gesang @ 2011-02-20 20:20 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 1833 bytes --]

Hi Hraban!

On 2011-02-20 <20:16:03>, Henning Hraban Ramm wrote:
< … />
> I'll wikify my invoice sample soon. LuaTeX docs in the wiki are a
> bit scattered ATM... (e.g. Lua, LuaTeX, CLD and MkIV all explain
> LuaTeX basics)

“Lua” is intended to be some kind of portal for all topics
related to Lua programming in Luatex. As opposed to “Luatex”
which should have a focus on typesetting-specific stuff, new
primitives and everything else revolutionary that Luatex offers.
“CLD” is *very* specific and basically just a demonstration for
what a wiki reader might expect in the manual. “MkIV” seems
outdated but I have no idea what content should go there. (Btw.
there’s also a page “programming in luatex”…)

Personally I would prefer that the distinction between the
categories typesetting and Lua scripting be emphasized, e.g. that
info on using the token, node or tex libs goes into the former
(or the Luatex wiki…) whereas Lua-based approaches to stuff that
used to be hacked in Tex macros would go into the latter. Does
this make sense?

Anyways, looking forward to see your invoice code

Philipp


> Greetlings from Lake Constance!
> Hraban
> ---
> http://www.fiee.net/texnique/
> http://wiki.contextgarden.net
> https://www.cacert.org (I'm an assurer)
> 
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
> 
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
> archive  : http://foundry.supelec.fr/projects/contextrev/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________

[-- Attachment #1.2: Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 486 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Learning LuaTeX : Invoice
  2011-02-20 20:20             ` Philipp Gesang
@ 2011-02-20 20:28               ` Wolfgang Schuster
  2011-02-20 23:28                 ` Hans Hagen
  2011-02-22  9:47               ` Henning Hraban Ramm
  1 sibling, 1 reply; 19+ messages in thread
From: Wolfgang Schuster @ 2011-02-20 20:28 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 525 bytes --]


Am 20.02.2011 um 21:20 schrieb Philipp Gesang:

> Anyways, looking forward to see your invoice code

It would be more interesting to have something like luacalc [1] available
in context. As it is only another kind of table one could insert the data
with a syntax like this

\startspreadsheet
  \startrow
    \startcell 3 \stopcell
    \startcell 5 \stopcell
    \startcell = A1 + A3 \stopcell
  \stoprow
\stopspreadsheet

and the final result is printed with a natural table.

[1] http://luacalc.sourceforge.net/

Wolfgang


[-- Attachment #1.2: Type: text/html, Size: 1090 bytes --]

[-- Attachment #2: Type: text/plain, Size: 486 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Learning LuaTeX : Invoice
  2011-02-20 20:28               ` Wolfgang Schuster
@ 2011-02-20 23:28                 ` Hans Hagen
  0 siblings, 0 replies; 19+ messages in thread
From: Hans Hagen @ 2011-02-20 23:28 UTC (permalink / raw)
  To: mailing list for ConTeXt users

[-- Attachment #1: Type: text/plain, Size: 1328 bytes --]

On 20-2-2011 9:28, Wolfgang Schuster wrote:
>
> Am 20.02.2011 um 21:20 schrieb Philipp Gesang:
>
>> Anyways, looking forward to see your invoice code
>
> It would be more interesting to have something like luacalc [1] available
> in context. As it is only another kind of table one could insert the data
> with a syntax like this
>
> \startspreadsheet
>    \startrow
>      \startcell 3 \stopcell
>      \startcell 5 \stopcell
>      \startcell = A1 + A3 \stopcell
>    \stoprow
> \stopspreadsheet
>
> and the final result is printed with a natural table.

See attached file.

For this to work ok we need a reset hook into TABLE but it shows the 
principle.

I think that we should stick close to lua so it's mostly a matter of tex 
interfacing. I can even imagine named sheets so that results can be 
recalled later on.

A nice distraction from more complex coding as this is rather simple so 
I'll think a bit about it.

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
-----------------------------------------------------------------

[-- Attachment #2: m-spreadsheet.mkiv --]
[-- Type: text/x-matlab, Size: 1912 bytes --]

% an experiment, no module yet

\startluacode
local byte, format = string.byte, string.format

spreadsheets = { }

local mt = {
    __index = function(t,k)
        local v = { }
        setmetatable(v,mt)
        t[k] = v
        return v
    end,
}

function spreadsheets.reset()
    spreadsheets.data = { }
    setmetatable(spreadsheets.data,mt)
end

spreadsheets.reset()

-- I'll make a nice lpeg

local offset = byte("A") - 1

local function execute(r,c,str)
    str = string.gsub(str,"([A-Z])",function(s)
        return format("spreadsheets.data[%s]",byte(s)-offset)
    end)
    -- todo: error checking + report
    local result = loadstring("return ".. str)
    result = result and result() or 0
    spreadsheets.data[c][r] = result
    return result
end

function spreadsheets.set(r,c,str)
    execute(r,c,str)
end

function spreadsheets.get(r,c,str)
    local result = execute(r,c,str)
    if result then
        context(result)
    end
end
\stopluacode

\def\resetspreadsheet{\ctxlua{spreadsheets.reset()}}
\def\setspreadsheet#1{\ctxlua{spreadsheets.set(\number\tblrow+1,\number\tblcol,"#1")}}
\def\getspreadsheet#1{\ctxlua{spreadsheets.get(\number\tblrow+1,\number\tblcol,"#1")}}

% we need an everyTABLE

\let\set\setspreadsheet
\let\get\getspreadsheet

\starttext

\bTABLE[align=middle]
   \bTR
     \bTD \get{100} \eTD \bTD test \set{30} \eTD
   \eTR
   \bTR
     \bTD \get{20} \eTD \bTD \get{4+3} \eTD
   \eTR
   \bTR
     \bTD \get{A[1] + A[2]} \eTD
     \bTD \get{B[1] + B[2]} \eTD
   \eTR
   \bTR
     \bTD[nx=2] \bf \get{A[3] + B[3]} \eTD
   \eTR
\eTABLE

\def\startspreadsheet#1\stopspreadsheet
  {\resetspreadsheet
   \bTABLE#1\eTABLE}

\def\startrow#1\stoprow
  {\bTR#1\eTR}

\def\startcell#1\stopcell
  {\bTD\get{#1}\eTD}

\startspreadsheet
   \startrow
     \startcell 3 \stopcell
     \startcell 5 \stopcell
     \startcell A[1] + B[1] \stopcell
   \stoprow
\stopspreadsheet

\stoptext

[-- Attachment #3: Type: text/plain, Size: 486 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Learning LuaTeX : Invoice
  2011-02-20 20:20             ` Philipp Gesang
  2011-02-20 20:28               ` Wolfgang Schuster
@ 2011-02-22  9:47               ` Henning Hraban Ramm
  2011-02-22  9:51                 ` luigi scarso
  1 sibling, 1 reply; 19+ messages in thread
From: Henning Hraban Ramm @ 2011-02-22  9:47 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Am 2011-02-20 um 21:20 schrieb Philipp Gesang:
> Anyways, looking forward to see your invoice code

Here you are:
http://wiki.contextgarden.net/Calculations_in_Lua

It’s just in a "works for me" state, and the page can go away as soon  
as the spreadsheet module goes live.


Greetlings from Lake Constance!
Hraban
---
http://www.fiee.net/texnique/
http://wiki.contextgarden.net
https://www.cacert.org (I'm an assurer)

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Learning LuaTeX : Invoice
  2011-02-22  9:47               ` Henning Hraban Ramm
@ 2011-02-22  9:51                 ` luigi scarso
  2011-02-22 10:01                   ` Wolfgang Schuster
  0 siblings, 1 reply; 19+ messages in thread
From: luigi scarso @ 2011-02-22  9:51 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Tue, Feb 22, 2011 at 10:47 AM, Henning Hraban Ramm <hraban@fiee.net> wrote:
> Am 2011-02-20 um 21:20 schrieb Philipp Gesang:
>>
>> Anyways, looking forward to see your invoice code
>
> Here you are:
> http://wiki.contextgarden.net/Calculations_in_Lua
>
> It’s just in a "works for me" state, and the page can go away as soon as the
> spreadsheet module goes live.
Can you add a small example ?

-- 
luigi
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Learning LuaTeX : Invoice
  2011-02-22  9:51                 ` luigi scarso
@ 2011-02-22 10:01                   ` Wolfgang Schuster
  2011-02-22 10:14                     ` luigi scarso
  0 siblings, 1 reply; 19+ messages in thread
From: Wolfgang Schuster @ 2011-02-22 10:01 UTC (permalink / raw)
  To: mailing list for ConTeXt users


Am 22.02.2011 um 10:51 schrieb luigi scarso:

> On Tue, Feb 22, 2011 at 10:47 AM, Henning Hraban Ramm <hraban@fiee.net> wrote:
>> Am 2011-02-20 um 21:20 schrieb Philipp Gesang:
>>> 
>>> Anyways, looking forward to see your invoice code
>> 
>> Here you are:
>> http://wiki.contextgarden.net/Calculations_in_Lua
>> 
>> It’s just in a "works for me" state, and the page can go away as soon as the
>> spreadsheet module goes live.
> Can you add a small example ?

The spreadsheet module has a example at the end of the file and Hennings code
has also a example at the end.

Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Learning LuaTeX : Invoice
  2011-02-22 10:01                   ` Wolfgang Schuster
@ 2011-02-22 10:14                     ` luigi scarso
  2011-02-22 10:55                       ` Henning Hraban Ramm
  0 siblings, 1 reply; 19+ messages in thread
From: luigi scarso @ 2011-02-22 10:14 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Tue, Feb 22, 2011 at 11:01 AM, Wolfgang Schuster
<schuster.wolfgang@googlemail.com> wrote:
>
> Am 22.02.2011 um 10:51 schrieb luigi scarso:
>
>> On Tue, Feb 22, 2011 at 10:47 AM, Henning Hraban Ramm <hraban@fiee.net> wrote:
>>> Am 2011-02-20 um 21:20 schrieb Philipp Gesang:
>>>>
>>>> Anyways, looking forward to see your invoice code
>>>
>>> Here you are:
>>> http://wiki.contextgarden.net/Calculations_in_Lua
>>>
>>> It’s just in a "works for me" state, and the page can go away as soon as the
>>> spreadsheet module goes live.
>> Can you add a small example ?
>
> The spreadsheet module has a example at the end of the file and Hennings code
> has also a example at the end.
Yes I've seen
-- register invoice items

userdata.RegisterAmountItem("Some introductional text", 0) -- just text

userdata.RegisterTimeItem("Learn \\LUATEX", 2.5)
userdata.RegisterTimeItem("Do some calculations in \\CONTEXT", 3.5 + 7)

userdata.RegisterAmountItem("Donations to Open Source projects", 99) -- lump sum

-- output

userdata.Invoice()

But it' s better
\startluacode
-- functions
\stopluacode
%%
\starttext
\startluacode
-- register invoice items
userdata.RegisterAmountItem("Some introductional text", 0) -- just text
userdata.RegisterTimeItem("Learn \\LUATEX", 2.5)
userdata.RegisterTimeItem("Do some calculations in \\CONTEXT", 3.5 + 7)
userdata.RegisterAmountItem("Donations to Open Source projects", 99) -- lump sum
-- output
userdata.Invoice()
\stopluacode
\stoptext

(or maybe a  better example)

-- 
luigi
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Learning LuaTeX : Invoice
  2011-02-22 10:14                     ` luigi scarso
@ 2011-02-22 10:55                       ` Henning Hraban Ramm
  0 siblings, 0 replies; 19+ messages in thread
From: Henning Hraban Ramm @ 2011-02-22 10:55 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Am 2011-02-22 um 11:14 schrieb luigi scarso:

>>> Can you add a small example ?
>>
>> The spreadsheet module has a example at the end of the file and  
>> Hennings code
>> has also a example at the end.
> Yes I've seen
...
> But it' s better
> \startluacode
> -- functions
> \stopluacode
> %%
> \starttext
> \startluacode
> -- register invoice items
> userdata.RegisterAmountItem("Some introductional text", 0) -- just  
> text
> userdata.RegisterTimeItem("Learn \\LUATEX", 2.5)
> userdata.RegisterTimeItem("Do some calculations in \\CONTEXT", 3.5 +  
> 7)
> userdata.RegisterAmountItem("Donations to Open Source projects", 99)  
> -- lump sum
> -- output
> userdata.Invoice()
> \stopluacode
> \stoptext
>
> (or maybe a  better example)

Feel free to change it, it’s a wiki.

In my own document the functions live in an environment, together with  
all the definitions for the letter, and the invoice items in the  
actual invoice document. I wanted to make a rather minimal example, so  
I left out all the letter stuff.

The page is of use only for those who speak little Lua (I was looking  
for a similar example); if you know better, you won’t need it, and if  
you don’t speak Lua at all, it’s useless for you.


Greetlings from Lake Constance!
Hraban
---
http://www.fiee.net/texnique/
http://wiki.contextgarden.net
https://www.cacert.org (I'm an assurer)

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2011-02-22 10:55 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-20 11:55 Learning LuaTeX : Invoice Henning Hraban Ramm
2011-02-20 12:07 ` Henning Hraban Ramm
2011-02-20 12:08 ` Wolfgang Schuster
2011-02-20 12:58   ` Henning Hraban Ramm
2011-02-20 13:29     ` Wolfgang Schuster
2011-02-20 13:29     ` Henning Hraban Ramm
2011-02-20 13:41       ` Wolfgang Schuster
2011-02-20 14:49         ` Henning Hraban Ramm
2011-02-20 15:12           ` Hans Hagen
2011-02-20 15:09         ` Hans Hagen
2011-02-20 19:16           ` Henning Hraban Ramm
2011-02-20 20:20             ` Philipp Gesang
2011-02-20 20:28               ` Wolfgang Schuster
2011-02-20 23:28                 ` Hans Hagen
2011-02-22  9:47               ` Henning Hraban Ramm
2011-02-22  9:51                 ` luigi scarso
2011-02-22 10:01                   ` Wolfgang Schuster
2011-02-22 10:14                     ` luigi scarso
2011-02-22 10:55                       ` Henning Hraban Ramm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).