[NTG-context] Re: XML processing, unwanted indentation/alignment

2024-02-16 Thread Taco Hoekwater


> On 16 Feb 2024, at 00:34, Bruce Horrocks  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  
>> wrote:
>> 
>> Greetings,
>> 
>> I'm typesetting an address book whose addresses are in XML. A typical entry 
>> has this structure:
>> 
>>  
>>
>>
>>  > mobile="" /> 
>>   
>>  
>>
>>  
>> 
>> 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: t...@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
___


[NTG-context] Re: XML processing, unwanted indentation/alignment

2024-02-15 Thread Bruce Horrocks
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  
> wrote:
> 
> Greetings,
> 
> I'm typesetting an address book whose addresses are in XML. A typical entry 
> has this structure:
> 
>   
> 
> 
>mobile="" /> 
>
>   
> 
>   
> 
> 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
___


[NTG-context] Re: XML processing, unwanted indentation/alignment

2024-02-15 Thread Wolfgang Schuster

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:


   
     
     
       email="" mobile="" />

       
       
     
   

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
___