From: luigi scarso <luigi.scarso@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: is it possible to have first and last line numbers from page?
Date: Mon, 5 Mar 2012 15:12:22 +0100 [thread overview]
Message-ID: <CAG5iGsA3dDqm5BNnU+5uWGfPt-2PHx5g_Q1yf_SRF9Y13DO49w@mail.gmail.com> (raw)
In-Reply-To: <4F535CCC.2030902@web.de>
[-- Attachment #1.1: Type: text/plain, Size: 2983 bytes --]
2012/3/4 Pablo Rodríguez <oinos@web.de>
> 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?
>
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
[-- Attachment #1.2: Type: text/html, Size: 3779 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
___________________________________________________________________________________
next prev parent reply other threads:[~2012-03-05 14:12 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-04 10:20 Pablo Rodríguez
2012-03-04 11:04 ` Wolfgang Schuster
2012-03-04 12:15 ` Pablo Rodríguez
2012-03-04 13:44 ` Wolfgang Schuster
2012-03-04 17:36 ` Pablo Rodríguez
2012-03-05 14:12 ` luigi scarso [this message]
2012-03-06 17:01 ` Pablo Rodríguez
2012-03-06 17:33 ` Pablo Rodríguez
2012-03-06 18:48 ` luigi scarso
2012-03-06 19:16 ` Pablo Rodríguez
2012-03-06 19:27 ` luigi scarso
2012-03-06 19:42 ` Pablo Rodríguez
2012-03-18 17:12 ` Pablo Rodríguez
2012-03-18 21:33 ` luigi scarso
2012-03-05 10:39 ` Hans Hagen
2012-03-06 17:04 ` Pablo Rodríguez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAG5iGsA3dDqm5BNnU+5uWGfPt-2PHx5g_Q1yf_SRF9Y13DO49w@mail.gmail.com \
--to=luigi.scarso@gmail.com \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).