How could I write something like the following converter using only the Lua interface?

      <p>Some stuff</p>
      <p>More stuff, with <em>emphasis</em></p>

\startxmlsetups xml:test:*


\startxmlsetups xml:test:html

\startxmlsetups xml:test:body

\startxmlsetups xml:test:p

\startxmlsetups xml:test:em


I can get the other stuff working with context.whatever or lxml.whatever; the one thing that is holding me back is the (start/stop)xmlsetups command, so I cannot replace, for example,

\startxmlsetups xml:test:html



I have tried context.startxmlsetups(xml:test:html), context.delayed.startxmlsetups(xml:test:html), context.nested.startxmlsetups(xml:test:html), function() context.startxmlsetups(xml:test:html) end, and function() context.startxmlsetups(xml:test:html) return true end; they all seem to either do nothing or give errors about \csname. The macro definition seems to be in core-env.mkiv, but I cannot make sense of it. Is there a way to call these start/stopxmlsetups commands from Lua, or to avoid them entirely?

Edit (7/9/18):

I have tried using #1 and '#1' as arguments to a Lua function outside of the xmlsetups environment, but they do not seem to mean anything useful there. This works:

\startxmlsetups xml:test:html

But not \ctxlua{lxml.flush('#1')} on its own, or \ctxlua{lxml.flush(#1)}, or \ctxlua{lxml.flush('xml:test:html')}. Even \ctxlua{lxml.flush('testxml::2')} fails to do anything. (testxml::2 is the result of calling print('#1') inside that particular xmlsetups environment. Interestingly, outside of that, print('#1') gives ##1; I do not know if it has any significance, but the standard Lua interpreter does not behave that way.)

I also tried the following:


  function xml.functions.test()


Which resulted in:

Missing \endcsname inserted

<to be read again>
\syst_setups_start_xml_indeed ...me \??setup #1:#2
                                              \expandafter \endcsname \e...

When I added \endcsname before \stopxmlsetups in the macro definition, I got Parameters must be named consecutively.

  • 1
    Please add a complete example so any would-be-helper can easily check out your problem. – vonbrand Jul 6 '18 at 16:11
  • Can you just call a lua function with #1 as an argument? – Aditya Jul 6 '18 at 23:45
  • 2
    @vonbrand This is a MWE even though it might not look like it because it's ConTeXt, not LaTeX. – Henri Menke Jul 7 '18 at 0:15
  • @Aditya See the edit. – Keiser Jul 9 '18 at 20:51
  • @Keiser Put the name of the setups environment in brackets, e.g. \startxmlsetups [xml:...] ... \stopxmlsetups. – Wolfgang Schuster Jul 14 '18 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.