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.
On Sat, 8 Oct 2022 11:59:04 -0600
Gavin via ntg-context
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
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
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 ___________________________________________________________________________________
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
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
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
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
On Wed, 12 Oct 2022 21:14:52 -0600
Gavin
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
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. 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}
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 ___________________________________________________________________________________
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
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
On 10/13/2022 1:52 PM, Gavin via ntg-context wrote: 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 -----------------------------------------------------------------
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
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
Hi List, I am trying to improve the spacing produced by the \unit command. I have solved three of my four issues by modifying phys-dim.mkxl, but the fourth issue has me stumped. Consider this example: \showmakeup[mathglue] \mathspacingmode=1 \starttext \startformula \unit{1.23e5 kg m^2/s^2} + \unit{8.64e5 newton m} = \unit{987,000 joule} \stopformula \stoptext There is no space between the units and the following + or =. The \showmakeup reveals that this is the space between a “dim” and a “bin” or a “dim” and a “rel”. I am guessing that “dim” refers to a new “dimension” atom class, and it appears that the table determining the spacing between atoms does not include space between this dimension class and the binary or relation classes. I don’t know that this is the problem, but this is my best guess. If this is the problem, is there a way I can add this space to the necessary table? If this is not the problem, I’m open to any other insight or advice. Thanks, Gavin
On Oct 8, 2022, at 11:59 AM, Gavin
wrote: 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.
participants (6)
-
Alan Braslau
-
Gavin
-
Hans Hagen
-
Max Chernoff
-
Oliver Sieber
-
Rik Kabel