asciimath / asciimathml

A new home for asciimathml
http://asciimath.org/
MIT License
958 stars 184 forks source link

Support physical units #129

Open suruena opened 3 years ago

suruena commented 3 years ago

Currently, it's cumbersome to write physical units with AsciiMath, for example: 42\ "N" = 42\ "kg"*"m"//"s"^2

Note that \ (escaping the space) is needed to ensure an space is inserted between the number and the unit, double quotes to ensure the unit symbol is not in italics, and // to have the usual division style. Furthermore, it's not possible to use double quotes when the unit symbol contains a Greek character (such as microsecods), so as far as I know it's not possible to show those units symbols with the correct typography.

It would be very nice if AsciiMath provided some specific syntax for correctly representing physical units easily, maybe when surrounded by apostrophes or something similar:

42 'N'= 42 'kg*m/s^2'

Ideally, having a simplified syntax for units would make this feature even more readable (e.g see UCUM for a plain text syntax designed for physical units), as anyway it has no sense to write any AsciiMath expression inside this units environment:

42 'N'= 42 'kg m/s2'

In both cases, this would make AsciiMath even more attractive for engineers, thank you very much.

Tronic commented 1 year ago

Suggesting something even simpler, e.g.

g = 9.81.m/s^2

Noting that dot directly following a number has no useful meaning (prints currently simply as a dot). Using some character other than dot could be safer, if it needs to be a strictly nonbreaking change. Either way, quotes at both ends of the unit are still quite ugly.

Units formatting also should add a narrow non-breaking space between the number and its unit where I believe \, is normally used in LaTeX for this.

Sometimes units need to be printed without a number so that is also a concern. Technically the dot prefix could also work for this:

[a] = .m/s^2

One concern is when to break out of unit mode, and in that regard the surrounding quotes are simpler. Otherwise spaces, parenthesis and division could either be part of the unit expression or a continuation of the equation (after which letters should appear as variables again).

aslakr commented 1 year ago

There is an old note from 2003 on how to use units in MathML https://www.w3.org/TR/mathml-units/ with a short segment on presentation MathML.

<math xmlns="http://www.w3.org/1998/Math/MathML">
<mstyle>
<mn>42</mn>
<mo rspace="thickmathspace">&InvisibleTimes;</mo>
<mi mathvariant="normal" class="MathML-Unit">N</mi>
<mo>=</mo>
<mn>42</mn>
<mo rspace="thickmathspace">&InvisibleTimes;</mo>
<mi mathvariant="normal" class="MathML-Unit">kg</mi>
<mo>&middot;</mo>
<mfrac>
<mi mathvariant="normal" class="MathML-Unit">m</mi>
<msup>
<mi mathvariant="normal" class="MathML-Unit">s</mi>
<mn>2</mn>
</msup>
</mfrac>
</mstyle>
</math>

One could maybe write the si units in full

42*newton = 42*kilogram*metre/second^2

a bit similar to https://ctan.org/pkg/siunitx?