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
___________________________________________________________________________________

Reply via email to