is it possible to have first and last line numbers from page?
I have asked this question before (more than twice), after I found no answer in the ConTeXt reference manual, the wiki or the mailing list. I wanted to be able to have in the headers the first and last line number from page. This feature is extremely useful when typesetting some kinds of poetry. The most basic sample would be: \starttext \startlinenumbering \dorecurse{10}{\input zapf\par\input knuth} \stoplinenumbering \stoptext Is that possible to achieve with ConTeXt? Many thanks for your help, Pablo -- http://www.ousia.tk
Am 04.03.2012 um 11:20 schrieb Pablo Rodríguez:
I have asked this question before (more than twice), after I found no answer in the ConTeXt reference manual, the wiki or the mailing list.
I wanted to be able to have in the headers the first and last line number from page. This feature is extremely useful when typesetting some kinds of poetry.
The most basic sample would be:
\starttext \startlinenumbering \dorecurse{10}{\input zapf\par\input knuth} \stoplinenumbering \stoptext
Is that possible to achieve with ConTeXt?
Yes but it’s not usable because the numbers are always shown on the next page. \definemarking[linenumber] \define\LinenumberCommand {\normalexpanded{\setmarking[linenumber]{\linenumber}}} \setuplinenumbering[command=\LinenumberCommand] \startsetups linenumber \doiftext { \getmarking[linenumber] } { \getmarking[linenumber][first] – \getmarking[linenumber][last] } \stopsetups \setupheadertexts[\texsetup{linenumber}] \starttext \dorecurse{6}{\input tufte\par} \startlinenumbering \dorecurse{20}{\input knuth\par} \stoplinenumbering \resetmarking[linenumber] \dorecurse{6}{\input tufte\par} \stoptext Wolfgang
On 03/04/2012 12:04 PM, Wolfgang Schuster wrote:
Am 04.03.2012 um 11:20 schrieb Pablo Rodríguez:
I wanted to be able to have in the headers the first and last line number from page. This feature is extremely useful when typesetting some kinds of poetry. [...] Is that possible to achieve with ConTeXt?
Yes but it’s not usable because the numbers are always shown on the next page.
Many thanks for your reply, Wolfgang. If you allow me one more question: is showing the numbers on the same page they refer to beyond the limits of TeX/LuaTeX? I'm asking this to know whether such a feature could be implemented some day in ConTeXt. Many thanks for your help again, Pablo -- http://www.ousia.tk
Am 04.03.2012 um 13:15 schrieb Pablo Rodríguez:
On 03/04/2012 12:04 PM, Wolfgang Schuster wrote:
Am 04.03.2012 um 11:20 schrieb Pablo Rodríguez:
I wanted to be able to have in the headers the first and last line number from page. This feature is extremely useful when typesetting some kinds of poetry. [...] Is that possible to achieve with ConTeXt?
Yes but it’s not usable because the numbers are always shown on the next page.
Many thanks for your reply, Wolfgang.
If you allow me one more question: is showing the numbers on the same page they refer to beyond the limits of TeX/LuaTeX?
I'm asking this to know whether such a feature could be implemented some day in ConTeXt.
It’s a problem with the way how line numbering works. Wolfgang
On 04/03/12 14:44, Wolfgang Schuster wrote:
Am 04.03.2012 um 13:15 schrieb Pablo Rodríguez:
[...] If you allow me one more question: is showing the numbers on the same page they refer to beyond the limits of TeX/LuaTeX?
I'm asking this to know whether such a feature could be implemented some day in ConTeXt.
It’s a problem with the way how line numbering works.
Thanks for your reply, Wolfgang. Would it be possible to make something similar with margin data or pure margin sectioning commands? Only interested in knowing whether this could work. Thanks again for your help, Pablo Pablo -- http://www.ousia.tk
2012/3/4 Pablo Rodríguez
Am 04.03.2012 um 11:20 schrieb Pablo Rodríguez:
I wanted to be able to have in the headers the first and last line number from page. This feature is extremely useful when typesetting some kinds of poetry. [...] Is that possible to achieve with ConTeXt?
Yes but it’s not usable because the numbers are always shown on the next
On 03/04/2012 12:04 PM, Wolfgang Schuster wrote: page.
Many thanks for your reply, Wolfgang.
If you allow me one more question: is showing the numbers on the same page they refer to beyond the limits of TeX/LuaTeX?
Absolutely no. As Hans said, a quick/dirty trick is possible: just mark the object with \pagereference[<unique id>]. The data is stored into the *tuc file, which can be read from the second pass. Then always run with $>context --purgeall ; context <yourfile>.mkiv Of course, "it's possible " doesn't mean "it's the right context way". \startluacode document.my_name_space = document.my_name_space or {} document.my_name_space.pages = document.my_name_space.pages or {} local f = io.open(file.addsuffix(tex.jobname,"tuc") ) print('>>>>> ',f) if f==nil then --[=[ do nothin ]=] else f:close() local tuc = dofile(file.addsuffix(tex.jobname,"tuc")) local data = tuc.structures.references.collected[""] local w local pages = document.my_name_space.pages local realpage,ref for k, v in pairs(data) do w=string.gmatch(k,'LIN:(\%d+):\%d+') ref = tonumber(w()) realpage = tostring(v.references.realpage) pages[realpage]= pages[realpage] or {} table.insert(pages[realpage],ref) end for page,array in pairs(pages) do table.sort(array) end end \stopluacode \definemarking[linenumber] \define\LinenumberCommand {\normalexpanded{\setmarking[linenumber]{\linenumber}}\pagereference[LIN:\linenumber:\currentpage]} \setuplinenumbering[command=\LinenumberCommand] \startsetups linenumber % \doiftext { % \getmarking[linenumber] % } % { % \getmarking[linenumber][first] – \getmarking[linenumber][last] % } \startluacode local l=0; if document.my_name_space == nil then return end; if document.my_name_space.pages == nil then return end; local pages = document.my_name_space.pages; for _,_ in pairs(pages) do l=l+1 end; if l== 0 then return end; --[=[ OK, we have some data to print ]=] local array = pages[tostring(tex.count.realpageno)] l=0; if array ==nil then return end; for _,_ in pairs(array) do l=l+1 end; if l>0 then context(" nr. "..array[1].." --- "..array[l]) end; \stopluacode \stopsetups \setupheadertexts[\texsetup{linenumber}] \starttext \dorecurse{6}{\input tufte\par} \startlinenumbering \dorecurse{20}{\input knuth\par} \stoplinenumbering \resetmarking[linenumber] \dorecurse{6}{\input tufte\par} \stoptext -- luigi
On 05/03/12 15:12, luigi scarso wrote:
2012/3/4 Pablo Rodríguez: [...] Many thanks for your reply, Wolfgang.
If you allow me one more question: is showing the numbers on the same page they refer to beyond the limits of TeX/LuaTeX?
Absolutely no. As Hans said, a quick/dirty trick is possible: just mark the object with \pagereference[<unique id>]. The data is stored into the *tuc file, which can be read from the second pass.
Many thanks for the code, Luigi. My question was to basic, but I wondered why this didn't worked.
Of course, "it's possible " doesn't mean "it's the right context way".
It does the work until it's implemented in ConTeXt. Many thanks again for your help, Pablo -- http://www.ousia.tk
On 05/03/12 15:12, luigi scarso wrote:
2012/3/4 Pablo Rodríguez If you allow me one more question: is showing the numbers on the same page they refer to beyond the limits of TeX/LuaTeX?
Absolutely no. As Hans said, a quick/dirty trick is possible: just mark the object with \pagereference[<unique id>]. The data is stored into the *tuc file, which can be read from the second pass.
Luigi, I'm afraid it doesn't work as expected in the real file Lines are numbered there with [step=5]. So I get in headers only actually numbered lines, although it header should contain the real line numbers (even with the line number isn't shown on that line). How would it the the code in that case? (Sorry for asking this, but I'm afraid I cannot code in lua [or in any other language].) Many thanks for your help, Pablo -- http://www.ousia.tk
2012/3/6 Pablo Rodríguez
On 05/03/12 15:12, luigi scarso wrote:
2012/3/4 Pablo Rodríguez If you allow me one more question: is showing the numbers on the same page they refer to beyond the limits of TeX/LuaTeX?
Absolutely no. As Hans said, a quick/dirty trick is possible: just mark the object with \pagereference[<unique id>]. The data is stored into the *tuc file, which can be read from the second pass.
Luigi, I'm afraid it doesn't work as expected in the real file
I'm not surprised....
Lines are numbered there with [step=5]. So I get in headers only actually numbered lines, although it header should contain the real line numbers (even with the line number isn't shown on that line).
How would it the the code in that case? (Sorry for asking this, but I'm afraid I cannot code in lua [or in any other language].)
Many thanks for your help,
Do you have an example ? -- luigi
On 06/03/12 19:48, luigi scarso wrote:
2012/3/6 Pablo Rodríguez
Luigi, I'm afraid it doesn't work as expected in the real file
I'm not surprised....
My fault, because I didn' realize that numbers only appeared on each fifth line.
Lines are numbered there with [step=5]. So I get in headers only actually numbered lines, although it header should contain the real line numbers (even with the line number isn't shown on that line).
How would it the the code in that case? (Sorry for asking this, but I'm afraid I cannot code in lua [or in any other language].)
Do you have an example ?
Adapting from your code: \startluacode document.my_name_space = document.my_name_space or {} document.my_name_space.pages = document.my_name_space.pages or {} local f = io.open(file.addsuffix(tex.jobname,"tuc") ) print('>>>>> ',f) if f==nil then --[=[ do nothin ]=] else f:close() local tuc = dofile(file.addsuffix(tex.jobname,"tuc")) local data = tuc.structures.references.collected[""] local w local pages = document.my_name_space.pages local realpage,ref for k, v in pairs(data) do w=string.gmatch(k,'LIN:(\%d+):\%d+') ref = tonumber(w()) realpage = tostring(v.references.realpage) pages[realpage]= pages[realpage] or {} table.insert(pages[realpage],ref) end for page,array in pairs(pages) do table.sort(array) end end \stopluacode \definemarking[linenumber] \define\LinenumberCommand {\normalexpanded{\setmarking[linenumber]{\linenumber}}\pagereference[LIN:\linenumber:\currentpage]} \setuplinenumbering[command=\LinenumberCommand,step=5] \startsetups linenumber \startluacode local l=0; if document.my_name_space == nil then return end; if document.my_name_space.pages == nil then return end; local pages = document.my_name_space.pages; for _,_ in pairs(pages) do l=l+1 end; if l== 0 then return end; --[=[ OK, we have some data to print ]=] local array = pages[tostring(tex.count.realpageno)] l=0; if array ==nil then return end; for _,_ in pairs(array) do l=l+1 end; if l>0 then context(array[1].." -- "..array[l]) end; \stopluacode \stopsetups \setupheadertexts[\texsetup{linenumber}] \starttext \dorecurse{6}{\input tufte\par} \startlinenumbering \dorecurse{20}{\input knuth\par} \stoplinenumbering \startlinenumbering \dorecurse{20}{\input knuth\par} \stoplinenumbering \stoptext On page 7 lines are numbered from lowest to highest values. A purist might consider this wrong, but this is unlikely to happen on a real book, since (I guess) line numbers on headers only make sense when they two different series cannot be on the same page. Many thanks for your help, Pablo -- http://www.ousia.tk
2012/3/6 Pablo Rodríguez
On page 7 lines are numbered from lowest to highest values. A purist might consider this wrong, but this is unlikely to happen on a real book, since (I guess) line numbers on headers only make sense when they two different series cannot be on the same page.
Many thanks for your help,
I see but ... how do you want to manage this situation ?
-- luigi
On 06/03/12 20:27, luigi scarso wrote:
2012/3/6 Pablo Rodríguez
On page 7 lines are numbered from lowest to highest values. A purist might consider this wrong, but this is unlikely to happen on a real book, since (I guess) line numbers on headers only make sense when they two different series cannot be on the same page.
Many thanks for your help,
I see but ... how do you want to manage this situation ?
In that particular case, I have no idea. I number lines by chapter, so it is impossible that I would face this situation. The canonical way to handle that would be to get the number from first line on the page and number from last line on the page. The header would be in that case "198--27", which doesn't make any sense. Since this is a hack for other purpose, you can simply ignore it. Thanks for your help, Pablo -- http://www.ousia.tk
On 06/03/12 20:27, luigi scarso wrote:
2012/3/6 Pablo Rodríguez
mailto:oinos@web.de> On page 7 lines are numbered from lowest to highest values. A purist might consider this wrong, but this is unlikely to happen on a real book, since (I guess) line numbers on headers only make sense when they two different series cannot be on the same page.
Many thanks for your help,
I see but ... how do you want to manage this situation?
Hi Luigi, sorry, but it seems that my reply to your question wasn't explaining at all. I'm really interested in your hack (from http://www.ntg.nl/pipermail/ntg-context/2012/065588.html). I would really appreciate, if the hack could print in the header the numbers from the first or the last lines that appear on page. It might not be the lowest and highest values and it lines may not show numbers (due to step=5). Many thanks for your help, Pablo -- http://www.ousia.tk
2012/3/18 Pablo Rodríguez
On 06/03/12 20:27, luigi scarso wrote:
2012/3/6 Pablo Rodríguez
mailto:oinos@web.de> On page 7 lines are numbered from lowest to highest values. A purist might consider this wrong, but this is unlikely to happen on a real book, since (I guess) line numbers on headers only make sense when they two different series cannot be on the same page.
Many thanks for your help,
I see but ... how do you want to manage this situation?
Hi Luigi,
sorry, but it seems that my reply to your question wasn't explaining at all.
I'm really interested in your hack (from http://www.ntg.nl/pipermail/ntg-context/2012/065588.html).
I would really appreciate, if the hack could print in the header the numbers from the first or the last lines that appear on page. It might not be the lowest and highest values and it lines may not show numbers (due to step=5).
Many thanks for your help, hm I think to understand, but I need an example ( "I have this but I want that") with the code that you are using .
-- luigi
On 4-3-2012 11:20, Pablo Rodríguez wrote:
\starttext \startlinenumbering \dorecurse{10}{\input zapf\par\input knuth} \stoplinenumbering \stoptext
currently it's not possible but it's no big deal to add that feature at some point as it's a matter of keeping track of first/last numbers; for the page it's trivial but as we also support numbering in columns and other places some housekeeping is needed (read: a quick hack is possible but I will only do a proper solution) Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On 05/03/12 11:39, Hans Hagen wrote:
On 4-3-2012 11:20, Pablo Rodríguez wrote:
\starttext \startlinenumbering \dorecurse{10}{\input zapf\par\input knuth} \stoplinenumbering \stoptext
currently it's not possible but it's no big deal to add that feature at some point as it's a matter of keeping track of first/last numbers; for the page it's trivial but as we also support numbering in columns and other places some housekeeping is needed (read: a quick hack is possible but I will only do a proper solution)
Many thanks for your reply, Hans. I think that implemented a proper ConTeXt solution would be useful for other users. I would really appreciate it, if a solution could be implemented. Many thanks again for your help, Pablo -- http://www.ousia.tk
participants (4)
-
Hans Hagen
-
luigi scarso
-
Pablo Rodríguez
-
Wolfgang Schuster