Hi, I was a little surprised to see that the spaces for most monospace fonts are not respected when using \xmlflushspacewise (see code below): https://i.ibb.co/C5LPVKsH/monospace-table.png Using \xmlverbatim displays as expected. For my actual document, I cannot use \xmlprettyprint because it generates an error. Is \xmlflushspacewise supposed to honour the glyph metrics of the space character for monospace fonts? mtx-context | current version: 2025.08.21 23:32 % ---- 8< ---- \startbuffer[test] <?xml version="1.0"?> <document><pre> |aaa|bbb|ccc| |---|---|---| | 1 | 2 | 3 | | 4 | 5 | 6 | | 7 | 8 | 9 | </pre></document> \stopbuffer \startxmlsetups xml:setup \xmlsetsetup{\xmldocument}{*}{-} \xmlsetsetup{\xmldocument}{document|pre}{xml:*} \stopxmlsetups \xmlregistersetup{xml:setup} \startxmlsetups xml:document \startdocument \xmlflush{#1} \stopdocument \stopxmlsetups \define[2]\Verbatim{ \startxmldisplayverbatim \setupbodyfont[#1] \xmlflushspacewise{#2} \stopxmldisplayverbatim } \startxmlsetups xml:pre \Verbatim{TextFontIN}{#1} \Verbatim{TextFontRM}{#1} \Verbatim{TextFontSP}{#1} \Verbatim{TextFontFC}{#1} \Verbatim{TextFontLM}{#1} \stopxmlsetups \definefontfamily [TextFontSP] [tt] [Source Code Pro] \definefontfamily [TextFontRM] [tt] [Roboto Mono] \definefontfamily [TextFontIN] [tt] [Inconsolata] \definefontfamily [TextFontFC] [tt] [Fira Code] \definefontfamily [TextFontLM] [tt] [Luxi Mono] \usetypescript[TextFont] \xmlprocessbuffer{main}{test}{} % ---- 8< ---- Aside, should this code be returning an error? mtx-context | fatal error: return code: 1 Thank you!
On 8/30/25 00:23, Thangalin wrote:
[...] Using \xmlverbatim displays as expected. For my actual document, I cannot use \xmlprettyprint because it generates an error.
Hi, Maybe `mtxrun --script check your-source.tex` might help to find the cause.
[...] Aside, should this code be returning an error?
mtx-context | fatal error: return code: 1
Yes, add \starttext...\stoptext, such as in: \starttext \xmlprocessbuffer{main}{test}{} \stoptext I hope it helps, Pablo
On 8/30/2025 12:23 AM, Thangalin wrote:
\startbuffer[test] <?xml version="1.0"?> <document><pre> |aaa|bbb|ccc| |---|---|---| | 1 | 2 | 3 | | 4 | 5 | 6 | | 7 | 8 | 9 | </pre></document> \stopbuffer
\startxmlsetups xml:setup \xmlsetsetup{\xmldocument}{*}{-} \xmlsetsetup{\xmldocument}{document|pre}{xml:*} \stopxmlsetups
\xmlregistersetup{xml:setup}
\startxmlsetups xml:document \startdocument \xmlflush{#1} \stopdocument \stopxmlsetups
\define[2]\Verbatim{ \startxmldisplayverbatim \setupbodyfont[#1] \xmlflushspacewise{#2} \stopxmldisplayverbatim }
\startxmlsetups xml:pre \Verbatim{TextFontIN}{#1} \Verbatim{TextFontRM}{#1} \Verbatim{TextFontSP}{#1} \Verbatim{TextFontFC}{#1} \Verbatim{TextFontLM}{#1} \stopxmlsetups
\definefontfamily [TextFontSP] [tt] [Source Code Pro] \definefontfamily [TextFontRM] [tt] [Roboto Mono] \definefontfamily [TextFontIN] [tt] [Inconsolata] \definefontfamily [TextFontFC] [tt] [Fira Code] \definefontfamily [TextFontLM] [tt] [Luxi Mono]
\usetypescript[TextFont]
\xmlprocessbuffer{main}{test}{}
You can try with: \define[2]\Verbatim{ \start \showglyphs \startxmldisplayverbatim \obeyspaces \xmlflushspacewise{#2} \stopxmldisplayverbatim \stop } \definefont[TestFont][inconsolata-regular.ttf] until Wolfgang gives you the perfect answer wrt \definefontfamily. Maybe we need some extra 'space/glue hack'. Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
Am 30.08.2025 um 13:09 schrieb Hans Hagen via ntg-context:
On 8/30/2025 12:23 AM, Thangalin wrote:
\startbuffer[test] <?xml version="1.0"?> <document><pre> |aaa|bbb|ccc| |---|---|---| | 1 | 2 | 3 | | 4 | 5 | 6 | | 7 | 8 | 9 | </pre></document> \stopbuffer
\startxmlsetups xml:setup \xmlsetsetup{\xmldocument}{*}{-} \xmlsetsetup{\xmldocument}{document|pre}{xml:*} \stopxmlsetups
\xmlregistersetup{xml:setup}
\startxmlsetups xml:document \startdocument \xmlflush{#1} \stopdocument \stopxmlsetups
\define[2]\Verbatim{ \startxmldisplayverbatim \setupbodyfont[#1] \xmlflushspacewise{#2} \stopxmldisplayverbatim }
\startxmlsetups xml:pre \Verbatim{TextFontIN}{#1} \Verbatim{TextFontRM}{#1} \Verbatim{TextFontSP}{#1} \Verbatim{TextFontFC}{#1} \Verbatim{TextFontLM}{#1} \stopxmlsetups
\definefontfamily [TextFontSP] [tt] [Source Code Pro] \definefontfamily [TextFontRM] [tt] [Roboto Mono] \definefontfamily [TextFontIN] [tt] [Inconsolata] \definefontfamily [TextFontFC] [tt] [Fira Code] \definefontfamily [TextFontLM] [tt] [Luxi Mono]
\usetypescript[TextFont]
\xmlprocessbuffer{main}{test}{}
You can try with:
\define[2]\Verbatim{ \start \showglyphs \startxmldisplayverbatim \obeyspaces \xmlflushspacewise{#2} \stopxmldisplayverbatim \stop }
\definefont[TestFont][inconsolata-regular.ttf]
until Wolfgang gives you the perfect answer wrt \definefontfamily.
I would [features=none] for the monospaced fonts but this is not the reason for the wrong alignment.
Maybe we need some extra 'space/glue hack'.
The rows with spaces before/after the number have a different alignment because *after* a normal space is inserted (the space *before* the number is a active space where \obeyedspace is applied) and the verbatim code changes the \spaceskip value to .5\emwidth. % file: buff-ver.mkxl \def\buff_verbatim_initialize_typing_two {\spaceskip.5\emwidth\relax ...} When you reset the \spaceskip value the alignment is correct. \starttexdefinition Verbatim #1#2 \switchtobodyfont[#1] \startxmldisplayverbatim \spaceskip\zeropoint \xmlflushspacewise{#2} \stopxmldisplayverbatim \stoptexdefinition Wolfgang
The table now aligns perfectly in a non-Inconsolata font, Wolfgang, thank you. When you reset the \spaceskip value the alignment is correct.
\starttexdefinition Verbatim #1#2 \switchtobodyfont[#1] \startxmldisplayverbatim \spaceskip\zeropoint \xmlflushspacewise{#2} \stopxmldisplayverbatim \stoptexdefinition
Wolfgang
participants (4)
-
Hans Hagen -
Pablo Rodriguez -
Thangalin -
Wolfgang Schuster