[NTG-context] \placelist summary alternative solution

2011-12-14 Thread Felix Ingram
I've ended up delving into the dark art that is Lua for this solution:

\define[0]\SummaryTable{%
\placetable[force, none]{}{%
\setupTABLE[frame=off]
\bTABLE
\bTABLEhead
\bTR\bTH Reference\eTH\bTH Title\eTH\bTH Page\eTH\eTR
\eTABLEhead
\bTABLEbody
\startluacode
for k, v in ipairs(structures.lists.collected) do
if v.metadata.kind == section and v.metadata.name == section then
context.bTR()
context.bTD()
context(REFREF)
context.eTD()
context.bTD()
context(v.titledata.title)
context.eTD()
context.bTD()
context(v.references.realpage)
context.eTD()
context.eTR()
end
end
\stopluacode%
\eTABLEbody
\eTABLE
}%
}%
\starttext
\section{Test}
\input{knuth}
\section{Test}
\input{knuth}
\section{Test}
\input{knuth}
\section{Test}
\input{knuth}
\section{Test}
\input{knuth}
\section{Test}
\input{knuth}
\section{Test}
\input{knuth}
\SummaryTable
\stoptext

This works to some degree though I have the following questions about it:

1. Is there a way to access a document global variable from Lua? I
will use this to replace the REFREF text.

2. v.references.realpage isn't the actual page of the title. How can I
access the page number that would have appeared in the ToC? (I've
restarted the page numbering in my master doc, the above example works
fine)

3. Is there a way to store some metadata along with my title? I'd like
something similar to this:
\myheader[author=me, date=2011-12-14]{This is my header with meta-data}
and then be able to access it from Lua again.

Thanks for any help you can give with this.

Felix
___
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] \placelist summary alternative solution

2011-12-14 Thread Hans Hagen

On 14-12-2011 17:50, Felix Ingram wrote:

I've ended up delving into the dark art that is Lua for this solution:

\define[0]\SummaryTable{%
\placetable[force, none]{}{%
\setupTABLE[frame=off]
\bTABLE
\bTABLEhead
\bTR\bTH Reference\eTH\bTH Title\eTH\bTH Page\eTH\eTR
\eTABLEhead
\bTABLEbody
\startluacode
 for k, v in ipairs(structures.lists.collected) do
 if v.metadata.kind == section and v.metadata.name == section then
 context.bTR()
 context.bTD()
 context(REFREF)
 context.eTD()
 context.bTD()
 context(v.titledata.title)
 context.eTD()
 context.bTD()
 context(v.references.realpage)
 context.eTD()
 context.eTR()
 end
 end
\stopluacode%
\eTABLEbody
\eTABLE
}%
}%
\starttext
\section{Test}
\input{knuth}
\section{Test}
\input{knuth}
\section{Test}
\input{knuth}
\section{Test}
\input{knuth}
\section{Test}
\input{knuth}
\section{Test}
\input{knuth}
\section{Test}
\input{knuth}
\SummaryTable
\stoptext

This works to some degree though I have the following questions about it:

1. Is there a way to access a document global variable from Lua? I
will use this to replace the REFREF text.


\startluacode

document.myvariables = { }

document.myvariables.whatever = SOME TEXT

\stopluacode

...

context(document.myvariables.whatever)


2. v.references.realpage isn't the actual page of the title. How can I
access the page number that would have appeared in the ToC? (I've
restarted the page numbering in my master doc, the above example works
fine)


as you're looking into the code ... search for helpers like

lists.prefixedpage

keep in mind that this is not yet an official api (although it will 
probably stay this way)





3. Is there a way to store some metadata along with my title? I'd like
something similar to this:
\myheader[author=me, date=2011-12-14]{This is my header with meta-data}
and then be able to access it from Lua again.


it's called userdata (third argument to \startchapter etc) .. it travels 
with the rest


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