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

number formatting of inline stem expression: https://github.com/metan… #933

Merged
merged 1 commit into from
Sep 25, 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
22 changes: 15 additions & 7 deletions lib/metanorma/standoc/inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,29 @@ def latex_parse1(text, block)
end

def stem_parse(text, xml, style, node)
attr = stem_attrs(node)
attrs, text = stem_attrs(node, text)
if /<([^:>&]+:)?math(\s+[^>&]+)?> |
<([^:>&]+:)?math(\s+[^>&]+)?>/x.match? text
xml.stem **attr.merge(type: "MathML") do |s|
xml.stem **attrs.merge(type: "MathML") do |s|
s << xml_encode(text)
end
elsif style == :latexmath then latex_parse(text, xml, attr)
elsif style == :latexmath then latex_parse(text, xml, attrs)
else
xml.stem text&.gsub("&amp;#", "&#"), **attr.merge(type: "AsciiMath")
xml.stem text&.gsub("&amp;#", "&#"), **attrs.merge(type: "AsciiMath")
end
end

def stem_attrs(node)
n = node.attr("number-format")
{ block: node.block?, "number-format": n }.compact
STEM_ATTRS = "number-format".freeze

def stem_attrs(node, text)
attrs = STEM_ATTRS.split("|").each_with_object({}) do |k, m|
n = node.attr(k) and m[k.to_sym] = n
end
while m = /^(#{STEM_ATTRS})(=[^%]+)?%(.*)$/o.match(text)
text = m[3]
attrs[m[1].to_sym] = m[2]&.sub(/^=/, "")
end
[{ block: node.block? }.merge(attrs), text]
end

def latex_parse(text, xml, attr)
Expand Down
14 changes: 14 additions & 0 deletions spec/metanorma/cleanup_math_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@
++++
3 + x
++++

stem:[number-format="notation=basic,exponent_sign=&#x25;,precision=4"% 1 xx 3]
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
Expand Down Expand Up @@ -203,6 +205,18 @@
<asciimath>3 + x</asciimath>
</stem>
</formula>
<p id="_">
<stem block="false" type="MathML">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mstyle displaystyle="false">
<mn data-metanorma-numberformat="notation='basic,exponent_sign=%,precision=4'">1</mn>
<mo>×</mo>
<mn data-metanorma-numberformat="notation='basic,exponent_sign=%,precision=4'">3</mn>
</mstyle>
</math>
<asciimath> 1 xx 3</asciimath>
</stem>
</p>
</sections>
</standard-document>
OUTPUT
Expand Down
Loading