On 6/5/24 12:00, Christoph Edenhauser wrote:
[...] I realise that it is somehow difficult for me to describe what I would like to achieve, perhaps what I have in mind is not even possible.
Hi Christoph, as far as I know (and as Hraban has already mentioned), this is not possible. Either XSLT or pandoc would be a way to do that. That being said, I would avoid conversion (a second source) in all cases. I use ConTeXt to typeset XML sources typing Markdown sources. pandoc generates XML and then ConTeXt typesets these XML sources.
My Question is, is it possible to generate a second context file2.tex with the help of this first xml-mapping file1.tex, where all the xml-nodes from the xml file are mapped to contex commands which then looks something like this:
I‘m afraid this is not possible (it works in a different way)
I would then like to edit the Text in such a more "TeXish" result manually, e.g. insert small spaces as in ‘St.\,Martin’, explain unknown words in \footnote{comment}, etc.
Different spaces are Unicode characters. As entities, &nnbsp; or (narrow no-breaking space and thin space, respectively).
I know you could or even should do the text corrections in the xml file, but XML would overwhelm my proofreader. (He has learnt to leave LaTeX code untouched, that should then work with ConTeXt code as well). So for me, the main reason for having a TeX-ish file2.tex is, that the Text could be corrected directly from the proofreader in this file2.tex file, but won't do that in the xml file.
I don’t mean the proofreader personally, but TeX code may not be inherenlty more readable that XML code. Compile the following: \starttext \startXML <?xml version="1.0"?> <chapter class="foo">St.&nnbsp;Martin</chapter> <paragraph id="first-par">A comprehensive treatise</paragraph> <section other="anoter">The medieval part of the church</section> \stopXML \startTEX \starttext \startchapter[title=St.\, Martin] \stopchapter \startsection[title=The medieval part of the church]\stopsection \stoptext \stopTEX \stoptext I think that a text editor with reasonable highlighting for XML is key to your issue. I mean, XML sources tend to be highlighted leaving pure text as uncolored and unformatted (no bold or italics). In that case, I think the text to be proofread may be recognized as not having any format at all (besides not enclosed inside "<" and ">").
And now a second approach to my question: Are all these \startxmlsetups like '\startxmlsetup xml:chapter' internally mapped to standard context commands like \startchapter ... \stopchapter before they are converted to pdf?
No, these are formatting commands after the mapping. In short, there are three steps involved in XML typesetting. First, you select which elements you would like to select from the XML source in an XML setup (with a mapping to your configuration commands). Second, you register this XML setup. Third, your configure the selected elements with ConTeXt commands. Here is a sample (using a buffer instead of an external file): \startbuffer[demo] <foo> <bar>line 1</bar> <bar>line 2</bar> <bar>line 3</bar> </foo> \stopbuffer \starttext \startxmlsetups abc:def \xmlsetsetup{#1}{foo|bar}{xyz:*} \stopxmlsetups \xmlregistersetup{abc:def} \startxmlsetups xyz:foo \xmlflush{#1} \stopxmlsetups \startxmlsetups xyz:bar \startparagraph \xmlflush{#1} \stopparagraph \stopxmlsetups \xmlprocessbuffer{main}{demo}{} \stoptext First of all, XML has no hardcoded names for any element (from a certain point of view, XML are only rules on how to use the "<>" tags). This is why, <foo> and <bar> are perfectly valid element names (although they have no meaning for people). Second, the mapping may use any name for destination setups. \xmlsetsetup does the mappings, the second group of parentheses contains the lpath (an Lua version of XPath [how XML is selected]) and the third group of parentheses is setups. The command \xmlsetsetup{#1}{foo|bar}{xyz:*} above is bound to existing elements (or paths) in the XML source, but both "xyz:foo" and "xzy:bar" may read as the user wants. Third, after that you need specify the setup for each mapping (or it won’t appear in your final document). The setup is what you defined as the second part of the mapping, may it be "xml:title" or "xyz:bar". Nothing here is hardcoded. XML is not HTML (elements with meaning). In order to deal with XML, ConTeXt has to provide the tools to select elements (and more complex constructs) and map them to configurable setups. How both tools (construct selection and setup configurations) may be deployed, this is up to each individual. Hardcoding this would be a real problem in the short run.
If this is the case, can this intermediate context representation be exported, and how would this be done?
Nice try, but I’m afraid this is not how it works. I hope my explanation may be minimally clear to understand why your approach is different from what ConTeXt offers. Feel free to ask, if my explanation wasn’t clear enough. I hope it helps, Pablo PS: if now the fancy thing may be about digital competences, the ability to read XML sources is way more useful than being able to read TeX 😅.