ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Wolfgang Schuster <schuster.wolfgang@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: How to define a new environment / function?
Date: Sat, 20 Jun 2015 11:10:00 +0200	[thread overview]
Message-ID: <55852DE8.8080801@gmail.com> (raw)
In-Reply-To: <558174E1.8070207@thomasmoebius.de>


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


> Dr. Thomas Möbius <mailto:kontakt@thomasmoebius.de>
> 17. Juni 2015 15:23
> Dear list,
>
> having used ConTeXt for years now, I am the first time in need
> to, well, "programming" something. And I realised, I am a little bit
> lost. I have a rather long list of variable descriptions that I would
> like to typeset in a usable and readable way. It should look something
> like this:
>
> ---snip: minimal example---
> \starttext
> \setupdelimitedtext[blockquote]
>
> {{\bf Geschlecht} \qquad Geschlecht \hfill $0,1$}
>
> \startblockquote
> Das Geschlecht des Probanden.
> \stopblockquote
>
> \blank
> {{\bf SoB} \qquad Geburtssaison \hfill $1,\dots,4$}
>
> \startblockquote
> Jahreszeit der Geburt. Kodierung: 1 = Winter, 2 = Frühling, 3 = Sommer,
> 4 = Herbst.
> \stopblockquote
>
> \blank
> {{\bf BildungV} \qquad Bildung Vater \hfill $1,\dots,6$}
>
> \startblockquote
> Ordinale Beschreibung der Bildung des Vaters zum Zeitpunkt der Erhebung.
> Kodierung: 0 = kein Abschluss, 1 = Volksschule, 2 = Hauptschule, 3 =
> Realschule, 4 = Fachabitur, 5 = Abitur, 6 = Studium.
> \stopblockquote
>
> \blank
> {{\bf BildungM} \qquad Bildung Mutter \hfill $1,\dots,6$}
>
> \startblockquote
> Ordinale Beschreibung der Bildung der Mutter zum Zeitpunkt der Erhebung.
> Kodierung siehe {\bf BildungV}.
> \stopblockquote
>
> \blank
> {{\bf Urb15} \qquad Urbanität \hfill $\naturalnumbers$}
>
> \startblockquote
> Beschreibung der Urbanität des Umfelds in den ersten 15 Lebensjahren.
> Kodierung: $\sum_{i=1}^{15} u_i$ mit $u_i=$ ein Punkt für eine Stadt bis
> 10.000 Einwohner, 2 Punkte für bis 100.000 Einwohner, 3 Punkte über
> 100.000 Einwohner im Jahr $i$.
> \stopblockquote
>
> \blank
> {{\bf LQ} \qquad Händigkeit \hfill $(0,1)$}
>
> \startblockquote
> Lateralisierungsquotient, wobei -1 = perfekt linkshändig und +1 =
> perfekt rechtshändig.
> \stopblockquote
>
> \stoptext
> ---end snip---
>
> What I would like to have is a function/environment/something that would
> allow me to write the above text in the following way:
>
> ---snip: want to example---
> \starttext
>
> \startvariable [alias=Geschlecht, name=Geschlecht, range={$0,1$}]
> Das Geschlecht des Probanden.
> \stopvariable
>
> \startvariable [alias=SoB, name=Geburtssaison, range={$1,\dots,4$}]
> Jahreszeit der Geburt. Kodierung: 1 = Winter, 2 = Frühling, 3 = Sommer,
> 4 = Herbst.
> \stopvariable
>
> \startvariable [alias=BildungV, name={Bildung Vater},
> range={$1,\dots,6$}, reference=bildungDesVater]
> Ordinale Beschreibung der Bildung des Vaters zum Zeitpunkt der Erhebung.
> Kodierung: 0 = kein Abschluss, 1 = Volksschule, 2 = Hauptschule, 3 =
> Realschule, 4 = Fachabitur, 5 = Abitur, 6 = Studium.
> \stopvariable
>
> \startvariable [alias=BildungM, name={Bildung Mutter},
> range={$1,\dots,6$}]
> Ordinale Beschreibung der Bildung der Mutter zum Zeitpunkt der Erhebung.
> Kodierung siehe \in[bildungDesVater].
> \stopvariable
>
> \startvariable [alias=Urb15, name=Urbanität, range={$\naturalnumbers$}]
> Beschreibung der Urbanität des Umfelds in den ersten 15 Lebensjahren.
> Kodierung: $\sum_{i=1}^{15} u_i$ mit $u_i=$ ein Punkt für eine Stadt bis
> 10.000 Einwohner, 2 Punkte für bis 100.000 Einwohner, 3 Punkte über
> 100.000 Einwohner im Jahr $i$.
>
> \startvariable [alias=LQ, name=Händigkeit, range={$(0,1)$}]
> Lateralisierungsquotient, wobei -1 = perfekt linkshändig und +1 =
> perfekt rechtshändig.
> \stopvariable
>
> \stoptext
> ---end snip---
>
> Could someone point me in the right direction, or get me started
> somehow? Is this difficult to accomplish? Or is it super easy and I 
> just don't know it?

The code below does what you want.

\def\startvariable
   {\begingroup
    \dosingleempty\dostartvariable}

\def\dostartvariable[#1]%
   {\getrawparameters[variable][alias=,name=,range=,reference=,#1]%
    \grabbufferdata[variable][startvariable][stopvariable]}

\def\stopvariable
   {\directsetup{variable:content}%
    \endgroup}

\startsetups[variable:content]

     \startlinealignment[middle]
         \variablealias
         \qquad
         \variablename
         \hfill
         \variablerange
         
\doifsomething{\variablereference}{\expanded{\reference[\variablereference]{\variablealias}}}
     \stoplinealignment

     \startblockquote
         \getbufferdata[variable]
     \stopblockquote

\stopsetups

\starttext

\startvariable [alias=Geschlecht, name=Geschlecht, range={$0,1$}]
Das Geschlecht des Probanden.
\stopvariable

\startvariable [alias=SoB, name=Geburtssaison, range={$1,\dots,4$}]
Jahreszeit der Geburt. Kodierung: 1 = Winter, 2 = Frühling, 3 = Sommer, 
4 = Herbst.
\stopvariable

\startvariable [alias=BildungV, name={Bildung Vater}, 
range={$1,\dots,6$},reference=bildungDesVater]
Ordinale Beschreibung der Bildung des Vaters zum Zeitpunkt der Erhebung.
Kodierung: 0 = kein Abschluss, 1 = Volksschule, 2 = Hauptschule, 3 =
Realschule, 4 = Fachabitur, 5 = Abitur, 6 = Studium.
\stopvariable

\startvariable [alias=BildungM, name={Bildung Mutter}, range={$1,\dots,6$}]
Ordinale Beschreibung der Bildung der Mutter zum Zeitpunkt der Erhebung.
Kodierung siehe \in[bildungDesVater].
\stopvariable

\startvariable [alias=Urb15, name=Urbanität, range={$\naturalnumbers$}]
Beschreibung der Urbanität des Umfelds in den ersten 15 Lebensjahren.
Kodierung: $\sum_{i=1}^{15} u_i$ mit $u_i=$ ein Punkt für eine Stadt bis
10.000 Einwohner, 2 Punkte für bis 100.000 Einwohner, 3 Punkte über
100.000 Einwohner im Jahr $i$.
\stopvariable

\startvariable [alias=LQ, name=Händigkeit, range={$(0,1)$}]
Lateralisierungsquotient, wobei -1 = perfekt linkshändig und +1 =
perfekt rechtshändig.
\stopvariable

\stoptext

Wolfgang

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

[-- Attachment #2: Type: text/plain, Size: 485 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
___________________________________________________________________________________

      reply	other threads:[~2015-06-20  9:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-17 13:23 "Dr. Thomas Möbius"
2015-06-20  9:10 ` Wolfgang Schuster [this message]

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=55852DE8.8080801@gmail.com \
    --to=schuster.wolfgang@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).