Am 23.12.2012 um 02:58 schrieb Roland Thiers <[email protected]>:

> Bonjour,
> I am new in ConTeXt. I love its features. I need some (or a lot of) help.
> I tried to get a macro which compute some values for a math function. With 
> help
> from the wiki ConTeXt Garden and some time I could do that 
> - write my function userdata.f
> - write another function to put the values in a table : userdata.tabf
> - put both of them in a file "/Users/rolandt/context/mesfonctionsluatex.lua"
> - In a file.tex, I use that macro : 
> \def\tabf#1#2%
> {\startluacode
> dofile("/Users/rolandt/context/mesfonctionsluatex.lua")
> userdata.tabf(#1,#2)
> \stopluacode}

When you Lua code is in the same folder as the TeX file you can use
\ctxloadluafile{myfile} to load the Lua file.

> Here are the functions:
> 
> -- fonction cube
> -- on utilise l'espace de nom userdata
> userdata=userdata or {}
> 
> function userdata.f(x)
>   context(x*x*x)
> end
> 
> -- fonction tabf
> -- which makes a table , compute  6 values, b=first x, c = step
> 
> userdata=userdata or {}
> 
> function userdata.tabf(b,c)
>     context.starttable{"*{7}{|l}|"}
> local b=b
> local c=c
> context("\\HL")
> context("\\VL x ")      for i=1,6 do context("\\NC" .. b+(i-1)*c) end
> context("\\VL".."\\AR")
> context("\\HL")
> context("\\VL f(x) ") for i=1,6 do context("\\NC")
> context(userdata.f(b+(i-1)*c)) end 
> context("\\VL".."\\LR")
> context("\\HL")
> context.stoptable()
> end

\startluacode

userdata         = userdata       or {}
userdata.roland = userdata.roland or {}

local roland = userdata.roland

function roland.f(x)
        context(x*x*x)
end

function roland.table(min,max,step)
        local min  = tonumber(min)
        local max  = tonumber(max)
        local step = tonumber(step)
        context.starttable({string.format("|*{%d}{l|}",max-min+2)})
        context.HL()
        context.VL()
        context("x")
        for i=min,max do
                context.NC()
                context(min+(i-1)*step)
        end
        context.VL()
        context.FR()
        context.HL()
        context.VL()
        context("f(x)")
        for i=min,max do
                context.NC()
                roland.f(min+(i-1)*step)
        end 
        context.VL()
        context.AR()
        context.HL()
        context.stoptable()
end

\stopluacode

\define[3]\TableFuntion
  {\ctxlua{userdata.roland.table("#1","#2","#3")}}

\starttext 
\TableFuntion{1}{6}{1}
\TableFuntion{2}{7}{1}
\stoptext

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

maillist : [email protected] / 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
___________________________________________________________________________________

Reply via email to