[NTG-context] XML, dealing with whitespace

Wolfgang Schuster wolfgang.schuster.lists at gmail.com
Sat Jan 15 20:28:00 CET 2022


Denis Maier via ntg-context schrieb am 15.01.2022 um 13:04:
>
> Hi all,
>
> I have sources that look like this:
>
> %%%%%%%%%%%%%%%%%%%%%
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <article>
>
>    <p>Bla Bla Bla</p>
>
> <p>
>
>       <underline>
>
>          <italic>Bla</italic>
>
>       </underline>, Bla Bla.</p>
>
> </article>
>
> %%%%%%%%%%%%%%%%%%%%%
>
> Typesetting this with context gives me a spurious space after the 
> underlined Bla in italics.
>

There is no spurious space, the line break is just converted to a space 
and I see no reason why this shouldn't happen. To remove space before or 
after certain parts of text within a paragraph you can use the 
\removeunwantedspace and \ignorespaces commands.

%%%% begin example
\starttexdefinition RemovePreceding #1
     \removeunwantedspaces
     #1
\stoptexdefinition

\starttexdefinition RemoveFollowing #1
     #1
     \ignorespaces
\stoptexdefinition

\starttext

Bla \RemovePreceding{Bla} Bla

Bla \RemoveFollowing{Bla} Bla

\stoptext
%%%% end example

When only  following spaces are a problem a better alternative to 
\ignorespace is \autoinsertnextspace which checks the following token 
which ensures there is space when the next character is punctuation.

%%%% begin example
\starttexdefinition Italic #1
     \emphasized{#1}
     \autoinsertnextspace
\stoptexdefinition

\starttexdefinition Underbar #1
     \underbar{#1}
\stoptexdefinition

\starttext

Bla Bla Bla

\Underbar{\Italic{Bla} , Bla Bla.}

\stoptext
%%%% end example

Wolfgang

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20220115/36410624/attachment.htm>


More information about the ntg-context mailing list