Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

formula number formatting: https://github.com/metanorma/metanorma/iss… #814

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions author/ref/document-attributes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ Read more about
link:/author/topics/blocks/math/[mathematical expressions].

`:number-presentation:`::
Sets the formatting options for the `number:[]` command in the document.
Sets the formatting options for the `number:[]` command in the document [added in https://github.com/metanorma/metanorma-standoc/releases/tag/v2.8.12]. Please refer to the dedicated section at
link:/author/topics/inline_markup/semantic-elements#numbers[numbers] for usage.
+
.Using the `:number-presentation:` attribute
[example]
Expand All @@ -101,14 +102,13 @@ Sets the formatting options for the `number:[]` command in the document.
number:341[]
----
====
+
Please refer to the dedicated section at
link:/author/topics/inline_markup/semantic-elements#numbers[numbers].


`:number-presentation-profile-{NAME}:`::
Sets the formatting options for the `number:[]` command in the document
as profile `{NAME}`.
as profile `{NAME}` [added in https://github.com/metanorma/metanorma-standoc/releases/tag/v2.8.12].
Please refer to the dedicated section at
link:/author/topics/inline_markup/semantic-elements#numbers[numbers] for usage.
+
.Using the `:number-presentation-profile-{NAME}:` attribute
[example]
Expand All @@ -121,11 +121,13 @@ as profile `{NAME}`.
number:342[profile=3]
----
====
+
Please refer to the dedicated section at
link:/author/topics/inline_markup/semantic-elements#numbers[numbers].


`:number-presentation-formula:`::
Sets the formatting options for numbers contained in formulas [added in https://github.com/metanorma/metanorma-standoc/releases/tag/2.9.6].
Please refer to the dedicated section at
link:/author/topics/inline_markup/semantic-elements#formula-numbers[numbers in formulas].

== Languages and localization

See also the link:/author/topics/languages[Languages] topic.
Expand Down
133 changes: 130 additions & 3 deletions author/topics/inline_markup/semantic-elements.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,132 @@ and it removes `exponent_sign`, resulting in

=== Encoding numbers as formulas

Numbers can be encoded in the `stem` blocks, and are formatted identically
as those using the `number` command.
Numbers can be formatted within `stem` blocks.

By default, numbers in `stem` blocks are not formatted at all: number formatting
is reserved for the `number` macro.

[example]
If a formula contains the string _1221_, it will usually not be formatted into
_1,221_, but left alone.

In order to make a block formula format its numbers, use the argument
`number-format` on `[stem]`: it has the same format as the foregoing number formatting
expressions.

.Using the `number-format` argument on a `stem` block
[example]
====
[source,adoc]
----
[stem]
++++
1 + x
++++

[stem,number-format="precision=2"]
++++
1 + x
++++
----

renders as:

____

1 + x

1.00 + x
____
====


Default numeric processing is applied to a formula by specifying
`number-format=default`.

.Using the `number-format` argument with `default` on a `stem` block
[example]
====
[source,adoc]
----
[stem,number-format="default"]
++++
1221 + x
++++
----

in an English-language document applies default English locale formatting on the
formula's number, to render as:

____

1,221 + x
____
====


Number formatting profiles can also be used on formulas.

.Using a number formatting profile on a `stem` block
[example]
====
[source,adoc]
----
:number-presentation-profile-foo: notation=scientific,exponent_sign=nil,decimal=","

[stem,number-format="profile=foo"]
++++
1221 + x
++++
----
====

It is possible to specify that by default, all formulas have their numbers
formatted, through the `number-presentation-formula` document attribute.

The document attribute can take the value `number-presentation`, in which case
it has the same value as the `:number-presentation:` document attribute; or
`default`, in which case default number formatting is applied
(`notation='basic'`).

Syntax:

[source,adoc]
----
:number-presentation-formula: {OPTIONS}
----


If `number-presentation-formula` is set, a formula can ignore number formatting
by setting `number-format: nil`.

.Using the `number-presentation-formula` document attribute
[example]
====
[source,adoc]
----
:number-presentation-formula: notation=scientific

[stem]
++++
1221 + x
++++

[stem,number-format=nil]
++++
1221 + x
++++
----

renders as:

____
1.221e3 + x

1221 + x
____
====


The `number` command however provides granular configuration options, and
is the recommended method for encoding numbers for consistency reasons.
Expand All @@ -533,8 +657,11 @@ There are stem:[30000.54] people in attendance.
----
====

NOTE: Inline stem macros (`stem:[]`) do not support attributes, so specifying
number formatting on inline stem macros is no currently supported, other than
through the universal application of `:number-presentation-formula:`.

NOTE: The number in the `\stem:[]` expression must be specified according to the
NOTE: The number in the `\stem:[]` or `number:[]` expression must be specified according to the
en-US locale; `30000.54` is recognised as a decimal number, `30 000,54` is not.
However, if the document is in French, `stem:[30000.54]` will in fact be
rendered consistent with French practice, as _30 000,54_.
Loading