Re: [NTG-context] How to do code listings & sections from XML (AsciiDoc)
On Fri, 12 Aug 2022 at 23:20, Aditya Mahajan wrote: > On Fri, 12 Aug 2022, Mojca Miklavec via ntg-context wrote: > > > (a) I don't know how to turn program listing (verbatim code) from xml > > to (perhaps, vim-based) syntax highlighting (but most importantly, to > > make sure that line breaks work properly) > > Does something like this work: > > https://wiki.contextgarden.net/Verbatim_XML Yes, awesome, this does exactly what I want, thank you very much. I used the following code: \usemodule[vim] % this breaks if directory doesn't exist before \setupvimtyping[directory=output/] % it would be potentially useful to have some predefined vimtyping already present in the module \definevimtyping [programlisting] [syntax=] \startluacode function xml.functions.processprogramlisting(t) buffers.assign("listing","\\startprogramlisting[syntax=cpp]\n" .. tostring(xml.text(t)) .. "\n\\stopprogramlisting") context.getbuffer { "listing" } end \stopluacode \startxmlsetups xml:programlisting \pushcatcodetable \setcatcodetable\ctxcatcodes \xmlfunction{#1}{processprogramlisting} \popcatcodetable \stopxmlsetups Now I need to get the "cpp" and "unnumbered" part processed automatically, so that it will work for any language: // test.cpp: int main() { return 0; } which would then be transformed into \startprogramlisting[syntax=cpp,numbering=no] int main() { return 0; } \stopprogramlisting For some reason the syntax highlighting doesn't work on the full document, but it works inside the minimal example, so I still need to investigate what's going on with the full document. On an unrelated note: I cannot make \startnarrow[middle=1cm] (or left=... for that matter) produce any offset on the left. I was playing with the following code, but the frame refuses to be shifted to the right \setupvimtyping [before={ \startnarrow[left=1cm,before={\blank[10pt]}] \switchtobodyfont[8pt] \startframed [align=flushleft, background=color, backgroundcolor=gray, frame=off, leftframe=on, rulethickness=2pt, framecolor=darkgray, width=local, offset=1ex]}, after={\stopframed\stopnarrow}] Hello \startprogramlisting[syntax=cpp,numbering=yes] int main() { return 0; } \stopprogramlisting Mojca ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___
Re: [NTG-context] How to do code listings & sections from XML (AsciiDoc)
On Fri, 12 Aug 2022 at 23:20, Aditya Mahajan wrote: > On Fri, 12 Aug 2022, Mojca Miklavec via ntg-context wrote: > > > Hi, > > > > Hans helped me out with some asciidoc processing a while ago. > > > > I played a bit further, but I'm currently facing two minor issues: > > > > (a) I don't know how to turn program listing (verbatim code) from xml > > to (perhaps, vim-based) syntax highlighting (but most importantly, to > > make sure that line breaks work properly) > > Does something like this work: > > https://wiki.contextgarden.net/Verbatim_XML Yes, awesome, this does exactly what I want, thank you very much. I used the following code: \usemodule[vim] % this breaks if directory doesn't exist before \setupvimtyping[directory=output/] % it would be potentially useful to have some predefined vimtyping already present in the module \definevimtyping [programlisting] [syntax=] \startluacode function xml.functions.processprogramlisting(t) buffers.assign("listing","\\startprogramlisting[syntax=cpp]\n" .. tostring(xml.text(t)) .. "\n\\stopprogramlisting") context.getbuffer { "listing" } end \stopluacode \startxmlsetups xml:programlisting \pushcatcodetable \setcatcodetable\ctxcatcodes \xmlfunction{#1}{processprogramlisting} \popcatcodetable \stopxmlsetups Now I need to get the "cpp" and "unnumbered" part processed automatically, so that it will work for any language: // test.cpp: int main() { return 0; } which would then be transformed into \startprogramlisting[syntax=cpp,numbering=no] int main() { return 0; } \stopprogramlisting For some reason the syntax highlighting doesn't work on the full document, but it works inside the minimal example, so I still need to investigate what's going on with the full document. On an unrelated note: I cannot make \startnarrow[middle=1cm] (or left=... for that matter) produce any offset on the left. I was playing with the following example, but the frame refuses to be shifted to the right \setupvimtyping [before={ \startnarrow[left=1cm,before={\blank[10pt]}] \switchtobodyfont[8pt] \startframed [align=flushleft, background=color, backgroundcolor=gray, frame=off, leftframe=on, rulethickness=2pt, framecolor=darkgray, width=local, offset=1ex]}, after={\stopframed\stopnarrow}] Hello \startprogramlisting[syntax=cpp,numbering=yes] int main() { return 0; } \stopprogramlisting Mojca ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___
Re: [NTG-context] How to do code listings & sections from XML (AsciiDoc)
> Hi, > > Hans helped me out with some asciidoc processing a while ago. > > I played a bit further, but I'm currently facing two minor issues: > > (a) I don't know how to turn program listing (verbatim code) from xml > to (perhaps, vim-based) syntax highlighting (but most importantly, to > make sure that line breaks work properly) > Ad (a). The source that looks similar to this: > > > int main() > { > return 0; > } > > > should be converted into some kind of equivalent of > > % on top > \usemodule[vim] > \definevimtyping [CPP] [syntax=cpp] > > \startCPP > int main() > { > return 0; > } > \stopCPP > Any hints would be greatly appreciated. This should get you pretty close: https://tex.stackexchange.com/a/652116/ You can look through the revision history for a few different versions if the newest one doesn't quite work. -- Max ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___
Re: [NTG-context] How to do code listings & sections from XML (AsciiDoc)
On Fri, 12 Aug 2022, Mojca Miklavec via ntg-context wrote: > Hi, > > Hans helped me out with some asciidoc processing a while ago. > > I played a bit further, but I'm currently facing two minor issues: > > (a) I don't know how to turn program listing (verbatim code) from xml > to (perhaps, vim-based) syntax highlighting (but most importantly, to > make sure that line breaks work properly) Does something like this work: https://wiki.contextgarden.net/Verbatim_XML Aditya ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___
[NTG-context] How to do code listings & sections from XML (AsciiDoc)
Hi, Hans helped me out with some asciidoc processing a while ago. I played a bit further, but I'm currently facing two minor issues: (a) I don't know how to turn program listing (verbatim code) from xml to (perhaps, vim-based) syntax highlighting (but most importantly, to make sure that line breaks work properly) (b) some section titles are missing Ad (a). The source that looks similar to this: int main() { return 0; } should be converted into some kind of equivalent of % on top \usemodule[vim] \definevimtyping [CPP] [syntax=cpp] \startCPP int main() { return 0; } \stopCPP In the attachment I have the source document (test.adoc), the generated docbook xml that should be further processed, and test.tex that one processes to get the final pdf. Any hints would be greatly appreciated. Mojca test.tex Description: Binary data test.adoc Description: Binary data http://docbook.org/ns/docbook; xmlns:xl="http://www.w3.org/1999/xlink; version="5.0" xml:lang="en"> Document title (completely missing) 2022-08-12 This title seems to be missing Hello code How it works // test.cpp: halfword tex_copy_node(halfword p) { /*tex We really need a stub for copying because mem might move in the meantime due to resizing! */ if (p 0 || p = lmt_node_memory_state.nodes_data.allocated) { return tex_formatted_error("nodes", "attempt to copy an impossible node %d", (int) p); } else if (p lmt_node_memory_state.reserved lmt_node_memory_state.nodesizes[p] == 0) { return tex_formatted_error("nodes", "attempt to copy a free %s node %d", get_node_name(node_type(p)), (int) p); } else { /*tex type of node */ halfword t = node_type(p); int i = get_node_size(t); /*tex current node being fabricated for new list */ halfword r = tex_get_node(i); /*tex this saves work */ memcpy((void *) (lmt_node_memory_state.nodes + r), (void *) (lmt_node_memory_state.nodes + p), (sizeof(memoryword) * (unsigned) i)); if (tex_nodetype_is_complex(i)) { // halfword copy_stub; if (tex_nodetype_has_attributes(t)) { add_attribute_reference(node_attr(p)); node_prev(r) = null; lmt_properties_copy(lmt_lua_state.lua_instance, r, p); } node_next(r) = null; switch (t) { case glue_node: copy_sub_list(glue_leader_ptr(r), glue_leader_ptr(p)); break; m-asciidoc-manual.tex Description: Binary data ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___