ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* line numbering within frame
@ 2020-01-23 10:54 Thomas A. Schmitz
  2020-01-23 11:45 ` Tomas Hala
  0 siblings, 1 reply; 9+ messages in thread
From: Thomas A. Schmitz @ 2020-01-23 10:54 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi all,

I want line numbering within a framed environment, and I need two (at least) independent numbering systems. I hit a similar problem in 2016, and Wolfgang provided a solution (defining different numbering environment). However, this does not work within a frame. The example shows the problem:

\starttext

% This works:
\definelinenumbering[One]
   \setuplinenumbering[One]
   [style=\ss,
      distance=-2ex,
      step=2,
      location=inleft,
      start=20,
      color=darkblue]
	 \startlinenumbering[One]
	 \input knuth 
	 \stoplinenumbering
  
 \blank [line]

   \definelinenumbering[Two]
   \setuplinenumbering[Two]
   [style=\bf,
      distance=-2ex,
      step=3,
      location=inleft,
      start=4,
      color=darkred]
	 \startlinenumbering[Two]
	 \input klein
	 \stoplinenumbering

% This fails:
\framed 
   [background=color,
      backgroundcolor=gray,
      align={normal,hanging,stretch,tolerant},
      frame=off,
      loffset=6ex,
      width=\textwidth,
      foregroundstyle=\ss]
{\definelinenumbering[Three]
   \setuplinenumbering[Three]
   [style=\ss,
      distance=-2ex,
      step=2,
      location=inleft,
      start=20,
      color=darkblue]
	 \startlinenumbering[Three]
	 \input knuth 
	 \stoplinenumbering
   \blank [line]

   \definelinenumbering[Four]
   \setuplinenumbering[Four]
   [style=\bf,
      distance=-2ex,
      step=3,
      location=inleft,
      start=4,
      color=darkred]
	 \startlinenumbering[Four]
	 \input klein
	 \stoplinenumbering}

\stoptext

The framed environment fails with the error message "Missing number, treated as zero.” Does anyone know how this can be fixed?

All 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: line numbering within frame
  2020-01-23 10:54 line numbering within frame Thomas A. Schmitz
@ 2020-01-23 11:45 ` Tomas Hala
  2020-01-23 21:32   ` Wolfgang Schuster
  2020-01-24 17:45   ` Thomas A. Schmitz
  0 siblings, 2 replies; 9+ messages in thread
From: Tomas Hala @ 2020-01-23 11:45 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi Thomas,

move definitions and setups for Three and Four before the use of \framed.
(With TL2019 works.)

Wishes,

Tomáš




Thu, Jan 23, 2020 ve 11:54:49AM +0100 Thomas A. Schmitz napsal(a):
# Hi all,
# 
# I want line numbering within a framed environment, and I need two (at least) independent numbering systems. I hit a similar problem in 2016, and Wolfgang provided a solution (defining different numbering environment). However, this does not work within a frame. The example shows the problem:
# 
# \starttext
# 
# % This works:
# \definelinenumbering[One]
#    \setuplinenumbering[One]
#    [style=\ss,
#       distance=-2ex,
#       step=2,
#       location=inleft,
#       start=20,
#       color=darkblue]
# 	 \startlinenumbering[One]
# 	 \input knuth 
# 	 \stoplinenumbering
#   
#  \blank [line]
# 
#    \definelinenumbering[Two]
#    \setuplinenumbering[Two]
#    [style=\bf,
#       distance=-2ex,
#       step=3,
#       location=inleft,
#       start=4,
#       color=darkred]
# 	 \startlinenumbering[Two]
# 	 \input klein
# 	 \stoplinenumbering
# 
# % This fails:
# \framed 
#    [background=color,
#       backgroundcolor=gray,
#       align={normal,hanging,stretch,tolerant},
#       frame=off,
#       loffset=6ex,
#       width=\textwidth,
#       foregroundstyle=\ss]
# {\definelinenumbering[Three]
#    \setuplinenumbering[Three]
#    [style=\ss,
#       distance=-2ex,
#       step=2,
#       location=inleft,
#       start=20,
#       color=darkblue]
# 	 \startlinenumbering[Three]
# 	 \input knuth 
# 	 \stoplinenumbering
#    \blank [line]
# 
#    \definelinenumbering[Four]
#    \setuplinenumbering[Four]
#    [style=\bf,
#       distance=-2ex,
#       step=3,
#       location=inleft,
#       start=4,
#       color=darkred]
# 	 \startlinenumbering[Four]
# 	 \input klein
# 	 \stoplinenumbering}
# 
# \stoptext
# 
# The framed environment fails with the error message "Missing number, treated as zero.” Does anyone know how this can be fixed?
# 
# All 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://context.aanhet.net
# archive  : https://bitbucket.org/phg/context-mirror/commits/
# wiki     : http://contextgarden.net
# ___________________________________________________________________________________

                                         Tomáš Hála
--------------------------------------------------------------------
Mendelova univerzita, Provozně ekonomická fakulta, ústav informatiky
Zemědělská 1, CZ-613 00 Brno,  tel. +420 545 13 22 28
--------------------------------------------------------------------
http://akela.mendelu.cz/~thala
___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: line numbering within frame
  2020-01-23 11:45 ` Tomas Hala
@ 2020-01-23 21:32   ` Wolfgang Schuster
  2020-01-23 21:53     ` Thomas A. Schmitz
  2020-01-24 17:45   ` Thomas A. Schmitz
  1 sibling, 1 reply; 9+ messages in thread
From: Wolfgang Schuster @ 2020-01-23 21:32 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Thu, 23 Jan 2020 12:45:22 +0100
Tomas Hala <tomas.hala@mendelu.cz> wrote:

> Hi Thomas,
> 
> move definitions and setups for Three and Four before the use of \framed.

Bonus question: Why is it necessary to put \definelinenumbering before \framed?

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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: line numbering within frame
  2020-01-23 21:32   ` Wolfgang Schuster
@ 2020-01-23 21:53     ` Thomas A. Schmitz
  2020-01-25 18:17       ` Wolfgang Schuster
  0 siblings, 1 reply; 9+ messages in thread
From: Thomas A. Schmitz @ 2020-01-23 21:53 UTC (permalink / raw)
  To: mailing list for ConTeXt users



> On 23. Jan 2020, at 22:32, Wolfgang Schuster <wolfgang.schuster.lists@gmail.com> wrote:
> 
> 
> Bonus question: Why is it necessary to put \definelinenumbering before \framed?
> 
> Wolfgang

I would be grateful for an answer because I have no clue ;-) In my real life case, I fetch the content of the frame from an xml file. Since not every frame has line numbering, I am already inside the frame when I have to define and set up the line numbering environment. I can probably code around it, but it makes my life definitely more difficult…

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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: line numbering within frame
  2020-01-23 11:45 ` Tomas Hala
  2020-01-23 21:32   ` Wolfgang Schuster
@ 2020-01-24 17:45   ` Thomas A. Schmitz
  2020-01-24 17:57     ` Tomas Hala
  1 sibling, 1 reply; 9+ messages in thread
From: Thomas A. Schmitz @ 2020-01-24 17:45 UTC (permalink / raw)
  To: mailing list for ConTeXt users



> On 23. Jan 2020, at 12:45, Tomas Hala <tomas.hala@mendelu.cz> wrote:
> 
> Hi Thomas,
> 
> move definitions and setups for Three and Four before the use of \framed.
> (With TL2019 works.)
> 
> Wishes,
> 
> Tomáš

Thank you for the hint - we’re still waiting for an answer to Wolfgang’s bonus question. But I have continued testing and discovered what is certainly a bug. Here’s a new example:

\setbreakpoints [compound]

\definelinenumbering
   [original]
   [style=\tx\ss,distance=-1ex,step=5,location=inleft,start=10,color=darkred]

\definelinenumbering
   [translation]
   [style=\tx\ss,distance=-1ex,step=5,location=inleft,start=50,color=darkblue]

\starttext

\framed 
  [background=color,
   backgroundcolor=gray,
   align={normal},
   frame=off,
   loffset=6ex,
   width=\textwidth,
   foregroundstyle=\ss]
{\startlinenumbering[original]
 \input knuth 
 \stoplinenumbering
  \blank [line]
   \startlinenumbering[translation]
   \input klein
   \stoplinenumbering}

\stoptext

If you compile it, you will see that the “color” key of the two defined linenumbering environments is not followed. If you comment out the first line \setbreakpoints [compound], you will get two colors, as expected. I leave it as an exercise for Hans and Wolfgang to explain what’s going on here :-)

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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: line numbering within frame
  2020-01-24 17:45   ` Thomas A. Schmitz
@ 2020-01-24 17:57     ` Tomas Hala
  2020-01-24 19:06       ` Wolfgang Schuster
  0 siblings, 1 reply; 9+ messages in thread
From: Tomas Hala @ 2020-01-24 17:57 UTC (permalink / raw)
  To: mailing list for ConTeXt users


Hi Thomas,

I compiled (TL2019) it with as well as without \setbreakpoints[compound] and
I got the same result -- in both case I see both colours. 

Wishes,

Tomáš

Fri, Jan 24, 2020 ve 06:45:06PM +0100 Thomas A. Schmitz napsal(a):
# 
# 
# > On 23. Jan 2020, at 12:45, Tomas Hala <tomas.hala@mendelu.cz> wrote:
# > 
# > Hi Thomas,
# > 
# > move definitions and setups for Three and Four before the use of \framed.
# > (With TL2019 works.)
# > 
# > Wishes,
# > 
# > Tomáš
# 
# Thank you for the hint - we’re still waiting for an answer to Wolfgang’s bonus question. But I have continued testing and discovered what is certainly a bug. Here’s a new example:
# 
# \setbreakpoints [compound]
# 
# \definelinenumbering  
#    [original]
#    [style=\tx\ss,distance=-1ex,step=5,location=inleft,start=10,color=darkred]
# 
# \definelinenumbering
#    [translation]
#    [style=\tx\ss,distance=-1ex,step=5,location=inleft,start=50,color=darkblue]
# 
# \starttext
# 
# \framed 
#   [background=color,
#    backgroundcolor=gray,
#    align={normal},
#    frame=off,
#    loffset=6ex,
#    width=\textwidth,
#    foregroundstyle=\ss]
# {\startlinenumbering[original]
#  \input knuth 
#  \stoplinenumbering
#   \blank [line]
#    \startlinenumbering[translation]
#    \input klein
#    \stoplinenumbering}
# 
# \stoptext
# 
# If you compile it, you will see that the “color” key of the two defined linenumbering environments is not followed. If you comment out the first line \setbreakpoints [compound], you will get two colors, as expected. I leave it as an exercise for Hans and Wolfgang to explain what’s going on here :-)
# 
# 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://context.aanhet.net
# archive  : https://bitbucket.org/phg/context-mirror/commits/
# wiki     : http://contextgarden.net
# ___________________________________________________________________________________

                                         Tomáš Hála
--------------------------------------------------------------------
Mendelova univerzita, Provozně ekonomická fakulta, ústav informatiky
Zemědělská 1, CZ-613 00 Brno,  tel. +420 545 13 22 28
--------------------------------------------------------------------
http://akela.mendelu.cz/~thala
___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: line numbering within frame
  2020-01-24 17:57     ` Tomas Hala
@ 2020-01-24 19:06       ` Wolfgang Schuster
  0 siblings, 0 replies; 9+ messages in thread
From: Wolfgang Schuster @ 2020-01-24 19:06 UTC (permalink / raw)
  To: ntg-context

On Fri, 24 Jan 2020 18:57:50 +0100
Tomas Hala <tomas.hala@mendelu.cz> wrote:

> 
> Hi Thomas,
> 
> I compiled (TL2019) it with as well as without \setbreakpoints[compound] and
> I got the same result -- in both case I see both colours. 

The output with LuaTeX is correct but when you use LuaMetaTeX the second color is wrong.


I can't explain why this happens but when you disable the break points for the line numbers the colors are correct (don't use the following code in your document but wait for a official fix from Hans).

\appendtoks
    \resetbreakpoints
\to \everylinenumber


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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: line numbering within frame
  2020-01-23 21:53     ` Thomas A. Schmitz
@ 2020-01-25 18:17       ` Wolfgang Schuster
  2020-01-26 12:49         ` Thomas A. Schmitz
  0 siblings, 1 reply; 9+ messages in thread
From: Wolfgang Schuster @ 2020-01-25 18:17 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Thomas A. Schmitz

On Thu, 23 Jan 2020 22:53:42 +0100
"Thomas A. Schmitz" <thomas.schmitz@uni-bonn.de> wrote:

> > On 23. Jan 2020, at 22:32, Wolfgang Schuster <wolfgang.schuster.lists@gmail.com> wrote:
> > 
> > Bonus question: Why is it necessary to put \definelinenumbering before \framed?
> > 
> > Wolfgang
> 
> I would be grateful for an answer because I have no clue ;-) In my real life case, I fetch the content of the frame from an xml file. Since not every frame has line numbering, I am already inside the frame when I have to define and set up the line numbering environment. I can probably code around it, but it makes my life definitely more difficult…


Before I give the answer to the question we have to go back to a few TeX/ConTeXt basics.


# Grouping

When you create a new command it is normally local to the current group level and after you end the group the command no longer exists.

In the following example I redefine the value for the color red in a group, when the group ends the new value is forgotten and the previous one is used. When you now create a new command or environment in the group and try to use it after its end you will get a error message (something I tried to avoid with the example) about an undefined command.

%%%% begin example
\starttext

\color[red]{Red}

\start

\definecolor[red][b=1]

\color[red]{Red}

\stop

\color[red]{Red}

\stoptext
%%%% end example


# Inheritance

When you create a new command or environment with \define... the new instance inherits most of its values from a parent instance.

You can overwrite individual values for your new instance but all other values are taken from the parent.

%%%% begin example
\setupframed[foregroundstyle=bold]

\defineframed[customframe][framecolor=red]

\starttext

\framed{Framed text!}

\placeframed[customframe]{Framed text!}

\stoptext
%%%% end example

When you can combine this with the previous section which explained grouping and overwrite values within the group. After the group has ended the new values are forgotten and the instance uses what was set before the group.

%%%% begin example
\defineframed[customframe][framecolor=red]

\starttext

\placeframed[customframe]{Framed text!}

\start

\setupframed[customframe][foregroundstyle=bold]

\placeframed[customframe]{Framed text!}

\stop

\placeframed[customframe]{Framed text!}

\stoptext
%%%% end example


# Line numbering

Line numbering in MkIV happens at a different point as it did in MkII. When you use line numbers for \framed (or \startframedtext) ConTeXt adds the numbers to the frame after the framed box is completed.

When the framed content is put in the box you're always within a group which means the numbers are added after the group has ended and as explained in the two sections above settings within a group normally are forgotten afterwards.

The first and bigger problem is that you try to create a new line numbering instance in each frame which no longer exists when the numbers are added and when ConTeXt tries to access values of this no longer existing instance in fails to get them which results in the error message.

%%%% begin example
\starttext

\startframedtext

\definelinenumbering[example]

\startlinenumbering[example]

\samplefile{klein}

\stoplinenumbering

\stopframedtext

\stoptext
%%%% end example

The minor problem is that you local changes for each instance (e.g. the color for the numbers) are also forgotten because you set them within the group. Only a limited numbers of values can be set in a group (e.g. the starting number) and they have to bet set with \startlinenumbering, this is possible because they are passed to Lua which ignores TeX groups.

While new linenumbering instances outside of frames are save in most cases you should try to avoid this and do it at the begin of the document because even here you can run into problems. Below is a example where I show that you can get the same error as in your example with line numbers for the whole page.

%%%% begin example
\setupsectionblock[bodypart][page=no]

\starttext

\startbodymatter

\definelinenumbering[example]

\startlinenumbering[example]

\samplefile{klein}

\stoplinenumbering

\stopbodymatter

\stoptext
%%%% end example


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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: line numbering within frame
  2020-01-25 18:17       ` Wolfgang Schuster
@ 2020-01-26 12:49         ` Thomas A. Schmitz
  0 siblings, 0 replies; 9+ messages in thread
From: Thomas A. Schmitz @ 2020-01-26 12:49 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 25.01.20 19:17, Wolfgang Schuster wrote:
> Before I give the answer to the question we have to go back to a few TeX/ConTeXt basics.

Wolfgang, thank you for this careful and helpful reply. It really made 
me understand what is going on here. At the same time, I also feel a bit 
more incompetent now because linenumbering behaves in unexpected ways: 
you can set some values (like the starting number) with the simple 
\startlinenumbering command but not all values. And there's this strange 
difference between luatex and luametatex... Without this mailing list, 
I'd be really lost. So thanks again, and I'm waiting for the official fix!

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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

end of thread, other threads:[~2020-01-26 12:49 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-23 10:54 line numbering within frame Thomas A. Schmitz
2020-01-23 11:45 ` Tomas Hala
2020-01-23 21:32   ` Wolfgang Schuster
2020-01-23 21:53     ` Thomas A. Schmitz
2020-01-25 18:17       ` Wolfgang Schuster
2020-01-26 12:49         ` Thomas A. Schmitz
2020-01-24 17:45   ` Thomas A. Schmitz
2020-01-24 17:57     ` Tomas Hala
2020-01-24 19:06       ` 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).