asciidoctor-mathematical 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7fd0033c90a779c003b2358774f5e9801eb8edc30f24407eca58c1f5239d322a
4
- data.tar.gz: db842b6dee4c6ad6dbc15dee99321d721b3f34238b473ee2d497d1ddaaca6b2f
3
+ metadata.gz: faf0fb4e29f2614d868f99bd0d85367a0a6db8ca6481668b2061ad452abf097f
4
+ data.tar.gz: a05239f948741cd7474442e095dbc0cb920da2d60bec09ec21965ae36f236a0e
5
5
  SHA512:
6
- metadata.gz: 8496913a5bf4be427950d5892f1b33910a56c4e35139a448ce6490ac38e19f429039465cfc35ae940ce129757394410698415e6d7c1fc933df39c28482951713
7
- data.tar.gz: c9607a682a7e4074d6ee509170202ec4e39909eacc8213714b355547de62b61ff43b217a3084e541249ebfa1c461edb9cac9fbec3b9db2947e095f6c7826c21f
6
+ metadata.gz: 0de6aa46ffbf1450dee13b0710c00445839a767a8ca238d0ed9643163da84b19a995c776221b5698508f832bcbfbd94d7da297563db3a7cdebb2a6b99c3705c5
7
+ data.tar.gz: 37bc274bfa70f1d653ae01ad25195c528b2a55758db519bc1677e872c6d42204bcda86db281f2ffb914ca7901d44452a3c1debe6b4c1008fb26eee366479b92c
@@ -1,13 +1,15 @@
1
1
  require 'pathname'
2
2
  require 'asciidoctor/extensions'
3
+ require 'asciimath'
3
4
 
4
5
  autoload :Digest, 'digest'
5
6
  autoload :Mathematical, 'mathematical'
6
7
 
7
8
  class MathematicalTreeprocessor < Asciidoctor::Extensions::Treeprocessor
8
9
  LineFeed = %(\n)
9
- StemInlineMacroRx = /\\?(?:stem|latexmath):([a-z,]*)\[(.*?[^\\])\]/m
10
+ StemInlineMacroRx = /\\?(?:stem|latexmath|asciimath):([a-z,]*)\[(.*?[^\\])\]/m
10
11
  LatexmathInlineMacroRx = /\\?latexmath:([a-z,]*)\[(.*?[^\\])\]/m
12
+ AsciiMathInlineMacroRx = /\\?asciimath:([a-z,]*)\[(.*?[^\\])\]/m
11
13
 
12
14
  def process document
13
15
  format = ((document.attr 'mathematical-format') || 'png').to_sym
@@ -69,16 +71,24 @@ class MathematicalTreeprocessor < Asciidoctor::Extensions::Treeprocessor
69
71
 
70
72
  def handle_stem_block(stem, mathematical, image_output_dir, image_target_dir, format, inline)
71
73
  equation_type = stem.style.to_sym
72
- return unless equation_type == :latexmath
73
74
 
74
- img_target, img_width, img_height = make_equ_image stem.content, stem.id, false, mathematical, image_output_dir, image_target_dir, format, inline
75
+ case equation_type
76
+ when :latexmath
77
+ content = stem.content
78
+ when :asciimath
79
+ content = AsciiMath.parse(stem.content).to_latex
80
+ else
81
+ return
82
+ end
83
+
84
+ img_target, img_width, img_height = make_equ_image content, stem.id, false, mathematical, image_output_dir, image_target_dir, format, inline
75
85
 
76
86
  parent = stem.parent
77
87
  if inline
78
88
  stem_image = create_pass_block parent, %{<div class="stemblock"> #{img_target} </div>}, {}
79
89
  parent.blocks[parent.blocks.index stem] = stem_image
80
90
  else
81
- alt_text = stem.attr 'alt', %($$#{stem.content}$$)
91
+ alt_text = stem.attr 'alt', (equation_type == :latexmath ? %($$#{content}$$) : %(`#{content}`))
82
92
  attrs = {'target' => img_target, 'alt' => alt_text, 'align' => 'center'}
83
93
  # NOTE: The following setups the *intended width and height in pixel* for png images, which can be different that that of the generated image when PPIs larger than 72.0 is used.
84
94
  if format == :png
@@ -127,8 +137,18 @@ class MathematicalTreeprocessor < Asciidoctor::Extensions::Treeprocessor
127
137
  def handle_inline_stem(node, text, mathematical, image_output_dir, image_target_dir, format, inline)
128
138
  document = node.document
129
139
  to_html = document.basebackend? 'html'
130
- support_stem_prefix = document.attr? 'stem', 'latexmath'
131
- stem_rx = support_stem_prefix ? StemInlineMacroRx : LatexmathInlineMacroRx
140
+
141
+ case document.attr 'stem'
142
+ when 'latexmath'
143
+ support_stem_prefix = true
144
+ stem_rx = LatexmathInlineMacroRx
145
+ when 'asciimath'
146
+ support_stem_prefix = true
147
+ stem_rx = AsciiMathInlineMacroRx
148
+ else
149
+ support_stem_prefix = false
150
+ stem_rx = StemInlineMacroRx
151
+ end
132
152
 
133
153
  source_modified = false
134
154
  # TODO skip passthroughs in the source (e.g., +stem:[x^2]+)
@@ -152,7 +172,7 @@ class MathematicalTreeprocessor < Asciidoctor::Extensions::Treeprocessor
152
172
  else
153
173
  %(image:#{img_target}[width=#{img_width},height=#{img_height}])
154
174
  end
155
- } if (text != nil) && (text.include? ':') && ((support_stem_prefix && (text.include? 'stem:')) || (text.include? 'latexmath:'))
175
+ } if (text != nil) && (text.include? ':') && ((support_stem_prefix && (text.include? 'stem:')) || (text.include? 'latexmath:') || (text.include? 'asciimath:'))
156
176
 
157
177
  [text, source_modified]
158
178
  end
@@ -179,31 +199,24 @@ class MathematicalTreeprocessor < Asciidoctor::Extensions::Treeprocessor
179
199
  end
180
200
  end
181
201
 
182
- def image_output_and_target_dir(parent)
183
- document = parent.document
184
-
185
- output_dir = parent.attr('imagesoutdir')
202
+ def image_output_and_target_dir(doc)
203
+ output_dir = doc.attr('imagesoutdir')
186
204
  if output_dir
187
- base_dir = nil
188
- if parent.attr('imagesdir').nil_or_empty?
205
+ if doc.attr('imagesdir').nil_or_empty?
189
206
  target_dir = output_dir
190
207
  else
191
208
  # When imagesdir attribute is set, every relative path is prefixed with it. So the real target dir shall then be relative to the imagesdir, instead of being relative to document root.
192
- doc_outdir = parent.attr('outdir') || (document.respond_to?(:options) && document.options[:to_dir])
193
- abs_imagesdir = parent.normalize_system_path(parent.attr('imagesdir'), doc_outdir)
194
- abs_outdir = parent.normalize_system_path(output_dir, base_dir)
195
- p1 = ::Pathname.new abs_outdir
196
- p2 = ::Pathname.new abs_imagesdir
197
- target_dir = p1.relative_path_from(p2).to_s
209
+ abs_imagesdir = ::Pathname.new doc.normalize_system_path(doc.attr('imagesdir'))
210
+ abs_outdir = ::Pathname.new doc.normalize_system_path(output_dir)
211
+ target_dir = abs_outdir.relative_path_from(abs_imagesdir).to_s
198
212
  end
199
213
  else
200
- base_dir = parent.attr('outdir') || (document.respond_to?(:options) && document.options[:to_dir])
201
- output_dir = parent.attr('imagesdir')
214
+ output_dir = doc.attr('imagesdir')
202
215
  # since we store images directly to imagesdir, target dir shall be NULL and asciidoctor converters will prefix imagesdir.
203
216
  target_dir = "."
204
217
  end
205
218
 
206
- output_dir = parent.normalize_system_path(output_dir, base_dir)
219
+ output_dir = doc.normalize_system_path(output_dir, doc.attr('docdir'))
207
220
  return [output_dir, target_dir]
208
221
  end
209
222
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-mathematical
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Stumm
@@ -50,22 +50,42 @@ dependencies:
50
50
  name: asciidoctor
51
51
  requirement: !ruby/object:Gem::Requirement
52
52
  requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '2.0'
53
56
  - - ">="
54
57
  - !ruby/object:Gem::Version
55
58
  version: 2.0.0
59
+ type: :runtime
60
+ prerelease: false
61
+ version_requirements: !ruby/object:Gem::Requirement
62
+ requirements:
56
63
  - - "~>"
57
64
  - !ruby/object:Gem::Version
58
65
  version: '2.0'
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: asciimath
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.0.0
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 2.0.0
59
79
  type: :runtime
60
80
  prerelease: false
61
81
  version_requirements: !ruby/object:Gem::Requirement
62
82
  requirements:
63
- - - ">="
83
+ - - "~>"
64
84
  - !ruby/object:Gem::Version
65
85
  version: 2.0.0
66
- - - "~>"
86
+ - - ">="
67
87
  - !ruby/object:Gem::Version
68
- version: '2.0'
88
+ version: 2.0.0
69
89
  - !ruby/object:Gem::Dependency
70
90
  name: rake
71
91
  requirement: !ruby/object:Gem::Requirement
@@ -107,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
127
  - !ruby/object:Gem::Version
108
128
  version: '0'
109
129
  requirements: []
110
- rubygems_version: 3.0.4
130
+ rubygems_version: 3.1.3
111
131
  signing_key:
112
132
  specification_version: 4
113
133
  summary: Asciidoctor STEM processor based on Mathematical