dimensional icon indicating copy to clipboard operation
dimensional copied to clipboard

`showIn degree` should not have space before unit

Open bjornbm opened this issue 7 years ago • 6 comments

showIn degree (2 *~ degree) == "2 °". It should be "2°". From https://physics.nist.gov/cuu/pdf/sp811.pdf:

7.2 Space between numerical value and unit symbol

In the expression for the value of a quantity, the unit symbol is placed after the numerical value and a space is left between the numerical value and the unit symbol.

The only exceptions to this rule are for the unit symbols for degree, minute, and second for plane angle: °, ', and ", respectively (see Table 6), in which case no space is left between the numerical value and the unit symbol.

Example: α = 30°22'8"

Note: α is a quantity symbol for plane angle.

Also applies to minutes (') and seconds (") of arc, but not °C.

bjornbm avatar Jun 02 '18 09:06 bjornbm

I will tackle this as part of my work on PresentationQuantity d a as an intermediate stop between Quantity d a and string/text/HTML/LaTeX.

On Jun 2, 2018 5:45 AM, "Björn Buckwalter" [email protected] wrote:

showIn degree (2 *~ degree) == "2 °". It should be "2°". From https://physics.nist.gov/cuu/pdf/sp811.pdf:

7.2 Space between numerical value and unit symbol

In the expression for the value of a quantity, the unit symbol is placed after the numerical value and a space is left between the numerical value and the unit symbol.

The only exceptions to this rule are for the unit symbols for degree, minute, and second for plane angle: °, ', and ", respectively (see Table 6), in which case no space is left between the numerical value and the unit symbol.

Example: α = 30°22'8"

Note: α is a quantity symbol for plane angle.

Also applies to minutes (') and seconds (") of arc, but not °C.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bjornbm/dimensional/issues/189, or mute the thread https://github.com/notifications/unsubscribe-auth/AAk005iArvvyVgik6kfL7AmhsmfbCdhHks5t4l6mgaJpZM4UXoCG .

dmcclean avatar Jun 02 '18 19:06 dmcclean

Open questions about this: What is the spacing when the unit is degree / second? Should it really be no space at all? Or some sort of zero-width space character? The α = 30°22'8" example should be separated with non-breaking spaces between chunks, right? As at https://en.wikipedia.org/wiki/Degree_symbol#Typography?

dmcclean avatar Jun 03 '18 02:06 dmcclean

Good questions. “2°/s” always looked a bit iffy to me, but couldn't say if it is “wrong”. I might write “2° s^-1”.

I would have written “30°22'8"” which is consistent with the NIST guide example (although I don't see that they spell out that there should be no spaces), as opposed to “30° 22' 8"” suggested by Wikipedia.

bjornbm avatar Jun 03 '18 09:06 bjornbm

So I think on the basis of those answers that perhaps NameAtoms come with a field that specifies whether they, when appearing in some sort of distinguished lead position within a composite UnitName, have the normal spacing behavior or this special spacing behavior?

The definition of that lead position is slightly complicated but should be reasonable to determine.

Again weird composite units rear their heads. 3.0 *~ (degree^pos2) and 3.0 *~ (degree * degree) are both such strange things (in the sense that they shouldn't exist in the wild) that I can't imagine what the "correct" spacing behavior for them is.

dmcclean avatar Dec 19 '18 19:12 dmcclean

A little complex but maybe necessary.

By the way, do you intend to provide the user with controls in the pretty printing functions for, for example, specifying if spaces or multiplication operators should be put between atomic units, symbols, etc? Here are some variations that, to my knowledge, are all “valid”:

1 km/s
1 km / s
1 kms^-1
1 km s^-1
1 km s^−1   -- "minus sign" (U+2212) rather than hyphen.
1 km·s^-1   -- dot
1 km · s⁻¹  -- superscript
1 km × s⁻¹  -- multiplication sign
1 kms⁻¹

Not a feature request from me; just wondering what your thoughts/intents on the matter are?

bjornbm avatar Dec 19 '18 20:12 bjornbm

My intent is to do it in several phases.

PresentationNumber will be a type that describes the abstract syntax of a number exactly as it will be printed / was parsed, with options for rationals, decimals, powers of 10, powers of pi. Possibly powers of 2.

data PresentationUnit d = SimpleUnit (Unit 'NonMetric d ExactPi)
                        | PrefixedUnit PrefixSet (Unit 'Metric d ExactPi)

PresentationNumberFormat will describe a way to get from Floating or ExactPi to a PresentationNumber (things like rounding options, preferences on exponential notation).

PresentationFormat d will be a PresentationNumberFormat and a PresentationUnit d.

data PresentationQuantity d = Simple PresentationNumber (Unit 'NonMetric d ExactPi)
                            | Composite Integer (Unit 'NonMetric d ExactPi) (PresentationQuantity d)

So that a PresentationFormat d describes a path from Quantity d a -> PresentationQuantity d. Then conversion from PresentationQuantity d to String (or some HTML or LaTeX type) would be where options of the type you describe come in.

Except to note that our grammar of unit names groups them as follows:

1 km/s
1 km / s

and

1 kms^-1
1 km s^-1
1 km s^−1   -- "minus sign" (U+2212) rather than hyphen.
1 km·s^-1   -- dot
1 km · s⁻¹  -- superscript
1 km × s⁻¹  -- multiplication sign
1 kms⁻¹

dmcclean avatar Dec 19 '18 22:12 dmcclean