Re: [NTG-context] Marginal line numbers

2010-12-17 Thread Jon Crump
On Thu, Dec 16, 2010 at 1:34 PM, Wolfgang Schuster
schuster.wolfg...@googlemail.com wrote:

 Am 16.12.2010 um 22:28 schrieb Jon Crump:

 In python-speak I'd interpret context.color() as a method call on a
 module 'context'. Could you, or anyone, direct me to any documentation
 for this module and a list of the properties and methods that it
 supports?

 http://pragma-ade.com/show-man-44.htm
 Wolfgang

Wolfgang, many thanks.
Jon
___
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
___


Re: [NTG-context] Marginal line numbers

2010-12-17 Thread Thomas A. Schmitz

On Dec 16, 2010, at 10:28 PM, Jon Crump wrote:

 Thomas, et alia.
 
 Thanks so very much! I now have this:
 
 \startluacode
 function filter(s)
   if math.mod(s,5) == 0 then
 context.color( { darkred }, s )
   end
 end
 \stopluacode
 
 \define[1]\MyNumber%
 {\ctxlua{filter(#1)}\endgraf}
 
 \startxmlsetups xml:lb
   \lineNumbers{\MyNumber{\xmlatt{#1}{n}}}
   \xmlflush{#1}
 \stopxmlsetups
 
 \defineinmargin [lineNumbers] [outer] [normal]
 

This was just an example to show you how to use lua to do things which are 
difficult or impossible or cumbersome in TeX alone, such as math, working with 
strings (substitutions, etc.), conditionals, loops... You don't have to take my 
code verbatim; the darkred was just meant to show that you can apply certain 
code to a number if it matches a condition (here: be divisible by 5).

 This gets me what I wanted.  Still fumbling greatly with the macro
 syntax. I'm not sure what the recursion is for, for example. On the
 other hand the lua seems rather straightforward to me by comparison. I
 tried returning an empty string like this: context.color( {blue}, ''
 ) to remove the other numbers, but that seemed silly, so I just
 removed the 'else' clause instead, and that seemed to work as well.
 

Yes, of course, if all you want  is process numbers divisible by 5, that's the 
easiest way. But it's good to know that lua allows more complex conditionals - 
you could use elseifs to make numbers divisible by 100 bold, or whatever. I 
find such conditionals in TeX much more cumbersome; even for somebody with no 
programming background like myself, they are easy to write in lua.

The recursion was just a way of demonstrating the effect. \dorecurse is a 
wonderful macro to construct minimal examples (you can search the mail archive 
for some real gems). And, as a hint: constructing a compilable minimal example 
not only is educational (I don't know how often I could solve my problems when 
I tried to produce a minimal example and saw where my approach was failing), 
but will also improve your chances of people actually willing to help you. If 
you want to see an elegant way of producing minimal examples in xml, search the 
mail archive for xmlprocessbuffer.

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
___


Re: [NTG-context] Marginal line numbers

2010-12-17 Thread Thomas A. Schmitz

On Dec 16, 2010, at 10:28 PM, Jon Crump wrote:

 Thomas, et alia.
 
 Thanks so very much! I now have this:
 
 \startluacode
 function filter(s)
  if math.mod(s,5) == 0 then
context.color( { darkred }, s )
  end
 end
 \stopluacode
 
 \define[1]\MyNumber%
 {\ctxlua{filter(#1)}\endgraf}
 
 \startxmlsetups xml:lb
   \lineNumbers{\MyNumber{\xmlatt{#1}{n}}}
   \xmlflush{#1}
 \stopxmlsetups
 
 \defineinmargin [lineNumbers] [outer] [normal]
 

This was just an example to show you how to use lua to do things which are 
difficult or impossible or cumbersome in TeX alone, such as math, working with 
strings (substitutions, etc.), conditionals, loops... You don't have to take my 
code verbatim; the darkred was just meant to show that you can apply certain 
code to a number if it matches a condition (here: be divisible by 5).

 This gets me what I wanted.  Still fumbling greatly with the macro
 syntax. I'm not sure what the recursion is for, for example. On the
 other hand the lua seems rather straightforward to me by comparison. I
 tried returning an empty string like this: context.color( {blue}, ''
 ) to remove the other numbers, but that seemed silly, so I just
 removed the 'else' clause instead, and that seemed to work as well.
 

Yes, of course, if all you want  is process numbers divisible by 5, that's the 
easiest way. But it's good to know that lua allows more complex conditionals - 
you could use elseifs to make numbers divisible by 100 bold, or whatever. I 
find such conditionals in TeX much more cumbersome; even for somebody with no 
programming background like myself, they are easy to write in lua.

The recursion was just a way of demonstrating the effect. \dorecurse is a 
wonderful macro to construct minimal examples (you can search the mail archive 
for some real gems). And, as a hint: constructing a compilable minimal example 
not only is educational (I don't know how often I could solve my problems when 
I tried to produce a minimal example and saw where my approach was failing), 
but will also improve your chances of people actually willing to help you. If 
you want to see an elegant way of producing minimal examples in xml, search the 
mail archive for xmlprocessbuffer.

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
___


Re: [NTG-context] Marginal line numbers

2010-12-16 Thread Jon Crump
Thomas, et alia.

Thanks so very much! I now have this:

\startluacode
 function filter(s)
   if math.mod(s,5) == 0 then
 context.color( { darkred }, s )
   end
 end
\stopluacode

\define[1]\MyNumber%
 {\ctxlua{filter(#1)}\endgraf}

\startxmlsetups xml:lb
\lineNumbers{\MyNumber{\xmlatt{#1}{n}}}
\xmlflush{#1}
\stopxmlsetups

\defineinmargin [lineNumbers] [outer] [normal]

This gets me what I wanted.  Still fumbling greatly with the macro
syntax. I'm not sure what the recursion is for, for example. On the
other hand the lua seems rather straightforward to me by comparison. I
tried returning an empty string like this: context.color( {blue}, ''
) to remove the other numbers, but that seemed silly, so I just
removed the 'else' clause instead, and that seemed to work as well.

In python-speak I'd interpret context.color() as a method call on a
module 'context'. Could you, or anyone, direct me to any documentation
for this module and a list of the properties and methods that it
supports?

On Wed, Dec 15, 2010 at 11:34 PM, Thomas A. Schmitz
thomas.schm...@uni-bonn.de wrote:

 This is easy with a lua function. Since you know python, I guess the 
 following example will be easy for you:

 \startluacode
  function filter(s)
    if math.mod(s,5) == 0 then
      context.color( { darkred }, s )
    else
      context.color( { darkblue }, s )
    end
  end
 \stopluacode

 \define[1]\MyNumber%
  {\ctxlua{filter(#1)}\endgraf}

 \starttext

 \dorecurse{25}{\MyNumber{\recurselevel}}

 \stoptext

 This should get you going, I hope

 Good luck

 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
___


Re: [NTG-context] Marginal line numbers

2010-12-16 Thread Wolfgang Schuster

Am 16.12.2010 um 22:28 schrieb Jon Crump:

 In python-speak I'd interpret context.color() as a method call on a
 module 'context'. Could you, or anyone, direct me to any documentation
 for this module and a list of the properties and methods that it
 supports?

http://pragma-ade.com/show-man-44.htm

Wolfgang

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


Re: [NTG-context] Marginal line numbers

2010-12-15 Thread Thomas A. Schmitz

On Dec 14, 2010, at 9:33 PM, Jon Crump wrote:

 All,
 
 Thanks to Thomas's help, I've been making my way up the learning curve.
 
 My TEI xml has empty lb elements indicating lines in the original and
 corresponding lb elements in the translation. I'd like to be able to
 set these numbers in the margin so that readers may coordinate the
 lineation. So far I have this:
 
 \startxmlsetups xml:lb
   \lineNumbers{\xmlatt{#1}{n}}
   \xmlflush{#1}
 \stopxmlsetups
 
 \defineinmargin [lineNumbers] [outer] [normal]
 
 which works, but I'd like to be able to set only every fifth or tenth
 line number. Is there a way to perform some arithmetic on the value of
 the n attribute and then execute \lineNumbers accordingly?
 
 for example:
 
 if n%5 == 0 then \lineNumbers else ignore lb
 
 Thanks,
 Jon

This is easy with a lua function. Since you know python, I guess the following 
example will be easy for you:

\startluacode
  function filter(s)
if math.mod(s,5) == 0 then
  context.color( { darkred }, s )
else
  context.color( { darkblue }, s )
end
  end
\stopluacode

\define[1]\MyNumber%
  {\ctxlua{filter(#1)}\endgraf}

\starttext

\dorecurse{25}{\MyNumber{\recurselevel}}

\stoptext

This should get you going, I hope

Good luck

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
___