ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* mkiv digits/units zero padding not working
@ 2020-05-07 15:31 Benjamin Buchmuller
  2020-05-07 16:21 ` Wolfgang Schuster
  0 siblings, 1 reply; 6+ messages in thread
From: Benjamin Buchmuller @ 2020-05-07 15:31 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi,

I’m trying to get

\digits{15.0=}±\digits{1.00}

\digits{_8.12}±\digits{0.34}

horizontally aligned as

15.0 ±1.00
 8.12±0.34

But I get

15.0±1.00
 8.12±0.34

instead.

From the source (phys-dim.mkiv), I can see that “=“ should expand to \hphantom{0}. (I think \zeropoint in the table is outdated, since \def\zeropoint\hphantom{0} does not solve the problem either.)

I can’t use tabulate or alignment in math mode for this problem unfortunately.

Any hints would be very welcome.

Thanks


Benjamin
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: mkiv digits/units zero padding not working
  2020-05-07 15:31 mkiv digits/units zero padding not working Benjamin Buchmuller
@ 2020-05-07 16:21 ` Wolfgang Schuster
  2020-05-07 17:41   ` Benjamin Buchmuller
  0 siblings, 1 reply; 6+ messages in thread
From: Wolfgang Schuster @ 2020-05-07 16:21 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Benjamin Buchmuller

Benjamin Buchmuller schrieb am 07.05.2020 um 17:31:
> Hi,
> 
> I’m trying to get
> 
> \digits{15.0=}±\digits{1.00}
> 
> \digits{_8.12}±\digits{0.34}
> 
> horizontally aligned as
> 
> 15.0 ±1.00
>   8.12±0.34
> 
> But I get
> 
> 15.0±1.00
>   8.12±0.34
> 
> instead.
> 
>  From the source (phys-dim.mkiv), I can see that “=“ should expand to \hphantom{0}. (I think \zeropoint in the table is outdated, since \def\zeropoint\hphantom{0} does not solve the problem either.)

1. Which table?

2. This is not how \def works.

3. When you redefine \zeropoint (which isn't a macro) you're going to 
break everything.

> I can’t use tabulate or alignment in math mode for this problem unfortunately.

I looked at the code and the problem is = can only be used to insert 
space for two digits (e.g. 100.==).

Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: mkiv digits/units zero padding not working
  2020-05-07 16:21 ` Wolfgang Schuster
@ 2020-05-07 17:41   ` Benjamin Buchmuller
  2020-05-07 18:00     ` Wolfgang Schuster
  0 siblings, 1 reply; 6+ messages in thread
From: Benjamin Buchmuller @ 2020-05-07 17:41 UTC (permalink / raw)
  To: Wolfgang Schuster; +Cc: mailing list for ConTeXt users

Hi Wolfang,

Thank you for your reply. I have indeed not explained my intended result very clearly. 

1. 

Primarily, I need to get the two values aligned at the digit separator of the first and second number respectively and overall at the ± sign. I’m working in an xtable, where I have entries such as

\startxcell \mpm{14.0==}{_1.5==} \stopxcell
\startxcell \mpm{_0.034}{_0.013} \stopxcell

and defined 

\def\mpm#1#2{
	\ifsecondargument
	\digits{#1}\,±\,\digits{#2}%
	\else
	\digits{#1}%
	\fi
}

Since I was hoping that I could exploit the zeropadding of \digits to get the format right. Indeed, it would save a lot of typing, if I wouldn’t have to specify the padding manually and I vaguely recall that there is somewhere a ConTeXt solution that can make such alignments, but I simply can’t find it any more …

2. + 3.

Absolutely right, this is my bad. I have badly mixed from Hans’ solution to a similar problem, 

https://www.mail-archive.com/ntg-context@ntg.nl/msg00724.html

which was actually \def\zeroamount{-} and the example in the source, I didn’t read properly. Just skip that part. :)

4. 

Indeed, 

\startxcell \mpm{14.==}{_1.5=} \stopxcell
\startxcell \mpm{_0.03}{_0.01} \stopxcell

aligns properly. But sometimes, I have the first digit specified, but not the second and unfortunately this doesn’t work

\startxcell \mpm{14.5=}{_1.5=} \stopxcell
\startxcell \mpm{_0.03}{_0.01} \stopxcell

because = is not immediately preceded by .



> On 7 May 2020, at 18:21, Wolfgang Schuster <wolfgang.schuster.lists@gmail.com> wrote:
> 
> Benjamin Buchmuller schrieb am 07.05.2020 um 17:31:
>> Hi,
>> I’m trying to get
>> \digits{15.0=}±\digits{1.00}
>> \digits{_8.12}±\digits{0.34}
>> horizontally aligned as
>> 15.0 ±1.00
>>  8.12±0.34
>> But I get
>> 15.0±1.00
>>  8.12±0.34
>> instead.
>> From the source (phys-dim.mkiv), I can see that “=“ should expand to \hphantom{0}. (I think \zeropoint in the table is outdated, since \def\zeropoint\hphantom{0} does not solve the problem either.)
> 
> 1. Which table?
> 
> 2. This is not how \def works.
> 
> 3. When you redefine \zeropoint (which isn't a macro) you're going to break everything.
> 
>> I can’t use tabulate or alignment in math mode for this problem unfortunately.
> 
> I looked at the code and the problem is = can only be used to insert space for two digits (e.g. 100.==).
> 
> Wolfgang

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: mkiv digits/units zero padding not working
  2020-05-07 17:41   ` Benjamin Buchmuller
@ 2020-05-07 18:00     ` Wolfgang Schuster
  2020-05-07 19:22       ` Benjamin Buchmuller
  0 siblings, 1 reply; 6+ messages in thread
From: Wolfgang Schuster @ 2020-05-07 18:00 UTC (permalink / raw)
  To: Benjamin Buchmuller; +Cc: mailing list for ConTeXt users

Benjamin Buchmuller schrieb am 07.05.2020 um 19:41:
> Hi Wolfang,
> 
> Thank you for your reply. I have indeed not explained my intended result very clearly.
> 
> 1.
> 
> Primarily, I need to get the two values aligned at the digit separator of the first and second number respectively and overall at the ± sign. I’m working in an xtable, where I have entries such as
> 
> \startxcell \mpm{14.0==}{_1.5==} \stopxcell
> \startxcell \mpm{_0.034}{_0.013} \stopxcell
> 
> and defined
> 
> \def\mpm#1#2{
> 	\ifsecondargument
> 	\digits{#1}\,±\,\digits{#2}%
> 	\else
> 	\digits{#1}%
> 	\fi
> }

Is there something missing in here because the \ifsecondargument check 
here makes non sense because the second argument is mandatory and not 
optional.

Is this what you want?

\define[2]\mpm
   {\digits{#1}%
    \doifsomething{#2}{\,±\,\digits{#2}}}

> Since I was hoping that I could exploit the zeropadding of \digits to get the format right. Indeed, it would save a lot of typing, if I wouldn’t have to specify the padding manually and I vaguely recall that there is somewhere a ConTeXt solution that can make such alignments, but I simply can’t find it any more …

You can align number on the decimal point (comma) but this works only 
when you have only one number in a cell.

\starttext

\startxtable[aligncharacter=yes,alignmentcharacter=±]
     \startxrow
         \startxcell
             \digits {14.0} ± \digits {1.5}
         \stopxcell
     \stopxrow
     \startxrow
         \startxcell
             \digits {0.034} ± \digits {0.013}
         \stopxcell
     \stopxrow
\stopxtable

\stoptext

> 2. + 3.
> 
> Absolutely right, this is my bad. I have badly mixed from Hans’ solution to a similar problem,
> 
> https://www.mail-archive.com/ntg-context@ntg.nl/msg00724.html
> 
> which was actually \def\zeroamount{-} and the example in the source, I didn’t read properly. Just skip that part. :)

The message is from 2003!

> 4.
> 
> Indeed,
> 
> \startxcell \mpm{14.==}{_1.5=} \stopxcell
> \startxcell \mpm{_0.03}{_0.01} \stopxcell
> 
> aligns properly. But sometimes, I have the first digit specified, but not the second and unfortunately this doesn’t work
> 
> \startxcell \mpm{14.5=}{_1.5=} \stopxcell
> \startxcell \mpm{_0.03}{_0.01} \stopxcell
> 
> because = is not immediately preceded by .

Can you write another mail with a request for this.

Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: mkiv digits/units zero padding not working
  2020-05-07 18:00     ` Wolfgang Schuster
@ 2020-05-07 19:22       ` Benjamin Buchmuller
  2020-05-07 20:13         ` Benjamin Buchmuller
  0 siblings, 1 reply; 6+ messages in thread
From: Benjamin Buchmuller @ 2020-05-07 19:22 UTC (permalink / raw)
  To: Wolfgang Schuster; +Cc: mailing list for ConTeXt users

Hi Wolfgang,

you are (of course) right again. I realised that I wouldn’t get the expected behaviour after checking the snippet isolated from my document’s context, where it is embedded in a \startplacetable[…]{}{}. I’m still learning to get the gist of the \doifs, the curly and square bracketed arguments and so on. Thanks for the hint! 

Seems like I’m going to make three cells and span the header column for now, though I guess it would be a nice feature to have the padding working in the other cases.

I’ll write a feature request for no 4.

Thanks!


> On 7 May 2020, at 20:00, Wolfgang Schuster <wolfgang.schuster.lists@gmail.com> wrote:
> 
> Benjamin Buchmuller schrieb am 07.05.2020 um 19:41:
>> Hi Wolfang,
>> Thank you for your reply. I have indeed not explained my intended result very clearly.
>> 1.
>> Primarily, I need to get the two values aligned at the digit separator of the first and second number respectively and overall at the ± sign. I’m working in an xtable, where I have entries such as
>> \startxcell \mpm{14.0==}{_1.5==} \stopxcell
>> \startxcell \mpm{_0.034}{_0.013} \stopxcell
>> and defined
>> \def\mpm#1#2{
>> 	\ifsecondargument
>> 	\digits{#1}\,±\,\digits{#2}%
>> 	\else
>> 	\digits{#1}%
>> 	\fi
>> }
> 
> Is there something missing in here because the \ifsecondargument check here makes non sense because the second argument is mandatory and not optional.
> 
> Is this what you want?
> 
> \define[2]\mpm
>  {\digits{#1}%
>   \doifsomething{#2}{\,±\,\digits{#2}}}
> 
>> Since I was hoping that I could exploit the zeropadding of \digits to get the format right. Indeed, it would save a lot of typing, if I wouldn’t have to specify the padding manually and I vaguely recall that there is somewhere a ConTeXt solution that can make such alignments, but I simply can’t find it any more …
> 
> You can align number on the decimal point (comma) but this works only when you have only one number in a cell.
> 
> \starttext
> 
> \startxtable[aligncharacter=yes,alignmentcharacter=±]
>    \startxrow
>        \startxcell
>            \digits {14.0} ± \digits {1.5}
>        \stopxcell
>    \stopxrow
>    \startxrow
>        \startxcell
>            \digits {0.034} ± \digits {0.013}
>        \stopxcell
>    \stopxrow
> \stopxtable
> 
> \stoptext
> 
>> 2. + 3.
>> Absolutely right, this is my bad. I have badly mixed from Hans’ solution to a similar problem,
>> https://www.mail-archive.com/ntg-context@ntg.nl/msg00724.html
>> which was actually \def\zeroamount{-} and the example in the source, I didn’t read properly. Just skip that part. :)
> 
> The message is from 2003!
> 
>> 4.
>> Indeed,
>> \startxcell \mpm{14.==}{_1.5=} \stopxcell
>> \startxcell \mpm{_0.03}{_0.01} \stopxcell
>> aligns properly. But sometimes, I have the first digit specified, but not the second and unfortunately this doesn’t work
>> \startxcell \mpm{14.5=}{_1.5=} \stopxcell
>> \startxcell \mpm{_0.03}{_0.01} \stopxcell
>> because = is not immediately preceded by .
> 
> Can you write another mail with a request for this.
> 
> Wolfgang

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: mkiv digits/units zero padding not working
  2020-05-07 19:22       ` Benjamin Buchmuller
@ 2020-05-07 20:13         ` Benjamin Buchmuller
  0 siblings, 0 replies; 6+ messages in thread
From: Benjamin Buchmuller @ 2020-05-07 20:13 UTC (permalink / raw)
  To: Wolfgang Schuster; +Cc: mailing list for ConTeXt users

Following up on the work-around, here is my improved code for xtable.

What doesn’t work is:

* alignment on the decimal separator takes place only in the first column with decimals (i.e. B), not on the  following one; this is independent of R1 having a decimal value in this column or not

* row spanning is now tricky since the width of the header column is taken for the first of the three rows spanned, which becomes even more complicated with option=stretch, I guess if I right align the second column and would phantomize the hsize of the header, this could work with a bit of optimization.

What I like about this approach however is that one could read the two arguments from a CSV file, which would save a lot of typing (and to manually specify the padding).

\def\mpm#1#2{
	\doifsomethingelse{#2}{
	\startxcell[align=left] \digits{#1} \stopxcell
	\startxcell ± \stopxcell
	\startxcell \digits{#2} \stopxcell
	}{
	\startxcell[align=left] \digits{#1} \stopxcell
	\startxcell \stopxcell
	\startxcell \digits{#2} \stopxcell
	}
}

\startxtable[split=repeat, aligncharacter=yes, alignmentcharacter={.}]

	\startxtablehead
		\startxrow[topframe=on, foregroundstyle=bold]
		\startxcell A \stopxcell
		\startxcell[align=left, nx=3] Bla bla bla bla bla bla bla bla \stopxcell
		\startxcell C \stopxcell
		\stopxrow
	\stopxtablehead
	
	\startxtablebody
		\startxrow[topframe=on]
		\startxcell R1 \stopxcell
		\mpm{12.3}{}%{1.5}
		\startxcell one \stopxcell
		\stopxrow
		
		\startxrow
		\startxcell R2 \stopxcell
		\mpm{0.01}{0.023}
		\startxcell two \stopxcell
		\stopxrow
		
		\startxrow
		\startxcell R3 \stopxcell
		\mpm{2.3}{0.1}
		\startxcell three\stopxcell
		\stopxrow
		
	\stopxtablebody

\stopxtable	

> On 7 May 2020, at 21:22, Benjamin Buchmuller <benjamin.buchmuller@gmail.com> wrote:
> 
> Hi Wolfgang,
> 
> you are (of course) right again. I realised that I wouldn’t get the expected behaviour after checking the snippet isolated from my document’s context, where it is embedded in a \startplacetable[…]{}{}. I’m still learning to get the gist of the \doifs, the curly and square bracketed arguments and so on. Thanks for the hint! 
> 
> Seems like I’m going to make three cells and span the header column for now, though I guess it would be a nice feature to have the padding working in the other cases.
> 
> I’ll write a feature request for no 4.
> 
> Thanks!
> 
> 
>> On 7 May 2020, at 20:00, Wolfgang Schuster <wolfgang.schuster.lists@gmail.com> wrote:
>> 
>> Benjamin Buchmuller schrieb am 07.05.2020 um 19:41:
>>> Hi Wolfang,
>>> Thank you for your reply. I have indeed not explained my intended result very clearly.
>>> 1.
>>> Primarily, I need to get the two values aligned at the digit separator of the first and second number respectively and overall at the ± sign. I’m working in an xtable, where I have entries such as
>>> \startxcell \mpm{14.0==}{_1.5==} \stopxcell
>>> \startxcell \mpm{_0.034}{_0.013} \stopxcell
>>> and defined
>>> \def\mpm#1#2{
>>> 	\ifsecondargument
>>> 	\digits{#1}\,±\,\digits{#2}%
>>> 	\else
>>> 	\digits{#1}%
>>> 	\fi
>>> }
>> 
>> Is there something missing in here because the \ifsecondargument check here makes non sense because the second argument is mandatory and not optional.
>> 
>> Is this what you want?
>> 
>> \define[2]\mpm
>> {\digits{#1}%
>>  \doifsomething{#2}{\,±\,\digits{#2}}}
>> 
>>> Since I was hoping that I could exploit the zeropadding of \digits to get the format right. Indeed, it would save a lot of typing, if I wouldn’t have to specify the padding manually and I vaguely recall that there is somewhere a ConTeXt solution that can make such alignments, but I simply can’t find it any more …
>> 
>> You can align number on the decimal point (comma) but this works only when you have only one number in a cell.
>> 
>> \starttext
>> 
>> \startxtable[aligncharacter=yes,alignmentcharacter=±]
>>   \startxrow
>>       \startxcell
>>           \digits {14.0} ± \digits {1.5}
>>       \stopxcell
>>   \stopxrow
>>   \startxrow
>>       \startxcell
>>           \digits {0.034} ± \digits {0.013}
>>       \stopxcell
>>   \stopxrow
>> \stopxtable
>> 
>> \stoptext
>> 
>>> 2. + 3.
>>> Absolutely right, this is my bad. I have badly mixed from Hans’ solution to a similar problem,
>>> https://www.mail-archive.com/ntg-context@ntg.nl/msg00724.html
>>> which was actually \def\zeroamount{-} and the example in the source, I didn’t read properly. Just skip that part. :)
>> 
>> The message is from 2003!
>> 
>>> 4.
>>> Indeed,
>>> \startxcell \mpm{14.==}{_1.5=} \stopxcell
>>> \startxcell \mpm{_0.03}{_0.01} \stopxcell
>>> aligns properly. But sometimes, I have the first digit specified, but not the second and unfortunately this doesn’t work
>>> \startxcell \mpm{14.5=}{_1.5=} \stopxcell
>>> \startxcell \mpm{_0.03}{_0.01} \stopxcell
>>> because = is not immediately preceded by .
>> 
>> Can you write another mail with a request for this.
>> 
>> Wolfgang
> 

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-05-07 20:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-07 15:31 mkiv digits/units zero padding not working Benjamin Buchmuller
2020-05-07 16:21 ` Wolfgang Schuster
2020-05-07 17:41   ` Benjamin Buchmuller
2020-05-07 18:00     ` Wolfgang Schuster
2020-05-07 19:22       ` Benjamin Buchmuller
2020-05-07 20:13         ` Benjamin Buchmuller

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).