[NTG-context] User-Defined Commands With Key-Value Options

Rik rik at panix.com
Thu Jul 23 22:32:36 CEST 2015


On 2015-07-22 05:20, Joas Yannick wrote:
> On 7/20/2105 11:28 AM Joas Yannick wrote:
> >
> > > On 7/20/2105 0:50 AM Hans Hagen wrote:
> > > So how would you like to use lua? Is the data stored in lua?
> >
> > Yes, I imagine that the data (for instance, the value of
> > the keys "number", "name", "abbreviation", "title", etc.)
> > is stored somewhere when the compilation process reads, say,
> > "\startbiblebook", and that they are available to define the
> > the formatting done by "\startbiblebook".
> >
> > Thank you.
>
> I have found this wiki:
>
> http://wiki.contextgarden.net/Commands_with_KeyVal_arguments
>
> But since I do not know Lua, I would appreciate that someone gets me
> started with my example.
>
Joas,

Perhaps there some confusion here about how ConTeXt is used to create a 
document, and what role Lua plays in it. ConTeXt is a macro-based 
language that provides a level of abstraction over TeX, which is also a 
macro language. Documents can be completely specified with the use of 
ConTeXt. Lua is a traditional programming language that is used by some 
versions of ConTeXt to optimize and extend some of the internal 
capabilities of ConTeXt and TeX. There are very few situations, if any, 
in which a document writer /must/ resort to using Lua; ConTeXt almost 
always suffices.

Only the first example you found in the ConTeXt wiki uses Lua, and that 
example is not really useful for your problem. The other examples on 
that page are coded in the ConTeXt macro language.

You might also look at 
http://wiki.contextgarden.net/System_Macros/Handling_Arguments and 
http://wiki.contextgarden.net/Commands_with_optional_arguments for more 
examples, and on the mailing list. I would also recommend looking in the 
mailing list for discussions of the \getrawparameters and \getbufferdata 
and related commands (in particular 
http://www.mail-archive.com/ntg-context%40ntg.nl/msg78808.html).

Here is some code I use to format verse. It provides default values for 
the language, margin inset and continuation line indents that can be 
overridden when needed:

    \starttexdefinition unexpanded startPoem
       \begingroup
       \dosingleempty\dostartPoem
    \stoptexdefinition

    \starttexdefinition dostartPoem [#SETUPS]
    \getrawparameters[Poem][inset=2em,indent=0em,before=,font=,
                               language=en,#SETUPS]
       \grabbufferdata[Poem][startPoem][stopPoem]
    \stoptexdefinition

    \starttexdefinition stopPoem
         \obeylines
         \language[\Poemlanguage]
         \Poembefore
         \Poemfont
    \setupnarrower[left={\dimexpr\Poemindent+\Poeminset\relax},
                        right=\Poeminset,
                        before=]
         \startnarrower[left,right]
           \startparagraph
           \setupindenting[-\Poemindent,yes]
           \inlinebuffer[Poem]
           \stopparagraph
         \stopnarrower
       \endgroup
       \blank[halfline]
    \stoptexdefinition

This type of code can easily be used to deal with the names, numbers, 
and abbreviations you describe in your requirements.

-- 
Rik Kabel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.ntg.nl/pipermail/ntg-context/attachments/20150723/da396100/attachment-0001.html>


More information about the ntg-context mailing list