ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Marginal line numbers
@ 2010-12-14 20:33 Jon Crump
  2010-12-16  7:34 ` Thomas A. Schmitz
  0 siblings, 1 reply; 7+ messages in thread
From: Jon Crump @ 2010-12-14 20:33 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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

* Re: Marginal line numbers
  2010-12-14 20:33 Marginal line numbers Jon Crump
@ 2010-12-16  7:34 ` Thomas A. Schmitz
  2010-12-16 21:28   ` Jon Crump
  0 siblings, 1 reply; 7+ messages in thread
From: Thomas A. Schmitz @ 2010-12-16  7:34 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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
___________________________________________________________________________________


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

* Re: Marginal line numbers
  2010-12-16  7:34 ` Thomas A. Schmitz
@ 2010-12-16 21:28   ` Jon Crump
  2010-12-16 21:34     ` Wolfgang Schuster
                       ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Jon Crump @ 2010-12-16 21:28 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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.schmitz@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
___________________________________________________________________________________


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

* Re: Marginal line numbers
  2010-12-16 21:28   ` Jon Crump
@ 2010-12-16 21:34     ` Wolfgang Schuster
  2010-12-17 16:37       ` Jon Crump
  2010-12-17  8:27     ` Thomas A. Schmitz
  2010-12-17 22:41     ` Thomas A. Schmitz
  2 siblings, 1 reply; 7+ messages in thread
From: Wolfgang Schuster @ 2010-12-16 21:34 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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


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


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

[-- Attachment #2: Type: text/plain, Size: 486 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] 7+ messages in thread

* Re: Marginal line numbers
  2010-12-16 21:28   ` Jon Crump
  2010-12-16 21:34     ` Wolfgang Schuster
@ 2010-12-17  8:27     ` Thomas A. Schmitz
  2010-12-17 22:41     ` Thomas A. Schmitz
  2 siblings, 0 replies; 7+ messages in thread
From: Thomas A. Schmitz @ 2010-12-17  8:27 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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 "elseif"s 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
___________________________________________________________________________________


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

* Re: Marginal line numbers
  2010-12-16 21:34     ` Wolfgang Schuster
@ 2010-12-17 16:37       ` Jon Crump
  0 siblings, 0 replies; 7+ messages in thread
From: Jon Crump @ 2010-12-17 16:37 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Thu, Dec 16, 2010 at 1:34 PM, Wolfgang Schuster
<schuster.wolfgang@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
___________________________________________________________________________________


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

* Re: Marginal line numbers
  2010-12-16 21:28   ` Jon Crump
  2010-12-16 21:34     ` Wolfgang Schuster
  2010-12-17  8:27     ` Thomas A. Schmitz
@ 2010-12-17 22:41     ` Thomas A. Schmitz
  2 siblings, 0 replies; 7+ messages in thread
From: Thomas A. Schmitz @ 2010-12-17 22:41 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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 "elseif"s 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
___________________________________________________________________________________


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

end of thread, other threads:[~2010-12-17 22:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-14 20:33 Marginal line numbers Jon Crump
2010-12-16  7:34 ` Thomas A. Schmitz
2010-12-16 21:28   ` Jon Crump
2010-12-16 21:34     ` Wolfgang Schuster
2010-12-17 16:37       ` Jon Crump
2010-12-17  8:27     ` Thomas A. Schmitz
2010-12-17 22:41     ` Thomas A. Schmitz

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