* XML and math
@ 2019-01-10 21:26 Aditya Mahajan
2019-01-10 22:00 ` Henri Menke
2019-01-10 22:08 ` Hans Hagen
0 siblings, 2 replies; 6+ messages in thread
From: Aditya Mahajan @ 2019-01-10 21:26 UTC (permalink / raw)
To: mailing list for ConTeXt users
Hi,
I have an XML file (which is generated via a program that I have no
control over), which contains elements as follows:
<p>
<equation text="$$y_1(t) = 1, t \geq 0$$">
<img alt="$$y_1(t) = 1, t \geq 0$$" class="equation"
height="15px" src="Lab01_eq10401623798909303081.png" width="95px"/>
</equation>
</p>
I want to typeset the `text` attribute of equation (and ignore the <img>
tag). So, I tried:
\startxmlsetups matlab
% Bunch of missing definitions
\xmlsetsetup{#1}{equation}{matlab:*}
\stopxmlsetups
\startxmlsetups matlab:equation
\xmlatt{#1}{text}
\stopxmlsetups
This literally typesets `$$y_1(t) = 1, t \geq 0$$`. How can I flush the
attribute using ctxcatcodes? (There is \xmlflushcontent, but that is for
content and not attributes).
Thanks,
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://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: XML and math
2019-01-10 21:26 XML and math Aditya Mahajan
@ 2019-01-10 22:00 ` Henri Menke
2019-01-10 22:09 ` Aditya Mahajan
2019-01-10 22:08 ` Hans Hagen
1 sibling, 1 reply; 6+ messages in thread
From: Henri Menke @ 2019-01-10 22:00 UTC (permalink / raw)
To: ntg-context
On 11/01/19 10:26 AM, Aditya Mahajan wrote:
> Hi,
>
> I have an XML file (which is generated via a program that I have no
> control over), which contains elements as follows:
>
> <p>
> <equation text="$$y_1(t) = 1, t \geq 0$$">
> <img alt="$$y_1(t) = 1, t \geq 0$$" class="equation"
> height="15px" src="Lab01_eq10401623798909303081.png" width="95px"/>
> </equation>
> </p>
>
> I want to typeset the `text` attribute of equation (and ignore the <img>
> tag). So, I tried:
>
> \startxmlsetups matlab
> % Bunch of missing definitions
> \xmlsetsetup{#1}{equation}{matlab:*}
> \stopxmlsetups
>
> \startxmlsetups matlab:equation
> \xmlatt{#1}{text}
> \stopxmlsetups
>
> This literally typesets `$$y_1(t) = 1, t \geq 0$$`. How can I flush the
> attribute using ctxcatcodes? (There is \xmlflushcontent, but that is for
> content and not attributes).
You could write your own attribute fetcher in Lua. Probably there is a
more elegant method.
\startbuffer[test]
<p>
<equation text="$$y_1(t) = 1, t \geq 0$$">
<img alt="$$y_1(t) = 1, t \geq 0$$" class="equation"
height="15px" src="Lab01_eq10401623798909303081.png" width="95px"/>
</equation>
</p>
\stopbuffer
\startxmlsetups matlab
% Bunch of missing definitions
\xmlsetsetup{#1}{p}{matlab:*}
\xmlsetsetup{#1}{equation}{matlab:*}
\stopxmlsetups
\startxmlsetups matlab:p
\xmlflush{#1}
\stopxmlsetups
\startxmlsetups matlab:equation
\xmlfunction{#1}{equation}
\stopxmlsetups
\startluacode
local a = "text"
local ctxcatcodes = catcodes.numbers.ctxcatcodes
function xml.functions.equation(id)
local e = lxml.getid(id)
if e then
local at = e.at
if at then
local att = at[a]
if att ~= "" then
context.sprint(ctxcatcodes,att)
end
end
end
end
\stopluacode
\xmlregistersetup{matlab}
\starttext
\xmlprocessbuffer{test}{test}{}
\stoptext
>
> Thanks,
> 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://context.aanhet.net
> archive : https://bitbucket.org/phg/context-mirror/commits/
> wiki : http://contextgarden.net
> ___________________________________________________________________________________
___________________________________________________________________________________
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://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: XML and math
2019-01-10 22:00 ` Henri Menke
@ 2019-01-10 22:09 ` Aditya Mahajan
0 siblings, 0 replies; 6+ messages in thread
From: Aditya Mahajan @ 2019-01-10 22:09 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1: Type: text/plain, Size: 2295 bytes --]
On Fri, 11 Jan 2019, Henri Menke wrote:
> On 11/01/19 10:26 AM, Aditya Mahajan wrote:
>> Hi,
>>
>> I have an XML file (which is generated via a program that I have no
>> control over), which contains elements as follows:
>>
>> <p>
>> <equation text="$$y_1(t) = 1, t \geq 0$$">
>> <img alt="$$y_1(t) = 1, t \geq 0$$" class="equation"
>> height="15px" src="Lab01_eq10401623798909303081.png" width="95px"/>
>> </equation>
>> </p>
>>
>> I want to typeset the `text` attribute of equation (and ignore the <img>
>> tag). So, I tried:
>>
>> \startxmlsetups matlab
>> % Bunch of missing definitions
>> \xmlsetsetup{#1}{equation}{matlab:*}
>> \stopxmlsetups
>>
>> \startxmlsetups matlab:equation
>> \xmlatt{#1}{text}
>> \stopxmlsetups
>>
>> This literally typesets `$$y_1(t) = 1, t \geq 0$$`. How can I flush the
>> attribute using ctxcatcodes? (There is \xmlflushcontent, but that is for
>> content and not attributes).
>
> You could write your own attribute fetcher in Lua. Probably there is a
> more elegant method.
>
> \startbuffer[test]
> <p>
> <equation text="$$y_1(t) = 1, t \geq 0$$">
> <img alt="$$y_1(t) = 1, t \geq 0$$" class="equation"
> height="15px" src="Lab01_eq10401623798909303081.png" width="95px"/>
> </equation>
> </p>
> \stopbuffer
>
> \startxmlsetups matlab
> % Bunch of missing definitions
> \xmlsetsetup{#1}{p}{matlab:*}
> \xmlsetsetup{#1}{equation}{matlab:*}
> \stopxmlsetups
>
> \startxmlsetups matlab:p
> \xmlflush{#1}
> \stopxmlsetups
>
> \startxmlsetups matlab:equation
> \xmlfunction{#1}{equation}
> \stopxmlsetups
> \startluacode
> local a = "text"
> local ctxcatcodes = catcodes.numbers.ctxcatcodes
>
> function xml.functions.equation(id)
> local e = lxml.getid(id)
> if e then
> local at = e.at
> if at then
> local att = at[a]
> if att ~= "" then
> context.sprint(ctxcatcodes,att)
> end
> end
> end
> end
> \stopluacode
>
> \xmlregistersetup{matlab}
>
> \starttext
> \xmlprocessbuffer{test}{test}{}
> \stoptext
Thanks!
Aditya
[-- Attachment #2: Type: text/plain, Size: 492 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://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: XML and math
2019-01-10 21:26 XML and math Aditya Mahajan
2019-01-10 22:00 ` Henri Menke
@ 2019-01-10 22:08 ` Hans Hagen
2019-01-10 23:21 ` Aditya Mahajan
1 sibling, 1 reply; 6+ messages in thread
From: Hans Hagen @ 2019-01-10 22:08 UTC (permalink / raw)
To: mailing list for ConTeXt users, Aditya Mahajan
On 1/10/2019 10:26 PM, Aditya Mahajan wrote:
> Hi,
>
> I have an XML file (which is generated via a program that I have no
> control over), which contains elements as follows:
>
> <p>
> <equation text="$$y_1(t) = 1, t \geq 0$$">
> <img alt="$$y_1(t) = 1, t \geq 0$$" class="equation"
> height="15px" src="Lab01_eq10401623798909303081.png" width="95px"/>
> </equation>
> </p>
>
> I want to typeset the `text` attribute of equation (and ignore the <img>
> tag). So, I tried:
>
> \startxmlsetups matlab
> % Bunch of missing definitions
> \xmlsetsetup{#1}{equation}{matlab:*}
> \stopxmlsetups
>
> \startxmlsetups matlab:equation
> \xmlatt{#1}{text}
> \stopxmlsetups
>
> This literally typesets `$$y_1(t) = 1, t \geq 0$$`. How can I flush the
> attribute using ctxcatcodes? (There is \xmlflushcontent, but that is for
> content and not attributes).
Time for an "aha, I knew it" moment ...
\starttext
\startbuffer[test]
<p>
<equation text="$$y_1(t) = 1, t \geq 0$$">
<img alt="$$y_1(t) = 1, t \geq 0$$" class="equation"
height="15px" src="Lab01_eq10401623798909303081.png" width="95px"/>
</equation>
</p>
\stopbuffer
\startxmlsetups whatever
\xmlsetsetup{#1}{p|equation}{xml:*}
\stopxmlsetups
\xmlregistersetup{whatever}
\startxmlsetups xml:p
\xmlflush{#1}
\stopxmlsetups
\startxmlsetups xml:equation
\cldcontext{lxml.getid("#1").at.text}
\stopxmlsetups
\startxmlsetups xml:equation
\startformula
\cldcontext{(string.gsub(lxml.getid("#1").at.text,"[$][$]",""))}
\stopformula
\stopxmlsetups
\xmlprocessbuffer{main}{test}{}
\stoptext
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | www.pragma-ade.nl | 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://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: XML and math
2019-01-10 22:08 ` Hans Hagen
@ 2019-01-10 23:21 ` Aditya Mahajan
2019-01-11 1:28 ` Aditya Mahajan
0 siblings, 1 reply; 6+ messages in thread
From: Aditya Mahajan @ 2019-01-10 23:21 UTC (permalink / raw)
To: Hans Hagen; +Cc: mailing list for ConTeXt users
[-- Attachment #1: Type: text/plain, Size: 1658 bytes --]
On Thu, 10 Jan 2019, Hans Hagen wrote:
> On 1/10/2019 10:26 PM, Aditya Mahajan wrote:
>> Hi,
>>
>> I have an XML file (which is generated via a program that I have no control
>> over), which contains elements as follows:
>>
>> <p>
>> <equation text="$$y_1(t) = 1, t \geq 0$$">
>> <img alt="$$y_1(t) = 1, t \geq 0$$" class="equation"
>> height="15px" src="Lab01_eq10401623798909303081.png" width="95px"/>
>> </equation>
>> </p>
>>
>> I want to typeset the `text` attribute of equation (and ignore the <img>
>> tag). So, I tried:
>>
>> \startxmlsetups matlab
>> % Bunch of missing definitions
>> \xmlsetsetup{#1}{equation}{matlab:*}
>> \stopxmlsetups
>>
>> \startxmlsetups matlab:equation
>> \xmlatt{#1}{text}
>> \stopxmlsetups
>>
>> This literally typesets `$$y_1(t) = 1, t \geq 0$$`. How can I flush the
>> attribute using ctxcatcodes? (There is \xmlflushcontent, but that is for
>> content and not attributes).
> Time for an "aha, I knew it" moment ...
:-) Thanks.
Follow-up question: How do I escape entities inside the attributes. One
snippet is:
<p>
<equation text="$$x_2(t) = \begin{cases} t, & 0 \leq t
< 5 \\ -t+10, & t \geq
5\end{cases}$$">$$x_2(t) =
\begin{cases} t, & 0 \leq t < 5 \\ -t+10, & t \geq
5\end{cases}$$</equation>
</p>
This contains `
` which I want to convert to either newline or blank.
(I have to use the text attribute. The content has the right information
in this particular instance due to a bug in the conversion)
Aditya
[-- Attachment #2: Type: text/plain, Size: 492 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://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: XML and math
2019-01-10 23:21 ` Aditya Mahajan
@ 2019-01-11 1:28 ` Aditya Mahajan
0 siblings, 0 replies; 6+ messages in thread
From: Aditya Mahajan @ 2019-01-11 1:28 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1: Type: text/plain, Size: 1489 bytes --]
On Thu, 10 Jan 2019, Aditya Mahajan wrote:
> On Thu, 10 Jan 2019, Hans Hagen wrote:
>
>> On 1/10/2019 10:26 PM, Aditya Mahajan wrote:
>>> Hi,
>>>
>>> I have an XML file (which is generated via a program that I have no
>>> control over), which contains elements as follows:
>>>
>>> <p>
>>> <equation text="$$y_1(t) = 1, t \geq 0$$">
>>> <img alt="$$y_1(t) = 1, t \geq 0$$" class="equation"
>>> height="15px" src="Lab01_eq10401623798909303081.png" width="95px"/>
>>> </equation>
>>> </p>
>>>
>>> I want to typeset the `text` attribute of equation (and ignore the <img>
>>> tag). So, I tried:
>>>
>>> \startxmlsetups matlab
>>> % Bunch of missing definitions
>>> \xmlsetsetup{#1}{equation}{matlab:*}
>>> \stopxmlsetups
>>>
>>> \startxmlsetups matlab:equation
>>> \xmlatt{#1}{text}
>>> \stopxmlsetups
>>>
>>> This literally typesets `$$y_1(t) = 1, t \geq 0$$`. How can I flush the
>>> attribute using ctxcatcodes? (There is \xmlflushcontent, but that is for
>>> content and not attributes).
>> Time for an "aha, I knew it" moment ...
>
> This contains `
` which I want to convert to either newline or blank.
Some debugging showed that the entity was being translated correctly. I
was typesetting the output under texcatcodes, which was causing the
problem. Setting formfeedasciicode and endoflineasciicode to ignorecatcode
made everything work correctly.
Aditya
[-- Attachment #2: Type: text/plain, Size: 492 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://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-01-11 1:28 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-10 21:26 XML and math Aditya Mahajan
2019-01-10 22:00 ` Henri Menke
2019-01-10 22:09 ` Aditya Mahajan
2019-01-10 22:08 ` Hans Hagen
2019-01-10 23:21 ` Aditya Mahajan
2019-01-11 1:28 ` Aditya Mahajan
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).