Hi all, I'm pulling my hair - thought this was easy, but turns out to be more difficult. The \externalfigure command can take a width and/or a height parameter, and context will be happy to take either one into account. I'm trying to translate that into xml syntax. Here's a minimal example that I can't make work. If anyone can explain what to do here, I might be able to work this out (or will be back with more questions :-) \startbuffer[test] <a> <externalfigure height="1cm" resource="hacker"/> </a> \stopbuffer \startxmlsetups xml:testsetups \xmlsetsetup{\xmldocument}{a|externalfigure}{xml:*} \stopxmlsetups \xmlregistersetup{xml:testsetups} \startxmlsetups xml:a \xmlflush{#1}\par \stopxmlsetups \startxmlsetups xml:externalfigure \externalfigure[\xmlatt{#1}{resource}] [\doifnotempty{\xmlatt{#1}{height}}{height=\xmlatt{#1}{height}}] \stopxmlsetups \starttext \xmlprocessbuffer{main}{test}{} \stoptext The "height" attribute is not taken into account - why? All best Thomas
On Fri, 3 Jun 2011, Thomas A. Schmitz wrote:
Hi all,
I'm pulling my hair - thought this was easy, but turns out to be more difficult. The \externalfigure command can take a width and/or a height parameter, and context will be happy to take either one into account. I'm trying to translate that into xml syntax. Here's a minimal example that I can't make work. If anyone can explain what to do here, I might be able to work this out (or will be back with more questions :-)
\startbuffer[test] <a> <externalfigure height="1cm" resource="hacker"/> </a> \stopbuffer
\startxmlsetups xml:testsetups \xmlsetsetup{\xmldocument}{a|externalfigure}{xml:*} \stopxmlsetups
\xmlregistersetup{xml:testsetups}
\startxmlsetups xml:a \xmlflush{#1}\par \stopxmlsetups
\startxmlsetups xml:externalfigure \externalfigure[\xmlatt{#1}{resource}] [\doifnotempty{\xmlatt{#1}{height}}{height=\xmlatt{#1}{height}}] \stopxmlsetups
(untested) \exeternalfigure[...][height=\doifemptyelse{\xmlatt{#1}{height}}{fit}{\xmlatt{#1}{height}}] Aditya
On Jun 3, 2011, at 9:57 PM, Aditya Mahajan wrote:
(untested)
\exeternalfigure[...][height=\doifemptyelse{\xmlatt{#1}{height}}{fit}{\xmlatt{#1}{height}}]
Aditya
Hmm, almost... Gives the dreaded "Missing number, treated as zero" error. But your "fit" gave me an idea: this works: [height=\xmlattdef{#1}{height}{fit}] but only if I have a real dimension as in height="5cm". What if I want to define something like height="0.4" and want this to be the equivalent of height=0.4\textheight ? This of course doesn't work: [height=\xmlattdef{#1}{height}{fit}\textheight] since it will expand to "fit\textheight" as a default option. Any suggestions? Thomas
On Jun 3, 2011, at 10:19 PM, Thomas A. Schmitz wrote:
Hmm, almost... Gives the dreaded "Missing number, treated as zero" error. But your "fit" gave me an idea: this works:
[height=\xmlattdef{#1}{height}{fit}]
but only if I have a real dimension as in height="5cm". What if I want to define something like height="0.4" and want this to be the equivalent of height=0.4\textheight ? This of course doesn't work:
[height=\xmlattdef{#1}{height}{fit}\textheight]
since it will expand to "fit\textheight" as a default option. Any suggestions?
Thomas
Answering my own question: this isn't pretty, but it does what I need at this moment: \startxmlsetups xml:externalfigure \doifemptyelse {\xmlatt{#1}{heigth}} {\externalfigure[\xmlatt{#1}{resource}] [width=\xmlatt{#1}{width}\textwidth]} {\externalfigure[\xmlatt{#1}{resource}] [height=\xmlatt{#1}{height}\textheight]} \stopxmlsetups So I'll leave it at that... Thomas
On 3-6-2011 10:19, Thomas A. Schmitz wrote:
On Jun 3, 2011, at 9:57 PM, Aditya Mahajan wrote:
(untested)
\exeternalfigure[...][height=\doifemptyelse{\xmlatt{#1}{height}}{fit}{\xmlatt{#1}{height}}]
Aditya
Hmm, almost... Gives the dreaded "Missing number, treated as zero" error. But your "fit" gave me an idea: this works:
[height=\xmlattdef{#1}{height}{fit}]
but only if I have a real dimension as in height="5cm". What if I want to define something like height="0.4" and want this to be the equivalent of height=0.4\textheight ? This of course doesn't work:
[height=\xmlattdef{#1}{height}{fit}\textheight]
since it will expand to "fit\textheight" as a default option. Any suggestions?
something (slow): \expdoifelse {\xmlattdef{#1}{height}{fit} {fit} {\xmlatt{#1}{height}\textheight} (of you define a lua helper) ----------------------------------------------------------------- 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 Jun 3, 2011, at 10:50 PM, Hans Hagen wrote:
On 3-6-2011 10:19, Thomas A. Schmitz wrote:
Hmm, almost... Gives the dreaded "Missing number, treated as zero" error. But your "fit" gave me an idea: this works:
[height=\xmlattdef{#1}{height}{fit}]
but only if I have a real dimension as in height="5cm". What if I want to define something like height="0.4" and want this to be the equivalent of height=0.4\textheight ? This of course doesn't work:
[height=\xmlattdef{#1}{height}{fit}\textheight]
since it will expand to "fit\textheight" as a default option. Any suggestions?
something (slow):
\expdoifelse {\xmlattdef{#1}{height}{fit} {fit} {\xmlatt{#1}{height}\textheight}
(of you define a lua helper)
Ah, expdoifelse is for "expanded doifelse," right? Any examples for such a lua helper? Sounds good, but I still haven't been able to understand how to mix xml and lua code. Thanks! Thomas
On Fri, Jun 03 2011, Thomas A. Schmitz wrote:
Ah, expdoifelse is for "expanded doifelse," right? Any examples for such a lua helper? Sounds good, but I still haven't been able to understand how to mix xml and lua code.
\startluacode function my_externalfigure(file, t) local args_present for k, v in pairs(t) do if v == "" then t[k] = nil else args_present = true end end context.externalfigure({file}, args_present and t) end \stopluacode \startxmlsetups xml:externalfigure \ctxlua{my_externalfigure("\xmlatt{#1}{resource}", {width = "\xmlatt{#1}{width}", height = "\xmlatt{#1}{height}"})} \stopxmlsetups My first idea was "\expanded{\externalfigure[...][\doif...]}" but it does not work... -- Peter
On 4-6-2011 12:14, Peter Münster wrote:
On Fri, Jun 03 2011, Thomas A. Schmitz wrote:
Ah, expdoifelse is for "expanded doifelse," right? Any examples for such a lua helper? Sounds good, but I still haven't been able to understand how to mix xml and lua code.
\startluacode function my_externalfigure(file, t) local args_present for k, v in pairs(t) do if v == "" then t[k] = nil else args_present = true end end context.externalfigure({file}, args_present and t) end \stopluacode
\startxmlsetups xml:externalfigure \ctxlua{my_externalfigure("\xmlatt{#1}{resource}", {width = "\xmlatt{#1}{width}", height = "\xmlatt{#1}{height}"})} \stopxmlsetups
My first idea was "\expanded{\externalfigure[...][\doif...]}" but it does not work...
you can consider passing #1 and using lxml.att at the lua end or go even further and pop in your own finalizer ----------------------------------------------------------------- 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 Jun 4, 2011, at 12:14 AM, Peter Münster wrote:
\startluacode function my_externalfigure(file, t) local args_present for k, v in pairs(t) do if v == "" then t[k] = nil else args_present = true end end context.externalfigure({file}, args_present and t) end \stopluacode
\startxmlsetups xml:externalfigure \ctxlua{my_externalfigure("\xmlatt{#1}{resource}", {width = "\xmlatt{#1}{width}", height = "\xmlatt{#1}{height}"})} \stopxmlsetups
My first idea was "\expanded{\externalfigure[...][\doif...]}" but it does not work...
Thanks a lot Peter, i will have to play with this tomorrow (just came home from a short trip). Thomas
participants (4)
-
Aditya Mahajan
-
Hans Hagen
-
pmlists@free.fr
-
Thomas A. Schmitz