Re: [NTG-context] Spacing in \unit - SOLVED

2022-10-21 Thread Gavin via ntg-context
Hans,

I made a small mistake in the phys-dim.mkxl file I sent you. I removed a % at 
the end of lines 469 and 485. Without the %, using alternative=text causes 
extra space before the unit. A corrected phys-dim.mkxl is attached.

Gavin



phys-dim.mkxl
Description: application/applefile
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

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


Re: [NTG-context] Spacing in \unit - SOLVED

2022-10-21 Thread Gavin via ntg-context
Hi Hans,

> I'll look into it (with Mikael as some relates to math) once you're done 
> playing and provide suggestions and tests.

I’m done playing. Below are tests and suggestions. Sorry it has taken so long 
for me to put this together.


Tests
I attached two test files. The first, units-spacing.tex, is for testing spacing 
for \unit used in text, inline math, and display math. The second, 
units-linebreaks.tex, tests line breaks when \unit. is used in text or in 
inline math. Line breaks were not my primary interest, but Max and Alan were 
quite interested. My proposed fixes for spacing also fix their concerns about 
line breaks.I tried to make these tests match the style of the Test Suite. They 
could be included there if they are useful.


Suggestions
I attached my my modified phys-dim.mkxl. All of my changes are commented and 
signed with -GP to make them easy to find. Below are comments on the five 
issues I addressed (not including line breaks). The first four of these are 
fixes.I don’t think any of these fixes are controversial or require new 
options. The fifth, regarding the space around the \times in scientific 
notation, might be an appropriate option, rather than a universal fix.


1. The \cdot in units should not have space around it.
These lines produce the \cdot between units, one is for the default \cdot, the 
other when the separator=cdot option is used. I’m not entirely sure why they 
are separate. Now, in math mode, the \cdot is changed to an ord. (ll. 392-393)

\protected\def\phys_units_separator
 
{\ifcsname\??unitseparator\unitparameter\c!separator\endcsname\lastnamedcs\else\ifmmode\mathord\cdot\else\cdot\fi\fi}
 % Made \cdot an "ord" in math mode -GP

\installunitsseparator\v!normal{\ifmmode\mathord\cdot\else\cdot\fi}  % Made 
\cdot an "ord" in math mode -GP


2. Space is needed between number and units
To get the thin space between the number and the units (ll.412-418)

\protected\def\phys_units_space
 {\ifmmode
\thinspace % let the atoms do the work. Right now atoms aren't doing the 
work, so I put in a \thinspace -GP
  \else
\unskip % weird, why is unskip needed

\ifcsname\??unitspace\unitparameter\c!space\endcsname\lastnamedcs\else\unitsmediumspace\fi
  \fi}


3. Space is needed after the units, before the next relation, binary operator, 
etc. Right now there seems to be no space added between the new dimension class 
and the relation and binary operator class. Until the space around the 
dimension class is fixed, The units should not be assigned to the dimension 
class, which means removing the code that sets units to this class. (ll. 
618-623)

\def\phys_units_start
 {\ifmmode
\dostarttagged\t!maction\t!unit
% \mathatom % I removed this because the correct spaces after dim haven't 
been set (e.g. dimbin, dimrel) -GP
%\s!leftclass  \mathdimensioncode
%\s!rightclass \mathdimensioncode
\bgroup
  \else
\dostarttagged\t!unit\empty
  \fi
  \let\phys_units_finish\phys_units_stop
  \let\phys_units_start\relax}


4. Remove hardcoded backspace before the solidus in units. (If this space 
should be tighter, it probably should be dealt with for every solidus, not just 
the solidus in \unit the unit command.) (ll.412-418)

\permanent\protected\def\unitsSOLIDUS
 {%\ifnum\c_phys_units_state=\plusone % suffix  % Removed three lines to 
eliminate backspace before / -GP
  %  \unitsbackspace
  %\fi
  {/}%
  }%\unitsbackspace}


5. I think the \times in scientific notation should not have extra space. 
Everyone who commented on the mailing list agreed. However, I’m not sure that 
this is a universal desire, so it might be good to add an options, like 
scispace=normal for the usual binop space around the \times and scispace=tight 
for no extra space around \times. The changed line in phys-dime.mkxl used to 
add space around the \times in text. Now, instead, it removes the space around 
the \times in math by making the \times an ord. (ll. 170-172)

\permanent\protected\def\digitstextbinop#1% assumes preceding
 {\ifmmode\mathord#1\else\nobreak#1\fi} % Removed space around binop (\times or 
\cdot) in \units -GP
 %{\ifmmode#1\else\fourperemspace\nobreak#1\fourperemspace\fi} % This is the 
old line with spaces -GP


Those are my five suggestions. Thanks for looking at spacing in \units!

Gavin




units-spacing.tex
Description: Binary data


units-linebreaks.tex
Description: Binary data


phys-dim.mkxl
Description: Binary data


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

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


Re: [NTG-context] Spacing in \unit - SOLVED

2022-10-14 Thread Hans Hagen via ntg-context

On 10/13/2022 1:52 PM, Gavin via ntg-context wrote:

Hi Oli,


Thank four your effort. I found out, that the following definition of a new 
unit, i called it SI, results also in a correct spaceing in the math 
environment:

\defineunit[SI][alternative=text]

It seems, that the option alternative=text solves the problem with no spaces 
between value and unit in the math environment.


That is a terrific solution that doesn’t require any messing with 
phys-dim.mkxl. You do not need to define a new unit. I got your result using 
this line:

\setupunits[alternative=text]

This fixed the most significant problems with \unit in most situations. I’m 
still applying some of my solutions as well.
I'll look into it (with Mikael as some relates to math) once you're done 
playing and provide suggestions and tests.


Hans


-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
   tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-

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

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


Re: [NTG-context] Spacing in \unit - degrees

2022-10-13 Thread Alan Braslau via ntg-context
On Wed, 12 Oct 2022 21:14:52 -0600
Gavin  wrote:

> As a recovering string theorist, I cannot help but speculate that
> this rule extends to spherical coordinates in any number of
> dimensions. However, if you don’t want the space, you can use
> 135\unit{℃}, which does not add a space.

Will 135\unit{℃} ever break between the digits 135 and the "unit"?
I agree that \unit should probably use an \mbox to prevent unwanted
breaks.

The other role of \unit, I understand, is to uniformize the
representation of numbers (digits).

> > Related,
> > \unit{90°} does not seem to introduce a space, as indeed it should
> > not.  

So ℃ needs to be registered as a degree and prevent any spacing.

> Also related, using \unit for just the units, and not the number, is
> useful when they follow something that is not a number, like a
> vector: $ \vec v = (4.0, -3.2, 1.5)\unit{m/s} $. You frequently do
> not want a space in that situation.

Why would one not want a (small) space before m/s in the above
example?

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

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


Re: [NTG-context] Spacing in \unit - SOLVED

2022-10-13 Thread Gavin via ntg-context
Hi Oli,

> Thank four your effort. I found out, that the following definition of a new 
> unit, i called it SI, results also in a correct spaceing in the math 
> environment:
> 
> \defineunit[SI][alternative=text]
> 
> It seems, that the option alternative=text solves the problem with no spaces 
> between value and unit in the math environment.

That is a terrific solution that doesn’t require any messing with 
phys-dim.mkxl. You do not need to define a new unit. I got your result using 
this line:

\setupunits[alternative=text]

This fixed the most significant problems with \unit in most situations. I’m 
still applying some of my solutions as well.

Thanks!
Gavin

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

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


Re: [NTG-context] Spacing in \unit - SOLVED

2022-10-13 Thread Oliver Sieber via ntg-context
Hi Gavin

Thank four your effort. I found out, that the following definition of a new 
unit, i called it SI, results also in a correct spaceing in the math 
environment:

\defineunit[SI][alternative=text]

It seems, that the option alternative=text solves the problem with no spaces 
between value and unit in the math environment.

Maybe this can be used to solve it easier in the code. I will have a look at 
phys-dim to solve it directly, if I find the time.

Best regards
Oli

> Am 12.10.2022 um 23:54 schrieb Gavin via ntg-context - ntg-context at ntg.nl 
> :
> 
> Hi Max, Alan, Bruce, Hans, et.al
> 
> I solved my four issues with \unit spacing. In the process, I prevented 
> unwanted line breaks and removed an overzealous backspace before division 
> symbols. Below is a MWE that shows all of these issues, as well as pictures 
> of the result with the unmodified phys-dim.mkxl and with my modified 
> phys-dim.mkxl. The final result is exactly what I wanted.
> 
> If anyone wants my changes, either for their own use or to improve the 
> distributed phys-dim.mkxl, I’m happy to share.
> 
> Thanks for all of your comments!
> Gavin
> 
> 
> MWE:
> 
> \setuppapersize[A5]
> 
> \starttext
> 
> The \type{\unit} command in text produces \unit{1.23e5 kg m^2/s^2}.
> 
> Inline math \type{$\unit$} produces $\unit{1.23e5 kg m^2/s^2}$.
> 
> Display math produces
> \startformula
> \unit{1.23e5 kg m^2/s^2} + \unit{8.64e5 newton m} = \unit{987,000 joule}
> \stopformula
> 
> Line breaking in math:
> 
> {\hsize=0pt $G = \unit{6.6743e-11 m3 kg-1 s-2}$}
> 
> \blank
> Line breaking in text:
> 
> {\hsize=0pt \unit{6.6743e-11 m3 kg-1 s-2}}
> 
> \stoptext
> 
> Output with unmodified phys-dim.mkxl:
> 
> 
> Output with my modified phys-dim.mkxl:
> 
> 
> 
> 
>> On Oct 10, 2022, at 12:15 AM, Max Chernoff via ntg-context 
>>  wrote:
>> 
>> Hi Alan,
>> 
>>> I would very strongly argue that the space between the number and the
>>> following units be UNBREAKABLE. Perhaps a thin space (preference), but
>>> most certainly non-breakable.
>>> 
>>> Similarly around the times in scientific notation.
>>> 
>>> I further cannot imagine that a line break be acceptable around a \cdot
>>> in composite units.
>>> 
>>> This can possibly lead to overfill and underfill, something that I find
>>> *infinitely* more acceptable then breaking numbers and units.
>> 
>> Yes, I agree completely here.
>> 
>>> I do not know or use the \units command. Maybe it uses unbreakable
>>> spaces, maybe not. I would never use it unless it could be configured
>>> to only use nonbreakable spaces.
>> 
>> The current behaviour doesn't break the unit from the number, but it
>> does split the scientific notation.
>> 
>> This test file:
>> 
>>  \starttext
>>  \hsize=0pt Math: $G = \unit{6.6743e-11 m3 kg-1 s-2}$
>> 
>>  \hsize=0pt Text: \unit{6.6743e-11 m3 kg-1 s-2}
>>  \stoptext
>> 
>> gives:
>> 
>>  Math:
>>  퐺=
>>  6.6743×
>>  10–11m3⋅kg–1⋅s–2
>>  Text:
>>  6.6743
>>  ×
>>  10−11 m3⋅kg−1⋅s−2
>> 
>> which isn't great. In my opinion, the \unit command should be typeset in an
>> \hbox (or similar) since I can't think of any circumstances where breaking
>> it would be reasonable.
>> 
>> Thanks,
>> -- Max
>> ___
>> If your question is of interest to others as well, please add an entry to 
>> the Wiki!
>> 
>> maillist : ntg-context@ntg.nl / 
>> https://www.ntg.nl/mailman/listinfo/ntg-context
>> webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
>> archive  : https://bitbucket.org/phg/context-mirror/commits/
>> wiki : https://contextgarden.net
>> ___
> 
> ___
> If your question is of interest to others as well, please add an entry to the 
> Wiki!
> 
> maillist : ntg-context@ntg.nl / 
> https://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki : https://contextgarden.net
> ___



signature.asc
Description: Message signed with OpenPGP
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

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


Re: [NTG-context] Spacing in \unit - degrees

2022-10-12 Thread Gavin via ntg-context
Hi Alan

> On Oct 12, 2022, at 5:55 PM, Alan Braslau via ntg-context 
>  wrote:
> 
> \unit{135℃} adds a space after the digits 135.
> I do not believe that this is correct
> (for ℃ is *not* a "real" unit, unlike \unit{408.15 K} which *is* a real
> unit).

According to “Scientific Style and Format: The CSE Manual for Authors, Editors, 
and Publishers, 8th Ed.” by the Council of Science Editors:

> The symbol for degrees Celsius, ℃ (not simply C), is separated from the 
> number on its left by one space, whereas the degree symbol for a plane angle 
> (e.g. a 45° angle) and for longitude and latitude (e.g. 45°30’N) is not 
> separated from the numeral by a space. [§12.2.1.1 SI Rules, pp.169-170]

As a recovering string theorist, I cannot help but speculate that this rule 
extends to spherical coordinates in any number of dimensions. However, if you 
don’t want the space, you can use 135\unit{℃}, which does not add a space.

> Also,
> \unit{135°C} drops the "C". Is this a parsing bug?

It is not a parsing bug; it is a limitation. In general, units must be spelled 
out (newton, joule, etc.) which produces the correct SI symbol (N, J, etc.). 
Some units are also recognized by their symbols (m, s, kg,…). Celsius is 
recognized by the single character “℃” and by the name “celsius”, but not by 
the two character combination “°C”. Probably, the parser could be expanded to 
recognize the two character combination. That requires mucking around in 
phys-dim.lua, which I’m not going to touch.

Use \unit{135 celsius} if you want the space, and 135\unit{celsius} if you 
don’t. Or you can add your favorite abbreviations:

\registerunit[
  °C=°C,
  ]
\setupunittext[
  °C=℃,
  ]

Then use \unit{135°C} if you want the space and 135\unit{°C} if you don’t.

> Related,
> \unit{90°} does not seem to introduce a space, as indeed it should not.

Also related, using \unit for just the units, and not the number, is useful 
when they follow something that is not a number, like a vector: $ \vec v = 
(4.0, -3.2, 1.5)\unit{m/s} $. You frequently do not want a space in that 
situation.

Now that I’ve had this success messing with other people’s code, I’ve got your 
luagraph module on my mind.

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

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


Re: [NTG-context] Spacing in \unit - SOLVED

2022-10-12 Thread Gavin via ntg-context
Hi Max and Rik

> On Oct 12, 2022, at 4:49 PM, Max Chernoff  wrote:
> 
> This new output looks *much* better than the old one, thanks! 

Thank you!

> My only comment is that the spacing around the multiplication sign looks
> a little too tight to me. The original spacing was probably too large,
> but I think that a little more space than you currently have would be
> better.

I haven’t adjusted the space directly. I just changed the \times and \cdot from 
class binom to class ord. I’m not going to tweak the space. I don’t even use 
this font. With proportional numbers in Libertinus, I think the \times looks 
great.



PastedGraphic-5.pdf
Description: Adobe PDF document


With tabular numbers, the \times looks a bit off center due to the extra space 
around the following 1.

>> If anyone wants my changes, either for their own use or to improve the
>> distributed phys-dim.mkxl, I’m happy to share.
> 
> Yes, can you please share that to the list?

See below for comments, and the full modified phys-dim.mkxl is attached

> Hi Rik,
> 
>> It does look like you have introduced additional space before the 
>> solidus. Was that intentional?
> 
> I believe that that is intentional. From the earlier email:
> 
>> removed an overzealous backspace before division symbols.
> 
> This new spacing looks much more even to me, especially around the
> exponents.

It was intentional. I didn’t add space. I removed a backspace in the \unit code.

Below I list all of my changes to the phys-dim.mkxl code, with some commentary. 
I have added comments in the code everywhere I made a change, and I signed the 
changes with -GP, so they are easy to find.

Thanks for your encouragement, because my high school physics students 
certainly do not give a s#!t.

I hope some people find this useful!

Gavin



This used to add space around the \times in text. Now, instead, it removes the 
space around the \times in math by making the \times an ord. (ll. 170-172)

\permanent\protected\def\digitstextbinop#1% assumes preceding
  {\ifmmode\mathord#1\else\nobreak#1\fi} % Removed space around binop (\times 
or \cdot) in \units -GP
  %{\ifmmode#1\else\fourperemspace\nobreak#1\fourperemspace\fi} % This is the 
old line with spaces -GP


These lines produce the \cdot between units, one is for the default \cdot, the 
other when the separator=cdot option is used. I’m not entirely sure why they 
are separate. Now, in math mode, the \cdot is changed to an ord. (ll. 392-393

\protected\def\phys_units_separator
  
{\ifcsname\??unitseparator\unitparameter\c!separator\endcsname\lastnamedcs\else\ifmmode\mathord\cdot\else\cdot\fi\fi}
 % Made \cdot an "ord" in math mode -GP

\installunitsseparator\v!normal{\ifmmode\mathord\cdot\else\cdot\fi}  % Made 
\cdot an "ord" in math mode -GP


To get the thin space between the number and the units (ll.412-418)

\protected\def\phys_units_space
  {\ifmmode
 \thinspace % let the atoms do the work. Right now atoms aren't doing the 
work, so I put in a \thinspace -GP
   \else
 \unskip % weird, why is unskip needed
 
\ifcsname\??unitspace\unitparameter\c!space\endcsname\lastnamedcs\else\unitsmediumspace\fi
   \fi}


This had a hardcoded backspace before the solidus. I think it looks better 
without. Even if this space should be tighter, it probably should be dealt with 
for every solidus, not just the solidus in \unit the unit command. (ll.412-418)

\permanent\protected\def\unitsSOLIDUS
  {%\ifnum\c_phys_units_state=\plusone % suffix  % Removed three lines to 
eliminate backspace before / -GP
   %  \unitsbackspace
   %\fi
   {/}%
   }%\unitsbackspace}


Finally, until the space around the dimension class is fixed, I’m just removing 
the code that sets units to this class. (ll. 618-623)

\def\phys_units_start
  {\ifmmode
 \dostarttagged\t!maction\t!unit
% \mathatom % I removed this because the correct spaces after dim haven't 
been set (e.g. dimbin, dimrel) -GP
%\s!leftclass  \mathdimensioncode
%\s!rightclass \mathdimensioncode
 \bgroup
   \else
 \dostarttagged\t!unit\empty
   \fi
   \let\phys_units_finish\phys_units_stop
   \let\phys_units_start\relax}




phys-dim.mkxl
Description: Binary data

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

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


Re: [NTG-context] Spacing in \unit - degrees

2022-10-12 Thread Alan Braslau via ntg-context
Further \unit question(s):

\unit{135℃} adds a space after the digits 135.
I do not believe that this is correct
(for ℃ is *not* a "real" unit, unlike \unit{408.15 K} which *is* a real
unit).

Also,
\unit{135°C} drops the "C". Is this a parsing bug?

Related,
\unit{90°} does not seem to introduce a space, as indeed it should not.

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

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


Re: [NTG-context] Spacing in \unit - SOLVED

2022-10-12 Thread Max Chernoff via ntg-context
Hi Gavin,

On Wed, 2022-10-12 at 15:54 -0600, Gavin wrote:
> Hi Max, Alan, Bruce, Hans, et.al
> 
> I solved my four issues with \unit spacing. In the process, I
> prevented unwanted line breaks and removed an overzealous backspace
> before division symbols. Below is a MWE that shows all of these
> issues, as well as pictures of the result with the unmodified phys-
> dim.mkxl and with my modified phys-dim.mkxl. The final result is
> exactly what I wanted.

This new output looks *much* better than the old one, thanks! 

My only comment is that the spacing around the multiplication sign looks
a little too tight to me. The original spacing was probably too large,
but I think that a little more space than you currently have would be
better.

> If anyone wants my changes, either for their own use or to improve the
> distributed phys-dim.mkxl, I’m happy to share.

Yes, can you please share that to the list?

Hi Rik,

> It does look like you have introduced additional space before the 
> solidus. Was that intentional?

I believe that that is intentional. From the earlier email:

> removed an overzealous backspace before division symbols.

This new spacing looks much more even to me, especially around the
exponents.

Thanks,
-- Max
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

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


Re: [NTG-context] Spacing in \unit - SOLVED

2022-10-12 Thread Rik Kabel via ntg-context


On 2022-10-12 17:54, Gavin via ntg-context wrote:

Hi Max, Alan, Bruce, Hans, et.al

I solved my four issues with \unit spacing. In the process, I prevented 
unwanted line breaks and removed an overzealous backspace before division 
symbols. Below is a MWE that shows all of these issues, as well as pictures of 
the result with the unmodified phys-dim.mkxl and with my modified 
phys-dim.mkxl. The final result is exactly what I wanted.

If anyone wants my changes, either for their own use or to improve the 
distributed phys-dim.mkxl, I’m happy to share.

Thanks for all of your comments!
Gavin


MWE:

\setuppapersize[A5]

\starttext

The \type{\unit} command in text produces \unit{1.23e5 kg m^2/s^2}.

Inline math \type{$\unit$} produces $\unit{1.23e5 kg m^2/s^2}$.

Display math produces
\startformula
  \unit{1.23e5 kg m^2/s^2} + \unit{8.64e5 newton m} = \unit{987,000 joule}
\stopformula

Line breaking in math:

{\hsize=0pt $G = \unit{6.6743e-11 m3 kg-1 s-2}$}

\blank
Line breaking in text:

{\hsize=0pt \unit{6.6743e-11 m3 kg-1 s-2}}

\stoptext

Output with unmodified phys-dim.mkxl:


Output with my modified phys-dim.mkxl:





On Oct 10, 2022, at 12:15 AM, Max Chernoff via ntg-context  
wrote:

Hi Alan,


I would very strongly argue that the space between the number and the
following units be UNBREAKABLE. Perhaps a thin space (preference), but
most certainly non-breakable.

Similarly around the times in scientific notation.

I further cannot imagine that a line break be acceptable around a \cdot
in composite units.

This can possibly lead to overfill and underfill, something that I find
*infinitely* more acceptable then breaking numbers and units.

Yes, I agree completely here.


I do not know or use the \units command. Maybe it uses unbreakable
spaces, maybe not. I would never use it unless it could be configured
to only use nonbreakable spaces.

The current behaviour doesn't break the unit from the number, but it
does split the scientific notation.

This test file:

   \starttext
   \hsize=0pt Math: $G = \unit{6.6743e-11 m3 kg-1 s-2}$

   \hsize=0pt Text: \unit{6.6743e-11 m3 kg-1 s-2}
   \stoptext

gives:

   Math:
   퐺=
   6.6743×
   10–11m3⋅kg–1⋅s–2
   Text:
   6.6743
   ×
   10−11 m3⋅kg−1⋅s−2

which isn't great. In my opinion, the \unit command should be typeset in an
\hbox (or similar) since I can't think of any circumstances where breaking
it would be reasonable.

Thanks,
-- Max
___


It does look like you have introduced additional space before the 
solidus. Was that intentional?


--
Rik

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

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


Re: [NTG-context] Spacing in \unit - SOLVED

2022-10-12 Thread Gavin via ntg-context
Hi Max, Alan, Bruce, Hans, et.al

I solved my four issues with \unit spacing. In the process, I prevented 
unwanted line breaks and removed an overzealous backspace before division 
symbols. Below is a MWE that shows all of these issues, as well as pictures of 
the result with the unmodified phys-dim.mkxl and with my modified 
phys-dim.mkxl. The final result is exactly what I wanted.

If anyone wants my changes, either for their own use or to improve the 
distributed phys-dim.mkxl, I’m happy to share.

Thanks for all of your comments!
Gavin


MWE:

\setuppapersize[A5]

\starttext

The \type{\unit} command in text produces \unit{1.23e5 kg m^2/s^2}.

Inline math \type{$\unit$} produces $\unit{1.23e5 kg m^2/s^2}$.

Display math produces
\startformula
 \unit{1.23e5 kg m^2/s^2} + \unit{8.64e5 newton m} = \unit{987,000 joule}
\stopformula

Line breaking in math:

{\hsize=0pt $G = \unit{6.6743e-11 m3 kg-1 s-2}$}

\blank
Line breaking in text:

{\hsize=0pt \unit{6.6743e-11 m3 kg-1 s-2}}

\stoptext

Output with unmodified phys-dim.mkxl:


PastedGraphic-3.pdf
Description: Adobe PDF document


Output with my modified phys-dim.mkxl:


PastedGraphic-2.pdf
Description: Adobe PDF document




> On Oct 10, 2022, at 12:15 AM, Max Chernoff via ntg-context 
>  wrote:
> 
> Hi Alan,
> 
>> I would very strongly argue that the space between the number and the
>> following units be UNBREAKABLE. Perhaps a thin space (preference), but
>> most certainly non-breakable.
>> 
>> Similarly around the times in scientific notation.
>> 
>> I further cannot imagine that a line break be acceptable around a \cdot
>> in composite units.
>> 
>> This can possibly lead to overfill and underfill, something that I find
>> *infinitely* more acceptable then breaking numbers and units.
> 
> Yes, I agree completely here.
> 
>> I do not know or use the \units command. Maybe it uses unbreakable
>> spaces, maybe not. I would never use it unless it could be configured
>> to only use nonbreakable spaces. 
> 
> The current behaviour doesn't break the unit from the number, but it
> does split the scientific notation.
> 
> This test file:
> 
>   \starttext
>   \hsize=0pt Math: $G = \unit{6.6743e-11 m3 kg-1 s-2}$
> 
>   \hsize=0pt Text: \unit{6.6743e-11 m3 kg-1 s-2}
>   \stoptext
> 
> gives:
> 
>   Math:
>   퐺=
>   6.6743×
>   10–11m3⋅kg–1⋅s–2
>   Text:
>   6.6743
>   ×
>   10−11 m3⋅kg−1⋅s−2
> 
> which isn't great. In my opinion, the \unit command should be typeset in an
> \hbox (or similar) since I can't think of any circumstances where breaking
> it would be reasonable.
> 
> Thanks,
> -- Max
> ___
> If your question is of interest to others as well, please add an entry to the 
> Wiki!
> 
> maillist : ntg-context@ntg.nl / 
> https://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki : https://contextgarden.net
> ___

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

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


Re: [NTG-context] Spacing in \unit

2022-10-10 Thread Max Chernoff via ntg-context
Hi Alan,

> I would very strongly argue that the space between the number and the
> following units be UNBREAKABLE. Perhaps a thin space (preference), but
> most certainly non-breakable.
> 
> Similarly around the times in scientific notation.
> 
> I further cannot imagine that a line break be acceptable around a \cdot
> in composite units.
> 
> This can possibly lead to overfill and underfill, something that I find
> *infinitely* more acceptable then breaking numbers and units.

Yes, I agree completely here.

> I do not know or use the \units command. Maybe it uses unbreakable
> spaces, maybe not. I would never use it unless it could be configured
> to only use nonbreakable spaces. 

The current behaviour doesn't break the unit from the number, but it
does split the scientific notation.

This test file:

   \starttext
   \hsize=0pt Math: $G = \unit{6.6743e-11 m3 kg-1 s-2}$
   
   \hsize=0pt Text: \unit{6.6743e-11 m3 kg-1 s-2}
   \stoptext
   
gives:

   Math:
   퐺=
   6.6743×
   10–11m3⋅kg–1⋅s–2
   Text:
   6.6743
   ×
   10−11 m3⋅kg−1⋅s−2
   
which isn't great. In my opinion, the \unit command should be typeset in an
\hbox (or similar) since I can't think of any circumstances where breaking
it would be reasonable.

Thanks,
-- Max
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

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


Re: [NTG-context] Spacing in \unit

2022-10-09 Thread Alan Braslau via ntg-context
On Sat, 8 Oct 2022 11:59:04 -0600
Gavin via ntg-context  wrote:

> I’m trying to fix four issues:
>   - No space between the number and the following units. Should be a
> thin space.
>   - No space between the units and the following symbol (+ and =
> above). Should be appropriate “bin" or “rel" space.
>   - Too much space around the \cdot in the units. Should be treated
> like an “ord" when used to separate units.
>   - Too much space around the \times in the scientific notation.
> Should be treated like an "ord" when used in scientific notation.
> (I'm not sure there is consensus on this.)

Gavin (and the mailing list),

I would very strongly argue that the space between the number and the
following units be UNBREAKABLE. Perhaps a thin space (preference), but
most certainly non-breakable.

Similarly around the times in scientific notation.

I further cannot imagine that a line break be acceptable around a \cdot
in composite units.

This can possibly lead to overfill and underfill, something that I find
*infinitely* more acceptable then breaking numbers and units.

I do not know or use the \units command. Maybe it uses unbreakable
spaces, maybe not. I would never use it unless it could be configured
to only use nonbreakable spaces. 

Perhaps others feel differently?

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

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


[NTG-context] Spacing in \unit

2022-10-08 Thread Gavin via ntg-context
Hi list,

I made a small example with all of the issues I am trying to fix for the \units 
command. The first formula below uses the \unit command, but produces strange 
spacing. The second formula produces the desired spacing, without using the 
\unit command.

\showmakeup[mathglue] %\mathspacingmode=1

\starttext
\startformula
 \unit{1.23e5 kg m^2/s^2} + \unit{8.64e5 W s} = \unit{9.87e5 newton m}
\stopformula
\startformula
 1.23\mathord\times10^5\,{\rm kg\mathord\cdot m^2/s^2} + 
8.64\mathord\times10^5\,{\rm W\mathord{\cdot}s} = 9.87\mathord\times10^5\,{\rm 
N\mathord{\cdot}m}
\stopformula
\stoptext

I’m trying to fix four issues:
  - No space between the number and the following units. Should be a thin space.
  - No space between the units and the following symbol (+ and = above). Should 
be appropriate “bin" or “rel" space.
  - Too much space around the \cdot in the units. Should be treated like an 
“ord" when used to separate units.
  - Too much space around the \times in the scientific notation. Should be 
treated like an "ord" when used in scientific notation. (I'm not sure there is 
consensus on this.)

Some of these seemed like things I could fix myself, so I dug into 
phys-dim.mkxl to see what I could do. The good news is that I didn’t break 
anything. The bad news is that nothing I did seemed to have any effect – 
including deleting phys-dim.mkxl entirely! I double checked that I was working 
on the same installation used for typesetting. Is the code used for \unit now 
somewhere else?

These issues only occur in math mode, and \unit handles comma separators 
correctly, unlike \digit.

I’d like to get some sort of temporary patch for at least some of these issues, 
even if I need to write it myself. I use \unit everywhere in physics problems 
sets for students and in keys that I share other teachers.

Any guidance is appreciated!

Gavin

P.S. I’m working on a more comprehensive test file, but its not ready yet.
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

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


Re: [NTG-context] Spacing in \unit

2022-09-25 Thread Bruce Horrocks via ntg-context


> On 25 Sep 2022, at 14:30, Gavin via ntg-context  wrote:
> 
> Hello list,
> 
> I have a few questions about space produced by the unit command. Consider 
> this MWE
> 
> \starttext
> \unit{3.00e8 kg m/s}
> 
> $\unit{3.00e8 kg m/s}$
> \stoptext
> 
> The dot between “kg” and “m” has different spacing depending on whether the 
> \unit command is in text or math mode. I think that the tighter spacing in 
> the first one, in text, is correct.
> 
> I personally would also like less space around the \times. To me, the number 
> 3.00e8 should be typeset more like a single number, rather than like a 
> product of 3.00 and 10^8. I am probably in the minority here. If \unit and 
> \digit had an option for tighter spacing around the \times, I’d use it, but 
> the current output with more space is probably what most people expect and 
> want. Perhaps something like [scispace=tight].

I too would prefer less space around the times e.g. \starttext 3.00×10\high{8} 
\stoptext is fine (except for the 8 which is nicer in \unit).

—
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://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___


Re: [NTG-context] Spacing in \unit

2022-09-25 Thread Hans Hagen via ntg-context

On 9/25/2022 5:29 PM, Gavin via ntg-context wrote:

Hi Hans,

I also just noticed that the space between the number and the unit is missing 
when I typeset with ConTeXt ver: 2022.09.11 20:44 LMTX fmt: 2022.9.25. This 
space was present in with the ConTeXt version I was using earlier, from a 
couple months ago. Thanks for putting it on the math todo list!
i can probably clean up the code a bit in lmtx ... units are not that 
(rapidly) evolving and much is rather old code so best collect all 
issues and make a test file that mikael and i can use (as wer then do 
math and text at the same time)


maybe we also need to add units (are there new ones anyway?)

Hans

-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
   tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

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


Re: [NTG-context] Spacing in \unit

2022-09-25 Thread Gavin via ntg-context
Hi Hans,

I also just noticed that the space between the number and the unit is missing 
when I typeset with ConTeXt ver: 2022.09.11 20:44 LMTX fmt: 2022.9.25. This 
space was present in with the ConTeXt version I was using earlier, from a 
couple months ago. Thanks for putting it on the math todo list!

Gavin

(I sent the above message to Hans, but failed to cc the mailing list. Sorry if 
some of you get this twice.)

> On Sep 25, 2022, at 9:19 AM, Hans Hagen  wrote:
> 
> On 9/25/2022 3:30 PM, Gavin via ntg-context wrote:
>> Hello list,
>> I have a few questions about space produced by the unit command. Consider 
>> this MWE
>> \starttext
>> \unit{3.00e8 kg m/s}
>> $\unit{3.00e8 kg m/s}$
>> \stoptext
>> The dot between “kg” and “m” has different spacing depending on whether the 
>> \unit command is in text or math mode. I think that the tighter spacing in 
>> the first one, in text, is correct.
>> I personally would also like less space around the \times. To me, the number 
>> 3.00e8 should be typeset more like a single number, rather than like a 
>> product of 3.00 and 10^8. I am probably in the minority here. If \unit and 
>> \digit had an option for tighter spacing around the \times, I’d use it, but 
>> the current output with more space is probably what most people expect and 
>> want. Perhaps something like [scispace=tight].
> 
> that's for the math todo
> 
>> Finally, \unit does not play nicely with surrounding spaces. For example:
>> $2\pi\,\unit{3.00e8 kg m/s}$
>> causes a fatal error:
>> tex error   > tex error on line 9 in file ./Untitled.tex: Incompatible 
>> glue units (case 1)
> that's an interesting case for the engine (Mixing regular and mu skips and 
> so) ... we mighth finaly have a valid case for a primitive zero test
> 
> Hans
> 
> -
>  Hans Hagen | PRAGMA ADE
>  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
>   tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
> -

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

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


Re: [NTG-context] Spacing in \unit

2022-09-25 Thread Hans Hagen via ntg-context

On 9/25/2022 3:30 PM, Gavin via ntg-context wrote:

Hello list,

I have a few questions about space produced by the unit command. Consider this 
MWE

\starttext
\unit{3.00e8 kg m/s}

$\unit{3.00e8 kg m/s}$
\stoptext

The dot between “kg” and “m” has different spacing depending on whether the 
\unit command is in text or math mode. I think that the tighter spacing in the 
first one, in text, is correct.

I personally would also like less space around the \times. To me, the number 
3.00e8 should be typeset more like a single number, rather than like a product 
of 3.00 and 10^8. I am probably in the minority here. If \unit and \digit had 
an option for tighter spacing around the \times, I’d use it, but the current 
output with more space is probably what most people expect and want. Perhaps 
something like [scispace=tight].


that's for the math todo


Finally, \unit does not play nicely with surrounding spaces. For example:

 $2\pi\,\unit{3.00e8 kg m/s}$

causes a fatal error:

tex error   > tex error on line 9 in file ./Untitled.tex: Incompatible glue 
units (case 1)
that's an interesting case for the engine (Mixing regular and mu skips 
and so) ... we mighth finaly have a valid case for a primitive zero test


Hans

-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
   tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

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


[NTG-context] Spacing in \unit

2022-09-25 Thread Gavin via ntg-context
Hello list,

I have a few questions about space produced by the unit command. Consider this 
MWE

\starttext
\unit{3.00e8 kg m/s}

$\unit{3.00e8 kg m/s}$
\stoptext

The dot between “kg” and “m” has different spacing depending on whether the 
\unit command is in text or math mode. I think that the tighter spacing in the 
first one, in text, is correct.

I personally would also like less space around the \times. To me, the number 
3.00e8 should be typeset more like a single number, rather than like a product 
of 3.00 and 10^8. I am probably in the minority here. If \unit and \digit had 
an option for tighter spacing around the \times, I’d use it, but the current 
output with more space is probably what most people expect and want. Perhaps 
something like [scispace=tight].

Finally, \unit does not play nicely with surrounding spaces. For example:

$2\pi\,\unit{3.00e8 kg m/s}$

causes a fatal error:

tex error   > tex error on line 9 in file ./Untitled.tex: Incompatible glue 
units (case 1)

 \phys_units_direct 
#1->\begingroup \the \everyunits \ifdim \lastskip 
>\zeropoint \settrue \c_phys_units_dospace \removelastskip \fi 
\c_phys_digits_method \unitparameter \c!method \relax \ifmmode \else 
\dontleavehmode \fi \edef \currentunit {#1}\always\edef \unitlanguag
 
$2\pi\,\unit
{3.00e8 kg m/s}$

Using \thinspace produces the same fatal error.

Putting the 2\pi after the \unit{…} can also cause surprises.

$\unit{3.00e8 kg m/s}\times 2\pi$

produces a \times that is right up against the “s”.

I am very happy with all of the work done on spacing in math. I hope that my 
observations above are helpful in fine-tuning the excellent system.

Thanks!
Gavin

P.S. I am on as M1 Mac, using ConTeXt  ver: 2022.09.11 20:44 LMTX  fmt: 
2022.9.25  int: english/english.
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

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