* catch % in gsub("%", "\\letterpercent")
@ 2020-08-27 15:11 Pablo Rodriguez
2020-08-27 15:30 ` Taco Hoekwater
2020-08-27 15:39 ` Hans van der Meer
0 siblings, 2 replies; 8+ messages in thread
From: Pablo Rodriguez @ 2020-08-27 15:11 UTC (permalink / raw)
To: mailing list for ConTeXt users
Dear list,
I have and \xmlraw command that gives some text with percent signs.
ConTeXt parses them as comments (so no output).
Using Lua gsub(), I need to replace something like:
string.gsub([[\xmlraw{#1}{.}]], "%", "\\letterpercent")
How do I need to invoke % to get the character found?
Many thanks for your help,
Pablo
--
http://www.ousia.tk
___________________________________________________________________________________
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] 8+ messages in thread
* Re: catch % in gsub("%", "\\letterpercent")
2020-08-27 15:11 catch % in gsub("%", "\\letterpercent") Pablo Rodriguez
@ 2020-08-27 15:30 ` Taco Hoekwater
2020-08-27 15:56 ` Pablo Rodriguez
2020-08-27 15:39 ` Hans van der Meer
1 sibling, 1 reply; 8+ messages in thread
From: Taco Hoekwater @ 2020-08-27 15:30 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 483 bytes --]
Hi,
> On 27 Aug 2020, at 17:11, Pablo Rodriguez <oinos@gmx.es> wrote:
>
> Dear list,
>
> I have and \xmlraw command that gives some text with percent signs.
> ConTeXt parses them as comments (so no output).
>
> Using Lua gsub(), I need to replace something like:
>
> string.gsub([[\xmlraw{#1}{.}]], "%", "\\letterpercent")
Double it: %%
See also https://www.lua.org/manual/5.3/manual.html#6.4.1 , but the mention of %% is a bit hidden.
Best wishes,
Taco
[-- Attachment #1.2: Type: text/html, Size: 992 bytes --]
[-- Attachment #2: Type: text/plain, Size: 493 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] 8+ messages in thread
* Re: catch % in gsub("%", "\\letterpercent")
2020-08-27 15:30 ` Taco Hoekwater
@ 2020-08-27 15:56 ` Pablo Rodriguez
2020-08-27 16:16 ` Wolfgang Schuster
0 siblings, 1 reply; 8+ messages in thread
From: Pablo Rodriguez @ 2020-08-27 15:56 UTC (permalink / raw)
To: ntg-context
On 8/27/20 5:30 PM, Taco Hoekwater wrote:
>> [...]
>> Using Lua gsub(), I need to replace something like:
>>
>> string.gsub([[\xmlraw{#1}{.}]], "%", "\\letterpercent")
>
> Double it: %%
>
> See also https://www.lua.org/manual/5.3/manual.html#6.4.1 , but the
> mention of %% is a bit hidden.
Many thanks for your replies, Taco and Hans.
I’m afraid this doesn’t work (and I need \xmlraw there):
\startbuffer[demo]
<html>
<body>
<div id="First">
<p>The <span class="special">% best</span> paragraph.</p>
</div>
</body>
</html>
\stopbuffer
\startxmlsetups xml:initialize
\xmlsetsetup{#1}{html}{xml:gen}
\stopxmlsetups
\xmlregistersetup{xml:initialize}
\startxmlsetups xml:gen
\startitemize
\xmlfilter{#1}{/**/span[@class='special']/command(xml:special)}
\stopitemize
\stopxmlsetups
\startxmlsetups xml:special
\startitem
\cldcontext{string.gsub([[\xmlraw{#1}{.}]], "%%",
"\\letterpercent")}
\stopitem
\stopxmlsetups
\starttext
\xmlprocessbuffer{main}{demo}{}
\stoptext
What am I missing or doing wrong there?
Many thanks for your help,
Pablo
--
http://www.ousia.tk
___________________________________________________________________________________
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] 8+ messages in thread
* Re: catch % in gsub("%", "\\letterpercent")
2020-08-27 15:56 ` Pablo Rodriguez
@ 2020-08-27 16:16 ` Wolfgang Schuster
2020-08-27 17:16 ` Pablo Rodriguez
0 siblings, 1 reply; 8+ messages in thread
From: Wolfgang Schuster @ 2020-08-27 16:16 UTC (permalink / raw)
To: mailing list for ConTeXt users
Pablo Rodriguez schrieb am 27.08.2020 um 17:56:
> On 8/27/20 5:30 PM, Taco Hoekwater wrote:
>>> [...]
>>> Using Lua gsub(), I need to replace something like:
>>>
>>> string.gsub([[\xmlraw{#1}{.}]], "%", "\\letterpercent")
>>
>> Double it: %%
>>
>> See also https://www.lua.org/manual/5.3/manual.html#6.4.1 , but the
>> mention of %% is a bit hidden.
>
> Many thanks for your replies, Taco and Hans.
>
> I’m afraid this doesn’t work (and I need \xmlraw there):
>
> \startbuffer[demo]
> <html>
> <body>
> <div id="First">
> <p>The <span class="special">% best</span> paragraph.</p>
> </div>
> </body>
> </html>
> \stopbuffer
>
> \startxmlsetups xml:initialize
> \xmlsetsetup{#1}{html}{xml:gen}
> \stopxmlsetups
>
> \xmlregistersetup{xml:initialize}
>
> \startxmlsetups xml:gen
> \startitemize
> \xmlfilter{#1}{/**/span[@class='special']/command(xml:special)}
> \stopitemize
> \stopxmlsetups
>
> \startxmlsetups xml:special
> \startitem
> \cldcontext{string.gsub([[\xmlraw{#1}{.}]], "%%",
> "\\letterpercent")}
> \stopitem
> \stopxmlsetups
This works fine with your example
\startxmlsetups xml:special
\startitem
\xmlflush{#1}
\stopitem
\stopxmlsetups
and to escape special characters you can use context.escape()
\startxmlsetups xml:special
\startitem
\cldcontext{context.escape([[\xmlraw{#1}{.}]])}
\stopitem
\stopxmlsetups
Wolfgang
___________________________________________________________________________________
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] 8+ messages in thread
* Re: catch % in gsub("%", "\\letterpercent")
2020-08-27 16:16 ` Wolfgang Schuster
@ 2020-08-27 17:16 ` Pablo Rodriguez
2020-08-27 17:35 ` Wolfgang Schuster
0 siblings, 1 reply; 8+ messages in thread
From: Pablo Rodriguez @ 2020-08-27 17:16 UTC (permalink / raw)
To: ntg-context
On 8/27/20 6:16 PM, Wolfgang Schuster wrote:
> Pablo Rodriguez schrieb am 27.08.2020 um 17:56:
>> [...]
>> \startxmlsetups xml:special
>> \startitem
>> \cldcontext{string.gsub([[\xmlraw{#1}{.}]], "%%",
>> "\\letterpercent")}
>> \stopitem
>> \stopxmlsetups
> [...]
> and to escape special characters you can use context.escape()
Many thanks for your reply, Wolfgang.
I’m afraid that I need to keep $ in order to get some formulas:
\cldcontext{(string.gsub([[\xmlraw{#1}{.}]],
'<span class="'..'math inline'..'">', '$'):gsub("</span>",
"\\ifmmode $\\fi"))}}
Actually this is way more complex, but I need to catch % and have to
substitution above.
Many thanks for your help,
Pablo
--
http://www.ousia.tk
___________________________________________________________________________________
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] 8+ messages in thread
* Re: catch % in gsub("%", "\\letterpercent")
2020-08-27 17:16 ` Pablo Rodriguez
@ 2020-08-27 17:35 ` Wolfgang Schuster
2020-08-27 17:49 ` Pablo Rodriguez
0 siblings, 1 reply; 8+ messages in thread
From: Wolfgang Schuster @ 2020-08-27 17:35 UTC (permalink / raw)
To: mailing list for ConTeXt users
Pablo Rodriguez schrieb am 27.08.2020 um 19:16:
> On 8/27/20 6:16 PM, Wolfgang Schuster wrote:
>> Pablo Rodriguez schrieb am 27.08.2020 um 17:56:
>>> [...]
>>> \startxmlsetups xml:special
>>> \startitem
>>> \cldcontext{string.gsub([[\xmlraw{#1}{.}]], "%%",
>>> "\\letterpercent")}
>>> \stopitem
>>> \stopxmlsetups
>> [...]
>> and to escape special characters you can use context.escape()
> Many thanks for your reply, Wolfgang.
>
> I’m afraid that I need to keep $ in order to get some formulas:
>
> \cldcontext{(string.gsub([[\xmlraw{#1}{.}]],
> '<span class="'..'math inline'..'">', '$'):gsub("</span>",
> "\\ifmmode $\\fi"))}}
>
> Actually this is way more complex, but I need to catch % and have to
> substitution above.
You have to replace %% with \letterpercent\letterpercent because you're
still playing with TeX rules.
\startxmlsetups xml:special
\startitem
\cldcontext{string.gsub("\xmlraw{#1}{.}","\letterpercent\letterpercent","\\letterpercent{}")}
\stopitem
\stopxmlsetups
To avoid these limitations create a new Lua function and call only this
function in the setup:
\startluacode
moduledata = moduledata or { }
function moduledata.special(str)
return string.gsub(str,"%%","\\letterpercent{}")
end
\stopluacode
\startxmlsetups xml:special
\startitem
\cldcontext{moduledata.special([[\xmlraw{#1}{.}]])}
\stopitem
\stopxmlsetups
Wolfgang
___________________________________________________________________________________
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] 8+ messages in thread
* Re: catch % in gsub("%", "\\letterpercent")
2020-08-27 17:35 ` Wolfgang Schuster
@ 2020-08-27 17:49 ` Pablo Rodriguez
0 siblings, 0 replies; 8+ messages in thread
From: Pablo Rodriguez @ 2020-08-27 17:49 UTC (permalink / raw)
To: ntg-context
On 8/27/20 7:35 PM, Wolfgang Schuster wrote:
> [...]
> You have to replace %% with \letterpercent\letterpercent because you're
> still playing with TeX rules.
>
> \startxmlsetups xml:special
> \startitem
> \cldcontext{string.gsub("\xmlraw{#1}{.}","\letterpercent\letterpercent","\\letterpercent{}")}
> \stopitem
> \stopxmlsetups
Many thanks for your reply, Wolfgang.
Now I understand what was going on.
> To avoid these limitations create a new Lua function and call only this
> function in the setup:
>
> \startluacode
>
> moduledata = moduledata or { }
>
> function moduledata.special(str)
> return string.gsub(str,"%%","\\letterpercent{}")
> end
>
> \stopluacode
>
> \startxmlsetups xml:special
> \startitem
> \cldcontext{moduledata.special([[\xmlraw{#1}{.}]])}
> \stopitem
> \stopxmlsetups
Now I see that I have a lot to learn.
Many thanks again for your help,
Pablo
--
http://www.ousia.tk
___________________________________________________________________________________
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] 8+ messages in thread
* Re: catch % in gsub("%", "\\letterpercent")
2020-08-27 15:11 catch % in gsub("%", "\\letterpercent") Pablo Rodriguez
2020-08-27 15:30 ` Taco Hoekwater
@ 2020-08-27 15:39 ` Hans van der Meer
1 sibling, 0 replies; 8+ messages in thread
From: Hans van der Meer @ 2020-08-27 15:39 UTC (permalink / raw)
To: NTG ConTeXt
[-- Attachment #1.1: Type: text/plain, Size: 1153 bytes --]
In Lua patterns % is a socalled magic character like ^$ etc. These are esacped with a %. Thus %% is what you need in the first string.
dr. Hans van der Meer
> On 27 Aug 2020, at 17:11, Pablo Rodriguez <oinos@gmx.es> wrote:
>
> Dear list,
>
> I have and \xmlraw command that gives some text with percent signs.
> ConTeXt parses them as comments (so no output).
>
> Using Lua gsub(), I need to replace something like:
>
> string.gsub([[\xmlraw{#1}{.}]], "%", "\\letterpercent")
>
> How do I need to invoke % to get the character found?
>
> Many thanks for your help,
>
> Pablo
> --
> http://www.ousia.tk
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________
[-- Attachment #1.2: Type: text/html, Size: 2754 bytes --]
[-- Attachment #2: Type: text/plain, Size: 493 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] 8+ messages in thread
end of thread, other threads:[~2020-08-27 17:49 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-27 15:11 catch % in gsub("%", "\\letterpercent") Pablo Rodriguez
2020-08-27 15:30 ` Taco Hoekwater
2020-08-27 15:56 ` Pablo Rodriguez
2020-08-27 16:16 ` Wolfgang Schuster
2020-08-27 17:16 ` Pablo Rodriguez
2020-08-27 17:35 ` Wolfgang Schuster
2020-08-27 17:49 ` Pablo Rodriguez
2020-08-27 15:39 ` Hans van der Meer
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).