asciimath 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +26 -0
- data/CHANGELOG.adoc +12 -0
- data/README.adoc +2 -1
- data/dump_symbol_table.rb +1 -1
- data/lib/asciimath/html.rb +1 -1
- data/lib/asciimath/latex.rb +1 -2
- data/lib/asciimath/markup.rb +26 -4
- data/lib/asciimath/mathml.rb +24 -8
- data/lib/asciimath/parser.rb +6 -2
- data/lib/asciimath/version.rb +1 -1
- data/spec/parser_spec.rb +20 -5
- metadata +4 -5
- data/.travis.yml +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b287c84a0345545fe98b4fc8cb6e229db81256175fe3493267691cf870521b3
|
4
|
+
data.tar.gz: fffc143e77dbb1a5a0ba364b702ee08caaf8fe9077cd5b9694ba9ff273132937
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a691bf5414b2887f98052774c525e604fc3e74ed8fc51a1bec2a6beb3c2dbbf8a1aecc4161a9bd6a8e85bca9f34e307f2043df1bb819a5b8ff9c206adb2e4aa6
|
7
|
+
data.tar.gz: f83a4a4ce3340807aa2a1f0e47056bc1438a2504862538935eed6ef0010a9f2da01004e95b0c5f132c23190b01b0ad07f3e238859ecd00d5e3166741665537d4
|
@@ -0,0 +1,26 @@
|
|
1
|
+
name: CI
|
2
|
+
on: [push, pull_request]
|
3
|
+
jobs:
|
4
|
+
test:
|
5
|
+
strategy:
|
6
|
+
matrix:
|
7
|
+
ruby: [jruby, 2.3, 2.4, 2.5, 2.6, 2.7]
|
8
|
+
os: [ubuntu-latest, macos-latest, windows-latest]
|
9
|
+
runs-on: ${{ matrix.os }}
|
10
|
+
steps:
|
11
|
+
- name: Checkout
|
12
|
+
uses: actions/checkout@v2
|
13
|
+
- name: Set up Ruby
|
14
|
+
uses: ruby/setup-ruby@v1
|
15
|
+
with:
|
16
|
+
ruby-version: ${{ matrix.ruby }}
|
17
|
+
- name: Reinstall Bundler
|
18
|
+
if: matrix.os == 'windows-latest' && matrix.ruby == 'jruby'
|
19
|
+
# Temporary workaround for https://github.com/ruby/setup-ruby/issues/129
|
20
|
+
run: |
|
21
|
+
gem uninstall -x bundler
|
22
|
+
gem install -N bundler -v 2.1.4
|
23
|
+
- name: Build
|
24
|
+
run: bundle install --jobs 4 --retry 3
|
25
|
+
- name: Test
|
26
|
+
run: bundle exec rake test
|
data/CHANGELOG.adoc
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
= Asciimath Changelog
|
2
2
|
|
3
|
+
== 2.0.2
|
4
|
+
|
5
|
+
Enhancements::
|
6
|
+
|
7
|
+
* Issue #51: generate `accent` and `accentunder` attributes on `munder`, `mover`, and `munderover` tags when appropriate
|
8
|
+
* Issue #52: map `phi` to U+03D5 and `varphi` to U+03C6 by default.
|
9
|
+
* Issue #53: Add support for Roman style font command `rm`.
|
10
|
+
|
11
|
+
Bug fixes::
|
12
|
+
|
13
|
+
* Issue #50: fix parsing error when unary and binary operators are missing an operand
|
14
|
+
|
3
15
|
== 2.0.1
|
4
16
|
|
5
17
|
Enhancements::
|
data/README.adoc
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# AsciiMath
|
2
|
+
:uri-project: https://github.com/asciidoctor/asciimath
|
2
3
|
ifndef::env-site[:status:]
|
3
4
|
|
4
5
|
An http://asciimath.org[AsciiMath] parser and MathML/LaTeX generator written in pure Ruby.
|
@@ -7,7 +8,7 @@ ifdef::status[]
|
|
7
8
|
[discrete]
|
8
9
|
## Status
|
9
10
|
|
10
|
-
image:
|
11
|
+
image:{uri-project}/workflows/CI/badge.svg?branch=master["Build Status", link={uri-project}/actions?query=branch%3Amaster]
|
11
12
|
image:https://img.shields.io/gem/v/asciimath.svg?label=gem%20version[Gem Version, link=https://rubygems.org/gems/asciimath]
|
12
13
|
endif::status[]
|
13
14
|
|
data/dump_symbol_table.rb
CHANGED
@@ -21,7 +21,7 @@ AsciiMath::Parser::DEFAULT_PARSER_SYMBOL_TABLE.each_pair do |asciimath, value|
|
|
21
21
|
next
|
22
22
|
end
|
23
23
|
|
24
|
-
mathml = AsciiMath::MathMLBuilder
|
24
|
+
mathml = AsciiMath::MathMLBuilder.default_display_symbol_table[sym]
|
25
25
|
|
26
26
|
if mathml
|
27
27
|
val = mathml[:value]
|
data/lib/asciimath/html.rb
CHANGED
@@ -4,7 +4,7 @@ module AsciiMath
|
|
4
4
|
class HTMLBuilder < ::AsciiMath::MarkupBuilder
|
5
5
|
|
6
6
|
def initialize(opts = {})
|
7
|
-
super(opts[:symbol_table] ||
|
7
|
+
super(opts[:symbol_table] || ::AsciiMath::MarkupBuilder.default_display_symbol_table(fix_phi: opts.fetch(:fix_phi, true)))
|
8
8
|
@prefix = opts[:prefifx] || ''
|
9
9
|
@inline = opts[:inline]
|
10
10
|
@html = ''
|
data/lib/asciimath/latex.rb
CHANGED
@@ -96,6 +96,7 @@ module AsciiMath
|
|
96
96
|
:bold_sans_serif => "\\mathsf",
|
97
97
|
:sans_serif_italic => "\\mathsf",
|
98
98
|
:sans_serif_bold_italic => "\\mathsf",
|
99
|
+
:roman => "\\mathrm",
|
99
100
|
}.freeze
|
100
101
|
|
101
102
|
private
|
@@ -244,8 +245,6 @@ module AsciiMath
|
|
244
245
|
end
|
245
246
|
|
246
247
|
when AsciiMath::AST::Matrix
|
247
|
-
len = expression.length - 1
|
248
|
-
|
249
248
|
parens(expression.lparen, expression.rparen) do
|
250
249
|
c = expression.length
|
251
250
|
@latex << "\\begin{matrix} "
|
data/lib/asciimath/markup.rb
CHANGED
@@ -4,7 +4,7 @@ require_relative 'symbol_table'
|
|
4
4
|
module AsciiMath
|
5
5
|
class MarkupBuilder
|
6
6
|
# Operation symbols
|
7
|
-
def self.add_default_display_symbols(b)
|
7
|
+
def self.add_default_display_symbols(b, fix_phi: true)
|
8
8
|
b.add(:plus, '+', :operator)
|
9
9
|
b.add(:minus, "\u2212", :operator)
|
10
10
|
b.add(:cdot, "\u22C5", :operator)
|
@@ -221,6 +221,7 @@ module AsciiMath
|
|
221
221
|
b.add(:bold_sans_serif, :bold_sans_serif, :font)
|
222
222
|
b.add(:sans_serif_italic, :sans_serif_italic, :font)
|
223
223
|
b.add(:sans_serif_bold_italic, :sans_serif_bold_italic, :font)
|
224
|
+
b.add(:roman, :normal, :font)
|
224
225
|
|
225
226
|
# Greek letters
|
226
227
|
b.add(:alpha, "\u03b1", :identifier)
|
@@ -265,9 +266,14 @@ module AsciiMath
|
|
265
266
|
b.add(:Tau, "\u03a4", :identifier)
|
266
267
|
b.add(:upsilon, "\u03c5", :identifier)
|
267
268
|
b.add(:Upsilon, "\u03a5", :identifier)
|
268
|
-
|
269
|
+
if fix_phi
|
270
|
+
b.add(:phi, "\u03d5", :identifier)
|
271
|
+
b.add(:varphi, "\u03c6", :identifier)
|
272
|
+
else
|
273
|
+
b.add(:phi, "\u03c6", :identifier)
|
274
|
+
b.add(:varphi, "\u03d5", :identifier)
|
275
|
+
end
|
269
276
|
b.add(:Phi, "\u03a6", :identifier)
|
270
|
-
b.add(:varphi, "\u03d5", :identifier)
|
271
277
|
b.add(:chi, "\u03c7", :identifier)
|
272
278
|
b.add(:Chi, "\u03a7", :identifier)
|
273
279
|
b.add(:psi, "\u03c8", :identifier)
|
@@ -278,7 +284,18 @@ module AsciiMath
|
|
278
284
|
b
|
279
285
|
end
|
280
286
|
|
281
|
-
|
287
|
+
private
|
288
|
+
DEFAULT_SYMBOL_TABLE = ::AsciiMath::MarkupBuilder.add_default_display_symbols(AsciiMath::SymbolTableBuilder.new, fix_phi: false).build
|
289
|
+
DEFAULT_SYMBOL_TABLE_FIX_PHI = ::AsciiMath::MarkupBuilder.add_default_display_symbols(AsciiMath::SymbolTableBuilder.new, fix_phi: true).build
|
290
|
+
|
291
|
+
public
|
292
|
+
def self.default_display_symbol_table(fix_phi: true)
|
293
|
+
if fix_phi
|
294
|
+
DEFAULT_SYMBOL_TABLE_FIX_PHI
|
295
|
+
else
|
296
|
+
DEFAULT_SYMBOL_TABLE
|
297
|
+
end
|
298
|
+
end
|
282
299
|
|
283
300
|
def initialize(symbol_table)
|
284
301
|
@symbol_table = symbol_table
|
@@ -475,5 +492,10 @@ module AsciiMath
|
|
475
492
|
nil
|
476
493
|
end
|
477
494
|
end
|
495
|
+
|
496
|
+
def is_accent(node)
|
497
|
+
resolved = resolve_symbol(node)
|
498
|
+
!resolved.nil? && resolved[:type] == :accent
|
499
|
+
end
|
478
500
|
end
|
479
501
|
end
|
data/lib/asciimath/mathml.rb
CHANGED
@@ -5,7 +5,7 @@ module AsciiMath
|
|
5
5
|
class MathMLBuilder < ::AsciiMath::MarkupBuilder
|
6
6
|
|
7
7
|
def initialize(opts = {})
|
8
|
-
super(opts[:symbol_table] ||
|
8
|
+
super(opts[:symbol_table] || ::AsciiMath::MarkupBuilder.default_display_symbol_table(fix_phi: opts.fetch(:fix_phi, true)))
|
9
9
|
@prefix = opts[:prefix] || ''
|
10
10
|
@mathml = ''
|
11
11
|
if opts[:msword]
|
@@ -149,21 +149,37 @@ module AsciiMath
|
|
149
149
|
end
|
150
150
|
|
151
151
|
def append_underover(base, sub, sup)
|
152
|
+
attrs = {}
|
153
|
+
|
154
|
+
sub_row_mode = @row_mode
|
155
|
+
if is_accent(sub)
|
156
|
+
attrs[:accentunder] = true
|
157
|
+
sub_row_mode = :avoid
|
158
|
+
end
|
159
|
+
|
160
|
+
sup_row_mode = @row_mode
|
161
|
+
if is_accent(sup)
|
162
|
+
attrs[:accent] = true
|
163
|
+
sup_row_mode = :avoid
|
164
|
+
end
|
165
|
+
|
166
|
+
|
167
|
+
|
152
168
|
if sub && sup
|
153
|
-
munderover do
|
169
|
+
munderover(attrs) do
|
154
170
|
append(base, :row => @row_mode)
|
155
|
-
append(sub, :row =>
|
156
|
-
append(sup, :row =>
|
171
|
+
append(sub, :row => sub_row_mode)
|
172
|
+
append(sup, :row => sup_row_mode)
|
157
173
|
end
|
158
174
|
elsif sub
|
159
|
-
munder do
|
175
|
+
munder(attrs) do
|
160
176
|
append(base, :row => @row_mode)
|
161
|
-
append(sub, :row =>
|
177
|
+
append(sub, :row => sub_row_mode)
|
162
178
|
end
|
163
179
|
elsif sup
|
164
|
-
mover do
|
180
|
+
mover(attrs) do
|
165
181
|
append(base, :row => @row_mode)
|
166
|
-
append(sup, :row =>
|
182
|
+
append(sup, :row => sup_row_mode)
|
167
183
|
end
|
168
184
|
else
|
169
185
|
append(base)
|
data/lib/asciimath/parser.rb
CHANGED
@@ -441,6 +441,7 @@ module AsciiMath
|
|
441
441
|
b.add('bsf', :bold_sans_serif, :unary)
|
442
442
|
b.add('sfi', :sans_serif_italic, :unary)
|
443
443
|
b.add('sfbi', :sans_serif_bold_italic, :unary)
|
444
|
+
b.add('rm', :roman, :unary)
|
444
445
|
|
445
446
|
# Greek letters
|
446
447
|
b.add('alpha', :alpha, :symbol)
|
@@ -612,12 +613,16 @@ module AsciiMath
|
|
612
613
|
token_to_symbol(t1)
|
613
614
|
end
|
614
615
|
when :unary
|
615
|
-
|
616
|
+
parse_simple_expression = parse_simple_expression(tok, depth)
|
617
|
+
s = unwrap_paren(parse_simple_expression)
|
618
|
+
s = identifier('') if s.nil?
|
616
619
|
s = convert_node(s, t1[:convert_operand])
|
617
620
|
unary(token_to_symbol(t1), s)
|
618
621
|
when :binary
|
619
622
|
s1 = unwrap_paren(parse_simple_expression(tok, depth))
|
623
|
+
s1 = identifier('') if s1.nil?
|
620
624
|
s2 = unwrap_paren(parse_simple_expression(tok, depth))
|
625
|
+
s2 = identifier('') if s2.nil?
|
621
626
|
|
622
627
|
s1 = convert_node(s1, t1[:convert_operand1])
|
623
628
|
s2 = convert_node(s2, t1[:convert_operand2])
|
@@ -704,7 +709,6 @@ module AsciiMath
|
|
704
709
|
def convert_to_color(color_expression)
|
705
710
|
s = ""
|
706
711
|
append_color_text(s, color_expression)
|
707
|
-
s
|
708
712
|
|
709
713
|
case s
|
710
714
|
when /#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i
|
data/lib/asciimath/version.rb
CHANGED
data/spec/parser_spec.rb
CHANGED
@@ -74,8 +74,8 @@ RSpec.shared_examples 'AsciiMath Examples' do
|
|
74
74
|
'j',
|
75
75
|
sub(symbol('vartheta'), '0')
|
76
76
|
),
|
77
|
-
:mathml => '<math><munder><mover><mi>A</mi><mo>^</mo></mover><mo>_</mo></munder><mo>=</mo><mover><mi>A</mi><mo>^</mo></mover><mi>exp</mi><mi>j</mi><msub><mi>ϑ</mi><mn>0</mn></msub></math>',
|
78
|
-
:mathml_word => '<math><munder><mrow><mover><mrow><mi>A</mi></mrow><
|
77
|
+
:mathml => '<math><munder><mover accent="true"><mi>A</mi><mo>^</mo></mover><mo>_</mo></munder><mo>=</mo><mover accent="true"><mi>A</mi><mo>^</mo></mover><mi>exp</mi><mi>j</mi><msub><mi>ϑ</mi><mn>0</mn></msub></math>',
|
78
|
+
:mathml_word => '<math><munder><mrow><mover accent="true"><mrow><mi>A</mi></mrow><mo>^</mo></mover></mrow><mrow><mo>_</mo></mrow></munder><mo>=</mo><mover accent="true"><mrow><mi>A</mi></mrow><mo>^</mo></mover><mi>exp</mi><mi>j</mi><msub><mrow><mi>ϑ</mi></mrow><mrow><mn>0</mn></mrow></msub></math>',
|
79
79
|
:latex => '\\underset{\\text{–}}{\\hat{A}} = \\hat{A} \\exp j \\vartheta_0'
|
80
80
|
))
|
81
81
|
|
@@ -272,7 +272,7 @@ RSpec.shared_examples 'AsciiMath Examples' do
|
|
272
272
|
unary(symbol('ul'), group('A')),
|
273
273
|
unary(symbol('vec'), group('v')),
|
274
274
|
),
|
275
|
-
:mathml => '<math><mover><mrow><mi>a</mi><mi>b</mi></mrow><mo>^</mo></mover><mover><mrow><mi>x</mi><mi>y</mi></mrow><mo>¯</mo></mover><munder><mi>A</mi><mo>_</mo></munder><mover><mi>v</mi><mo>→</mo></mover></math>',
|
275
|
+
:mathml => '<math><mover accent="true"><mrow><mi>a</mi><mi>b</mi></mrow><mo>^</mo></mover><mover accent="true"><mrow><mi>x</mi><mi>y</mi></mrow><mo>¯</mo></mover><munder accentunder="true"><mi>A</mi><mo>_</mo></munder><mover accent="true"><mi>v</mi><mo>→</mo></mover></math>',
|
276
276
|
:html => '<span class="math-inline"><span class="math-blank">‍</span><span class="math-underover"><span class="math-smaller"><span class="math-operator">^</span></span><span class="math-row"><span class="math-identifier">a</span><span class="math-identifier">b</span></span><span class="math-smaller"><span class="math-blank">‍</span></span></span><span class="math-blank">‍</span><span class="math-underover"><span class="math-smaller"><span class="math-operator">¯</span></span><span class="math-row"><span class="math-identifier">x</span><span class="math-identifier">y</span></span><span class="math-smaller"><span class="math-blank">‍</span></span></span><span class="math-blank">‍</span><span class="math-underover"><span class="math-smaller"><span class="math-blank">‍</span></span><span class="math-identifier">A</span><span class="math-smaller"><span class="math-operator">_</span></span></span><span class="math-blank">‍</span><span class="math-underover"><span class="math-smaller"><span class="math-operator">→</span></span><span class="math-identifier">v</span><span class="math-smaller"><span class="math-blank">‍</span></span></span></span>',
|
277
277
|
:latex => '\\hat{a b} \\overline{x y} \\underline{A} \\vec{v}',
|
278
278
|
))
|
@@ -418,7 +418,7 @@ RSpec.shared_examples 'AsciiMath Examples' do
|
|
418
418
|
unary(symbol('ubrace'), grseq('1', symbol('+'), '2')),
|
419
419
|
unary(symbol('obrace'), group(symbol('('), seq('3', symbol('+'), '4'), nil))
|
420
420
|
),
|
421
|
-
:mathml => '<math><munder><mrow><mn>1</mn><mo>+</mo><mn>2</mn></mrow><mo>⏟</mo></munder><mover><mrow><mn>3</mn><mo>+</mo><mn>4</mn></mrow><mo>⏞</mo></mover></math>',
|
421
|
+
:mathml => '<math><munder accentunder="true"><mrow><mn>1</mn><mo>+</mo><mn>2</mn></mrow><mo>⏟</mo></munder><mover accent="true"><mrow><mn>3</mn><mo>+</mo><mn>4</mn></mrow><mo>⏞</mo></mover></math>',
|
422
422
|
:latex => '\\underbrace{1 + 2} \\overbrace{3 + 4}',
|
423
423
|
))
|
424
424
|
|
@@ -519,7 +519,7 @@ RSpec.shared_examples 'AsciiMath Examples' do
|
|
519
519
|
|
520
520
|
example('overarc a_b^c', &should_generate(
|
521
521
|
:ast => subsup(unary(symbol('overarc'), 'a'), 'b', 'c'),
|
522
|
-
:mathml => '<math><msubsup><mover><mi>a</mi><mo>⏜</mo></mover><mi>b</mi><mi>c</mi></msubsup></math>',
|
522
|
+
:mathml => '<math><msubsup><mover accent="true"><mi>a</mi><mo>⏜</mo></mover><mi>b</mi><mi>c</mi></msubsup></math>',
|
523
523
|
:latex => '{\\overset{\\frown}{a}}_b^c'
|
524
524
|
))
|
525
525
|
|
@@ -572,6 +572,21 @@ RSpec.shared_examples 'AsciiMath Examples' do
|
|
572
572
|
:latex => '\\left \\{ x \\; : \\; x \\in A \\wedge x \\in B \\right \\}',
|
573
573
|
))
|
574
574
|
|
575
|
+
example('ii', &should_generate(
|
576
|
+
:ast => unary(symbol('ii'), identifier('')),
|
577
|
+
:mathml => '<math><mstyle mathvariant="italic"><mi></mi></mstyle></math>'
|
578
|
+
))
|
579
|
+
|
580
|
+
example('rm(ms)', &should_generate(
|
581
|
+
:ast => unary(symbol('rm'), grseq(identifier('m'), identifier('s'))),
|
582
|
+
:mathml => '<math><mstyle mathvariant="normal"><mrow><mi>m</mi><mi>s</mi></mrow></mstyle></math>'
|
583
|
+
))
|
584
|
+
|
585
|
+
example('hat', &should_generate(
|
586
|
+
:ast => unary(symbol('hat'), identifier('')),
|
587
|
+
:mathml => '<math><mover accent="true"><mi></mi><mo>^</mo></mover></math>'
|
588
|
+
))
|
589
|
+
|
575
590
|
version = RUBY_VERSION.split('.').map { |s| s.to_i }
|
576
591
|
|
577
592
|
if version[0] > 1 || version[1] > 8
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciimath
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pepijn Van Eeckhoudt
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-12-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -76,8 +76,8 @@ executables:
|
|
76
76
|
extensions: []
|
77
77
|
extra_rdoc_files: []
|
78
78
|
files:
|
79
|
+
- ".github/workflows/ci.yml"
|
79
80
|
- ".gitignore"
|
80
|
-
- ".travis.yml"
|
81
81
|
- AST.adoc
|
82
82
|
- CHANGELOG.adoc
|
83
83
|
- Gemfile
|
@@ -156,8 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
156
|
- !ruby/object:Gem::Version
|
157
157
|
version: '0'
|
158
158
|
requirements: []
|
159
|
-
|
160
|
-
rubygems_version: 2.7.6
|
159
|
+
rubygems_version: 3.0.3
|
161
160
|
signing_key:
|
162
161
|
specification_version: 4
|
163
162
|
summary: AsciiMath parser and converter
|
data/.travis.yml
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
cache:
|
3
|
-
apt: true
|
4
|
-
directories:
|
5
|
-
- vendor/bundle
|
6
|
-
- $HOME/.cache/pip
|
7
|
-
rvm:
|
8
|
-
- 2.3
|
9
|
-
- 2.4
|
10
|
-
- 2.5
|
11
|
-
- jruby
|
12
|
-
- truffleruby
|
13
|
-
before_install:
|
14
|
-
- type bundle || gem install bundler --version '~> 1.0'
|
15
|
-
install:
|
16
|
-
- bundle install --path vendor/bundle --jobs=3 --retry=3
|