[NTG-context] Spacing in \unit - SOLVED

Gavin gavinpublic at comcast.net
Fri Oct 21 20:20:42 CEST 2022


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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: units-spacing.tex
Type: application/octet-stream
Size: 279 bytes
Desc: not available
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20221021/863c7c70/attachment-0003.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: units-linebreaks.tex
Type: application/octet-stream
Size: 166 bytes
Desc: not available
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20221021/863c7c70/attachment-0004.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: phys-dim.mkxl
Type: application/octet-stream
Size: 30279 bytes
Desc: not available
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20221021/863c7c70/attachment-0005.obj>
-------------- next part --------------




More information about the ntg-context mailing list