From thomas.schmitz@uni-bonn.de Tue Sep 11 19:22:19 2012 From: "Thomas A. Schmitz" To: ntg-context@ntg.nl Subject: [NTG-context] xml cross-references in lua? Date: Tue, 11 Sep 2012 19:22:13 +0200 Message-ID: <504F7345.6050309@uni-bonn.de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0313732580734734485==" --===============0313732580734734485== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Hi all, I have a question about xml processing and I think that what I want/need can best be achieved by using lua code, but so far, I'm not really sure how to proceed, so any help from one of the resident lua gurus would be welcome. So: the question. xml allows to provide elements with unique identifiers so that one can add cross-references within the document structure. Here is a sample xml file that shows what I mean: Hans Hagen The Meaning of Life Is 42 The Rhetoric of Mathematics 2011 Hans Hagen The New Meaning is Now 43 High Energy Metaphysics 2012

This has been successfully proven in papers by and .

[Note: the TEI guidelines add the hash character in the attribute value to such references, but after much googling, I'm still not sure if this is standard or necessary or bizarre.] So: at the point of the reference (which may be empty, like here, or contain text), I want to refer back to the bibitems. The typesetting engine should then be instructed to pick up the information, so that this is, e.g., typeset as "This has been successfully proven in papers by Hans Hagen (2011) and Hans Hagen (2012)." My idea: since the xml:id attributes must be unique across the document, it would be easiest to collect them into a lua table, with the xml:id as key, so their content could be accessed and typeset later. But unfortunately, I have no clue how to go about this... Could somebody provide a pointer? Thanks for your interest, if you've read this far! Thomas --===============0313732580734734485==-- From pragma@wxs.nl Tue Sep 11 20:18:31 2012 From: Hans Hagen To: ntg-context@ntg.nl Subject: Re: [NTG-context] xml cross-references in lua? Date: Tue, 11 Sep 2012 20:18:19 +0200 Message-ID: <504F806B.4010108@wxs.nl> In-Reply-To: <504F7345.6050309@uni-bonn.de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2376626942173803397==" --===============2376626942173803397== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On 11-9-2012 19:22, Thomas A. Schmitz wrote: > Hi all, > > I have a question about xml processing and I think that what I want/need > can best be achieved by using lua code, but so far, I'm not really sure > how to proceed, so any help from one of the resident lua gurus would be > welcome. > > So: the question. xml allows to provide elements with unique identifiers > so that one can add cross-references within the document structure. Here > is a sample xml file that shows what I mean: > > > > Hans Hagen > The Meaning of Life Is 42 > The Rhetoric of Mathematics > 2011 > > > Hans Hagen > The New Meaning is Now 43 > High Energy Metaphysics > 2012 > > >

This has been successfully proven in papers by ref=3D"#hagen2011"/> and .

>
>
> > [Note: the TEI guidelines add the hash character in the attribute value > to such references, but after much googling, I'm still not sure if this > is standard or necessary or bizarre.] > > So: at the point of the reference (which may be empty, like here, or > contain text), I want to refer back to the bibitems. The typesetting > engine should then be instructed to pick up the information, so that > this is, e.g., typeset as "This has been successfully proven in papers > by Hans Hagen (2011) and Hans Hagen (2012)." > > My idea: since the xml:id attributes must be unique across the document, > it would be easiest to collect them into a lua table, with the xml:id as > key, so their content could be accessed and typeset later. But > unfortunately, I have no clue how to go about this... Could somebody > provide a pointer? > > Thanks for your interest, if you've read this far! If the number of bib items is not that large hashing does not save much.=20 (In x-xfdf.mkiv you can see another example). \starttext \startbuffer[demo] Hans Hagen The Meaning of Life Is 42 The Rhetoric of Mathematics 2011 Hans Hagen The New Meaning is Now 43 High Energy Metaphysics 2012

This has been successfully proven in papers by and .

\stopbuffer \startxmlsetups xml:define \xmlsetsetup{#1}{*}{xml:*} \stopxmlsetups \startxmlsetups xml:document \xmlall{#1}{/text} \stopxmlsetups \startxmlsetups xml:text \xmlflush{#1} \stopxmlsetups \startxmlsetups xml:p \xmlflush{#1} \par \stopxmlsetups \startxmlsetups xml:bib \BibAuthor{#1}{\xmlatt{#1}{ref}} \stopxmlsetups \startxmlsetups xml:author [[\xmlflush{#1}]] \stopxmlsetups \def\BibAuthor#1#2{[1:\xmlfirst{whatever}{/document/bibitem[@xml:id=3D=3Dstri= ng.sub('#2',2)]/author}]} \xmlregistersetup{xml:define} \xmlprocessbuffer{whatever}{demo}{} \startluacode userdata =3D userdata or { } userdata.bibitems =3D { } \stopluacode \startxmlsetups xml:document \xmlflush{#1} \stopxmlsetups \startxmlsetups xml:bibitem \ctxlua{userdata.bibitems["\letterhash\xmlatt{#1}{xml:id}"] =3D "#1"} \stopxmlsetups \def\BibAuthor#1#2{[2:\xmlfirst{\cldcontext{userdata.bibitems['#2']}}{/author= }]} \xmlprocessbuffer{whatever}{demo}{} \stoptext (I ran into a recently introduced side effect of an optimization so I'll=20 generate you a new beta. Older versions should work anyway as no special=20 trickery is used.) 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 ----------------------------------------------------------------- --===============2376626942173803397==-- From thomas.schmitz@uni-bonn.de Wed Sep 12 08:32:56 2012 From: "Thomas A. Schmitz" To: ntg-context@ntg.nl Subject: Re: [NTG-context] xml cross-references in lua? Date: Wed, 12 Sep 2012 08:32:53 +0200 Message-ID: <50502C95.3030606@uni-bonn.de> In-Reply-To: <504F806B.4010108@wxs.nl> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============8379951171549731456==" --===============8379951171549731456== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On 09/11/2012 08:18 PM, Hans Hagen wrote: > > If the number of bib items is not that large hashing does not save > much. (In x-xfdf.mkiv you can see another example). > > \starttext > > \startbuffer[demo] > Hans Hagen The Meaning of Life Is 42 > The Rhetoric of Mathematics 2011 > Hans Hagen > The New Meaning is Now 43 High Energy > Metaphysics 2012

This has > been successfully proven in papers by and > .

\stopbuffer > > \startxmlsetups xml:define \xmlsetsetup{#1}{*}{xml:*} \stopxmlsetups > > \startxmlsetups xml:document \xmlall{#1}{/text} \stopxmlsetups > \startxmlsetups xml:text \xmlflush{#1} \stopxmlsetups \startxmlsetups > xml:p \xmlflush{#1} \par \stopxmlsetups > > \startxmlsetups xml:bib \BibAuthor{#1}{\xmlatt{#1}{ref}} > \stopxmlsetups > > \startxmlsetups xml:author [[\xmlflush{#1}]] \stopxmlsetups > > \def\BibAuthor#1#2{[1:\xmlfirst{whatever}{/document/bibitem[@xml:id=3D=3Dst= ring.sub('#2',2)]/author}]} > > > > \xmlregistersetup{xml:define} > > \xmlprocessbuffer{whatever}{demo}{} > > \startluacode userdata =3D userdata or { } userdata.bibitems =3D { } > \stopluacode > > \startxmlsetups xml:document \xmlflush{#1} \stopxmlsetups > > \startxmlsetups xml:bibitem > \ctxlua{userdata.bibitems["\letterhash\xmlatt{#1}{xml:id}"] =3D "#1"} > \stopxmlsetups > > \def\BibAuthor#1#2{[2:\xmlfirst{\cldcontext{userdata.bibitems['#2']}}{/auth= or}]} > > > > \xmlprocessbuffer{whatever}{demo}{} > > \stoptext > > (I ran into a recently introduced side effect of an optimization so > I'll generate you a new beta. Older versions should work anyway as no > special trickery is used.) > > Hans > Ah, wonderful, Hans, I can play with this! Thanks a lot for the swift reply and for the help, this will get me going! All best Thomas --===============8379951171549731456==--