Skip to content

Commit

Permalink
Merge pull request #600 from metanorma/fix/stem-mn-formatting
Browse files Browse the repository at this point in the history
do not by default format numbers within formulae: https://github.com/…
  • Loading branch information
opoudjis authored Sep 6, 2024
2 parents 6ccbaf9 + dee7be3 commit 9670a63
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/isodoc/presentation_function/math.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def normalise_number(num)
end

def implicit_number_formatter(num, locale)
num.ancestors("formula").empty? or return
## by default, no formatting in formulas
fmt = { significant: num_totaldigits(num.text) }.compact
n = normalise_number(num.text)
@numfmt.localized_number(n, locale:, format: fmt,
Expand Down
113 changes: 113 additions & 0 deletions spec/isodoc/presentation_xml_maths_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,119 @@
.sub(%r{<localized-strings>.*</localized-strings>}m, "")))
.to be_equivalent_to Xml::C14n.format(output1)
end

it "with numbers within formulas" do
allow_any_instance_of(IsoDoc::PresentationXMLConvert)
.to(receive(:twitter_cldr_localiser_symbols)
.and_return({
fraction_group_digits: 2,
fraction_group: "'",
precision: 2,
}))

input = <<~INPUT
<standard-document xmlns="http://riboseinc.com/isoxml">
<bibdata>
<title language="en">test</title>
</bibdata>
<sections>
<formula id="_">
<stem block="true" type="MathML">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mstyle displaystyle="true">
<mn>1</mn>
<mo>+</mo>
<mi>x</mi>
</mstyle>
</math>
<asciimath>1 + x</asciimath>
</stem>
</formula>
<formula id="_">
<stem block="true" type="MathML">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mstyle displaystyle="true">
<mn data-metanorma-numberformat="notation='basic',exponent_sign='plus',precision='4'">2</mn>
<mo>+</mo>
<mi>x</mi>
</mstyle>
</math>
<asciimath>2 + x</asciimath>
</stem>
</formula>
<formula id="_">
<stem block="true" type="MathML">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mstyle displaystyle="true">
<mn data-metanorma-numberformat="notation='basic'">3</mn>
<mo>+</mo>
<mi>x</mi>
</mstyle>
</math>
<asciimath>3 + x</asciimath>
</stem>
</formula>
</sections>
</standard-document>
INPUT
output = <<~OUTPUT
<standard-document xmlns="http://riboseinc.com/isoxml" type="presentation">
<bibdata>
<title language="en">test</title>
</bibdata>
<preface>
<clause type="toc" id="_" displayorder="1">
<title depth="1">Table of contents</title>
</clause>
</preface>
<sections>
<p class="zzSTDTitle1">test</p>
<formula id="_">
<stem block="true" type="MathML">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mstyle displaystyle="true">
<mn>1</mn>
<mo>+</mo>
<mi>x</mi>
</mstyle>
</math>
<asciimath>1 + x</asciimath>
</stem>
</formula>
<formula id="_">
<stem block="true" type="MathML">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mstyle displaystyle="true">
<mn>2.00'00</mn>
<mo>+</mo>
<mi>x</mi>
</mstyle>
</math>
<asciimath>2 + x</asciimath>
</stem>
</formula>
<formula id="_">
<stem block="true" type="MathML">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mstyle displaystyle="true">
<mn>3.00</mn>
<mo>+</mo>
<mi>x</mi>
</mstyle>
</math>
<asciimath>3 + x</asciimath>
</stem>
</formula>
</sections>
</standard-document>
OUTPUT
expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert
.new({ localizenumber: "#=#0;##$#" }
.merge(presxml_options))
.convert("test", input, true))
.sub(%r{<localized-strings>.*</localized-strings>}m, "")))
.to be_equivalent_to Xml::C14n.format(output)
end
end

it "propagates boldface into MathML" do
Expand Down

0 comments on commit 9670a63

Please sign in to comment.