* xml syntax for \externalfigure
@ 2011-06-03 19:23 Thomas A. Schmitz
2011-06-03 19:57 ` Aditya Mahajan
0 siblings, 1 reply; 9+ messages in thread
From: Thomas A. Schmitz @ 2011-06-03 19:23 UTC (permalink / raw)
To: mailing ConTeXt users list for
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
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: xml syntax for \externalfigure
2011-06-03 19:23 xml syntax for \externalfigure Thomas A. Schmitz
@ 2011-06-03 19:57 ` Aditya Mahajan
2011-06-03 20:19 ` Thomas A. Schmitz
0 siblings, 1 reply; 9+ messages in thread
From: Aditya Mahajan @ 2011-06-03 19:57 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: xml syntax for \externalfigure
2011-06-03 19:57 ` Aditya Mahajan
@ 2011-06-03 20:19 ` Thomas A. Schmitz
2011-06-03 20:28 ` Thomas A. Schmitz
2011-06-03 20:50 ` Hans Hagen
0 siblings, 2 replies; 9+ messages in thread
From: Thomas A. Schmitz @ 2011-06-03 20:19 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: xml syntax for \externalfigure
2011-06-03 20:19 ` Thomas A. Schmitz
@ 2011-06-03 20:28 ` Thomas A. Schmitz
2011-06-03 20:50 ` Hans Hagen
1 sibling, 0 replies; 9+ messages in thread
From: Thomas A. Schmitz @ 2011-06-03 20:28 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: xml syntax for \externalfigure
2011-06-03 20:19 ` Thomas A. Schmitz
2011-06-03 20:28 ` Thomas A. Schmitz
@ 2011-06-03 20:50 ` Hans Hagen
2011-06-03 20:56 ` Thomas A. Schmitz
1 sibling, 1 reply; 9+ messages in thread
From: Hans Hagen @ 2011-06-03 20:50 UTC (permalink / raw)
To: mailing list for ConTeXt users; +Cc: Thomas A. Schmitz
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
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: xml syntax for \externalfigure
2011-06-03 20:50 ` Hans Hagen
@ 2011-06-03 20:56 ` Thomas A. Schmitz
2011-06-03 22:14 ` Peter Münster
0 siblings, 1 reply; 9+ messages in thread
From: Thomas A. Schmitz @ 2011-06-03 20:56 UTC (permalink / raw)
To: Hans Hagen; +Cc: mailing list for ConTeXt users
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
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: xml syntax for \externalfigure
2011-06-03 20:56 ` Thomas A. Schmitz
@ 2011-06-03 22:14 ` Peter Münster
2011-06-03 22:24 ` Hans Hagen
2011-06-04 20:35 ` Thomas A. Schmitz
0 siblings, 2 replies; 9+ messages in thread
From: Peter Münster @ 2011-06-03 22:14 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: xml syntax for \externalfigure
2011-06-03 22:14 ` Peter Münster
@ 2011-06-03 22:24 ` Hans Hagen
2011-06-04 20:35 ` Thomas A. Schmitz
1 sibling, 0 replies; 9+ messages in thread
From: Hans Hagen @ 2011-06-03 22:24 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: xml syntax for \externalfigure
2011-06-03 22:14 ` Peter Münster
2011-06-03 22:24 ` Hans Hagen
@ 2011-06-04 20:35 ` Thomas A. Schmitz
1 sibling, 0 replies; 9+ messages in thread
From: Thomas A. Schmitz @ 2011-06-04 20:35 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2011-06-04 20:35 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-03 19:23 xml syntax for \externalfigure Thomas A. Schmitz
2011-06-03 19:57 ` Aditya Mahajan
2011-06-03 20:19 ` Thomas A. Schmitz
2011-06-03 20:28 ` Thomas A. Schmitz
2011-06-03 20:50 ` Hans Hagen
2011-06-03 20:56 ` Thomas A. Schmitz
2011-06-03 22:14 ` Peter Münster
2011-06-03 22:24 ` Hans Hagen
2011-06-04 20:35 ` Thomas A. Schmitz
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).