* [NTG-context] XML processing, unwanted indentation/alignment
@ 2024-02-15 20:28 Michael Guravage
2024-02-15 21:03 ` [NTG-context] " Wolfgang Schuster
2024-02-15 23:34 ` Bruce Horrocks
0 siblings, 2 replies; 4+ messages in thread
From: Michael Guravage @ 2024-02-15 20:28 UTC (permalink / raw)
To: ntg-context
[-- Attachment #1.1: Type: text/plain, Size: 1767 bytes --]
Greetings,
I'm typesetting an address book whose addresses are in XML. A typical entry
has this structure:
<family surname="">
<address street="" housenumber="" postcode="1" city="" telephone="" />
<members>
<member first_name="" initials="" maiden_name="" birthday="" email=""
mobile="" />
<member first_name="" initials="" birthday="" email="" mobile="" />
<member first_name="" initials="" birthday="" />
</members>
</family>
initials and birthday are required, first_name can be left blank and email,
mobile and maiden_name are optional.
I've written a macro (name) to compose the name, i.e. initials, first_name
(maiden_name), and another macro (nameemaillink) to make the name a link
associated with an email address.
% Derive an individual's name
\def\name#1%
{\ifxmlattempty{#1}{first_name} {\xmlatt{#1}{initials}} \else
{\xmlatt{#1}{initials}, \xmlatt{#1}{first_name}} \fi
\ifxmlattempty{#1}{maiden_name} {} \else {
\tfxx(\xmlatt{#1}{maiden_name})} \fi}
% Create a mailto:link that associates a individual's name with their email
address.
\def\nameemaillink#1%
{\ifxmlattempty{#1}{email} {\name{#1}} \else {\goto{\name{#1}}
[url(mailto:\xmlatt{#1}{email})]} \fi}
I thought I was done when I noticed that a composed name with an empty
first name, with or without an email address, is slightly indented. In the
mwe Moe and Curly, without first names, are indented; while Shemp and
Michael aren't.
That the undesired indentation/alignment is dependent on the presence of a
first name is baffling. After this long description, if someone would look
at the code and tell me where I've gone wrong I would be very grateful. The
interesting bits begin on lines 8 and 12 in xml.tex.
--
With kind regards,
Michael
[-- Attachment #1.2: Type: text/html, Size: 2668 bytes --]
[-- Attachment #2: xml.tex --]
[-- Type: text/x-tex, Size: 2069 bytes --]
% XML processing instructions
% Turn a phone number into a tel:link - without spaces
\def\phonelink#1%
{\goto{#1} [url(tel:\cldcontext{string.nospaces("#1")})]}
% Derive an individual's name
\def\name#1%
{\ifxmlattempty{#1}{first_name} {\xmlatt{#1}{initials}} \else {\xmlatt{#1}{initials}, \xmlatt{#1}{first_name}} \fi
\ifxmlattempty{#1}{maiden_name} {} \else { \tfxx(\xmlatt{#1}{maiden_name})} \fi}
% Create a mailto:link that associates a individual's name with their email address.
\def\nameemaillink#1%
{\ifxmlattempty{#1}{email} {\name{#1}} \else {\goto{\name{#1}} [url(mailto:\xmlatt{#1}{email})]} \fi}
% Make an individual's mobile phone number a tel:link.
\def\mobilelink#1%
{\ifxmlattempty{#1}{mobile} {} \else {\phonelink{\xmlatt{#1}{mobile}}} \fi}
% Track these several elements.
\startxmlsetups xml:list:base
\xmlsetsetup{#1}{addressBook|family|address|members|member}{xml:list:*}
\stopxmlsetups
\xmlregisterdocumentsetup{list}{xml:list:base}
% When we encounter the root <addressBook> element merely flush the rest.
\startxmlsetups xml:list:addressBook
\xmlflush{#1}
\stopxmlsetups
% Place each family in a frametext box
\startxmlsetups xml:list:family
\startframedtext[width=\textwidth]
{\tfb \bf \xmlatt{#1}{surname}\ifxmlattempty{#1}{prefix}{}\else{, \xmlatt{#1}{prefix}}\fi}\blank
\xmlflush{#1}
\stopframedtext
\blank[big]
\stopxmlsetups
% Enumerate the address information
\startxmlsetups xml:list:address
\xmlatt{#1}{street} \xmlatt{#1}{housenumber}\crlf
\xmlatt{#1}{postcode} \xmlatt{#1}{city}\crlf
\ifxmlattempty{#1}{telephone}{\vskip -1em}\else{\phonelink{\xmlatt{#1}{telephone}}}\fi
%\vskip -1em
\xmlflush{#1}
\blank[big]
\stopxmlsetups
% The only purpose of the <members> element is to make a table of members.
\startxmlsetups xml:list:members
\starttabulate[|l|l|l|]
\xmlflush{#1}
\stoptabulate
\stopxmlsetups
% Each <member> gets his own table row.
\startxmlsetups xml:list:member
\NC \nameemaillink{#1} \NC \xmlatt{#1}{birthday} \NC \mobilelink{#1} \NC\NR
\stopxmlsetups
% finis
[-- Attachment #3: mwe.tex --]
[-- Type: text/x-tex, Size: 250 bytes --]
\environment xml.tex % XML processing instructions
\setupframedtext[frame=off, width=\textwidth, align={flushleft,broad,nothyphenated}]
\setupinteraction[state=start, color=darkblue]
\starttext
\xmlprocessfile{list}{mwe.xml}{}
\stoptext
% finis
[-- Attachment #4: mwe.xml --]
[-- Type: text/xml, Size: 777 bytes --]
<?xml version="1.0" encoding="utf-8"?>
<addressBook>
<family surname="Horwitz"> <!-- The Three Stooges -->
<address street="Dorpstraat" housenumber="42" postcode="1234 AB" city="Hilversum" telephone="0123 456789" />
<members>
<member first_name="Samuel" initials="S." birthday="17.03.1895" email="shemp@@stooges.com" mobile="0123456789" /> <!-- Shemp -->
<member first_name="" initials="M." birthday="19.06.1897" email="moe@stooges.com" mobile="0123456789"/> <!-- Moe -->
<member first_name="" initials="J." birthday="22.10.1903" mobile="0123456789" /> <!-- Curly -->
<member first_name="Michael" initials="M." birthday="09.03.1939" mobile="0123456789" /> <!-- Michael -->
</members>
</family>
</addressBook>
<!-- finis -->
[-- Attachment #5: mwe.pdf --]
[-- Type: application/pdf, Size: 13551 bytes --]
[-- Attachment #6: Type: text/plain, Size: 511 bytes --]
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 4+ messages in thread
* [NTG-context] Re: XML processing, unwanted indentation/alignment
2024-02-15 20:28 [NTG-context] XML processing, unwanted indentation/alignment Michael Guravage
@ 2024-02-15 21:03 ` Wolfgang Schuster
2024-02-15 23:34 ` Bruce Horrocks
1 sibling, 0 replies; 4+ messages in thread
From: Wolfgang Schuster @ 2024-02-15 21:03 UTC (permalink / raw)
To: mailing list for ConTeXt users, Michael Guravage
Michael Guravage schrieb am 15.02.2024 um 21:28:
> Greetings,
>
> I'm typesetting an address book whose addresses are in XML. A typical
> entry has this structure:
>
> <family surname="">
> <address street="" housenumber="" postcode="1" city="" telephone="" />
> <members>
> <member first_name="" initials="" maiden_name="" birthday=""
> email="" mobile="" />
> <member first_name="" initials="" birthday="" email="" mobile="" />
> <member first_name="" initials="" birthday="" />
> </members>
> </family>
>
> initials and birthday are required, first_name can be left blank and
> email, mobile and maiden_name are optional.
>
> I've written a macro (name) to compose the name, i.e. initials,
> first_name (maiden_name), and another macro (nameemaillink) to make the
> name a link associated with an email address.
>
> % Derive an individual's name
> \def\name#1%
> {\ifxmlattempty{#1}{first_name} {\xmlatt{#1}{initials}} \else
> {\xmlatt{#1}{initials}, \xmlatt{#1}{first_name}} \fi
> \ifxmlattempty{#1}{maiden_name} {} \else {
> \tfxx(\xmlatt{#1}{maiden_name})} \fi}
You have a few spaces in the definition of your command (e.g. the space
after \else and another one after the following { in the main_name
attribute) which end as multiple spaces in the output.
While you can fix the problem by removing the spaces a better solution
is to use the texdefinition environment to create your command, you can
even use blank lines to structure the arguments.
To avoid problems with existing commands it is good practice to use
camelcase for your own commands.
%%%% begin example
\starttexdefinition Name #1
\ifxmlattempty{#1}{first_name}
\xmlatt{#1}{initials}
\else
\xmlatt{#1}{initials}, \xmlatt{#1}{first_name}
\fi
\ifxmlattempty{#1}{maiden_name}
%
\else
{\tfxx(\xmlatt{#1}{maiden_name})}
\fi
\stoptexdefinition
%%%% end example
Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 4+ messages in thread
* [NTG-context] Re: XML processing, unwanted indentation/alignment
2024-02-15 20:28 [NTG-context] XML processing, unwanted indentation/alignment Michael Guravage
2024-02-15 21:03 ` [NTG-context] " Wolfgang Schuster
@ 2024-02-15 23:34 ` Bruce Horrocks
2024-02-16 8:32 ` Taco Hoekwater
1 sibling, 1 reply; 4+ messages in thread
From: Bruce Horrocks @ 2024-02-15 23:34 UTC (permalink / raw)
To: ntg-context mailing list
The extra space is because you have a space between {first_name} and {\xmlatt... on line 9 of xml.tex.
> On 15 Feb 2024, at 20:28, Michael Guravage <guravage@literatesolutions.com> wrote:
>
> Greetings,
>
> I'm typesetting an address book whose addresses are in XML. A typical entry has this structure:
>
> <family surname="">
> <address street="" housenumber="" postcode="1" city="" telephone="" />
> <members>
> <member first_name="" initials="" maiden_name="" birthday="" email="" mobile="" />
> <member first_name="" initials="" birthday="" email="" mobile="" />
> <member first_name="" initials="" birthday="" />
> </members>
> </family>
>
> initials and birthday are required, first_name can be left blank and email, mobile and maiden_name are optional.
>
> I've written a macro (name) to compose the name, i.e. initials, first_name (maiden_name), and another macro (nameemaillink) to make the name a link associated with an email address.
>
> % Derive an individual's name
> \def\name#1%
> {\ifxmlattempty{#1}{first_name} {\xmlatt{#1}{initials}} \else {\xmlatt{#1}{initials}, \xmlatt{#1}{first_name}} \fi
%%%% Remove the space after {first_name} here
> \ifxmlattempty{#1}{maiden_name} {} \else { \tfxx(\xmlatt{#1}{maiden_name})} \fi}
>
> % Create a mailto:link that associates a individual's name with their email address.
> \def\nameemaillink#1%
> {\ifxmlattempty{#1}{email} {\name{#1}} \else {\goto{\name{#1}} [url(mailto:\xmlatt{#1}{email})]} \fi}
>
> I thought I was done when I noticed that a composed name with an empty first name, with or without an email address, is slightly indented. In the mwe Moe and Curly, without first names, are indented; while Shemp and Michael aren't.
>
> That the undesired indentation/alignment is dependent on the presence of a first name is baffling. After this long description, if someone would look at the code and tell me where I've gone wrong I would be very grateful. The interesting bits begin on lines 8 and 12 in xml.tex.
—
Bruce Horrocks
Hampshire, UK
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 4+ messages in thread
* [NTG-context] Re: XML processing, unwanted indentation/alignment
2024-02-15 23:34 ` Bruce Horrocks
@ 2024-02-16 8:32 ` Taco Hoekwater
0 siblings, 0 replies; 4+ messages in thread
From: Taco Hoekwater @ 2024-02-16 8:32 UTC (permalink / raw)
To: mailing list for ConTeXt users
> On 16 Feb 2024, at 00:34, Bruce Horrocks <ntg@scorecrow.com> wrote:
>
> The extra space is because you have a space between {first_name} and {\xmlatt... on line 9 of xml.tex.
>
>> On 15 Feb 2024, at 20:28, Michael Guravage <guravage@literatesolutions.com> wrote:
>>
>> Greetings,
>>
>> I'm typesetting an address book whose addresses are in XML. A typical entry has this structure:
>>
>> <family surname="">
>> <address street="" housenumber="" postcode="1" city="" telephone="" />
>> <members>
>> <member first_name="" initials="" maiden_name="" birthday="" email="" mobile="" />
>> <member first_name="" initials="" birthday="" email="" mobile="" />
>> <member first_name="" initials="" birthday="" />
>> </members>
>> </family>
>>
>> initials and birthday are required, first_name can be left blank and email, mobile and maiden_name are optional.
>>
>> I've written a macro (name) to compose the name, i.e. initials, first_name (maiden_name), and another macro (nameemaillink) to make the name a link associated with an email address.
>>
>> % Derive an individual's name
>> \def\name#1%
>> {\ifxmlattempty{#1}{first_name} {\xmlatt{#1}{initials}} \else {\xmlatt{#1}{initials}, \xmlatt{#1}{first_name}} \fi
> %%%% Remove the space after {first_name} here
>> \ifxmlattempty{#1}{maiden_name} {} \else { \tfxx(\xmlatt{#1}{maiden_name})} \fi}
I am fairly certain the “ {} “ before the \else introduces spaces.
>>
>> % Create a mailto:link that associates a individual's name with their email address.
>> \def\nameemaillink#1%
>> {\ifxmlattempty{#1}{email} {\name{#1}} \else {\goto{\name{#1}} [url(mailto:\xmlatt{#1}{email})]} \fi}
>>
>> I thought I was done when I noticed that a composed name with an empty first name, with or without an email address, is slightly indented. In the mwe Moe and Curly, without first names, are indented; while Shemp and Michael aren't.
>>
>> That the undesired indentation/alignment is dependent on the presence of a first name is baffling. After this long description, if someone would look at the code and tell me where I've gone wrong I would be very grateful. The interesting bits begin on lines 8 and 12 in xml.tex.
>
> —
> Bruce Horrocks
> Hampshire, UK
>
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
>
> maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
> webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
> archive : https://github.com/contextgarden/context
> wiki : https://wiki.contextgarden.net
> ___________________________________________________________________________________
—
Taco Hoekwater E: taco@bittext.nl
genderfluid (all pronouns)
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-02-16 8:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-15 20:28 [NTG-context] XML processing, unwanted indentation/alignment Michael Guravage
2024-02-15 21:03 ` [NTG-context] " Wolfgang Schuster
2024-02-15 23:34 ` Bruce Horrocks
2024-02-16 8:32 ` Taco Hoekwater
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).