ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Roland Thiers <roland.thiers@gmail.com>
To: ntg-context@ntg.nl
Subject: to pass an argument in a macro
Date: Sun, 23 Dec 2012 01:58:40 +0000 (UTC)	[thread overview]
Message-ID: <loom.20121223T013536-464@post.gmane.org> (raw)

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}


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

I am sure it could be much better but it works !
Evidently I need a third argument to be able to choose how many values compute.
I failed completely (I don't understand how arguments are passed).
I tried things like : context.starttable{"*{%s}{|l}|",a} but ... fatal error :)
I would appreciate some help or  what to read to improve understanding that kind
of things.
Best regards,
Roland



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


             reply	other threads:[~2012-12-23  1:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-23  1:58 Roland Thiers [this message]
2012-12-23  7:43 ` Wolfgang Schuster
2012-12-25  8:36   ` Roland Thiers
2012-12-25 12:24     ` Hans Hagen
2012-12-25 12:34       ` Roland Thiers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=loom.20121223T013536-464@post.gmane.org \
    --to=roland.thiers@gmail.com \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).