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