ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* How to define a new environment / function?
@ 2015-06-17 13:23 "Dr. Thomas Möbius"
  2015-06-20  9:10 ` Wolfgang Schuster
  0 siblings, 1 reply; 2+ messages in thread
From: "Dr. Thomas Möbius" @ 2015-06-17 13:23 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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?

Thank you so much!

Best
Thomas
___________________________________________________________________________________
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] 2+ messages in thread

* Re: How to define a new environment / function?
  2015-06-17 13:23 How to define a new environment / function? "Dr. Thomas Möbius"
@ 2015-06-20  9:10 ` Wolfgang Schuster
  0 siblings, 0 replies; 2+ messages in thread
From: Wolfgang Schuster @ 2015-06-20  9:10 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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

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

end of thread, other threads:[~2015-06-20  9:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-17 13:23 How to define a new environment / function? "Dr. Thomas Möbius"
2015-06-20  9:10 ` Wolfgang Schuster

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