jekyll-tex-eqn 0.9.2 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jekyll-tex-eqn.rb +43 -16
  3. metadata +22 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e7da3c797d328f1dc308a8eba1c235ef925f4e66c6364f218023d4d6e99131d
4
- data.tar.gz: 78439154af7d5e02d9fcc3a39053ba3c9bd737fd5087c43b4c3b559c69feec27
3
+ metadata.gz: 6bf0089e27fafd98d16aa5d8a8c7d4feaaa9ea1a0fc135bf8afa594936c1501a
4
+ data.tar.gz: a792c706fff9b4fbd55d3cf5896042e3215a7fb5ef31f0930ba910d4b7038253
5
5
  SHA512:
6
- metadata.gz: e0e18ffc63f1b4635b28ae93105e7b4d27066b90af9d29b18b904cba6506d4a77242296d24bf8e4fa6c0c816da677f6330526ce1096913d8f8aa416aa47f17f8
7
- data.tar.gz: f2c9d78a7cdbc3c82892d5445aaecf84061f74112306ce1bc090c32c017c900ed74621e7eb4469e39bbbc41c607736c760e269f8454880e9708e92a80f22f6bd
6
+ metadata.gz: b5880241dd57e19b3072a2dcb4cbcbb9081172c6a9496f19d5928a62d2feeefb488e5e7be6216b0079bbe1c6c26fb7709a37890f8072ffe8eb358c9578211474
7
+ data.tar.gz: 45fda985ffdd7f6f1530f533944db009a786f10eb50f895200f2d0d1eff96f87e9784b6ce4b2ae6d614ecfe159396a9b3894ccdb9e8c01377b1bfe682d73cc61
@@ -48,6 +48,7 @@ module Jekyll
48
48
  EXTRAHEAD_KEY="extra_head" # Key for the extra header
49
49
  INLINE_SCALE_KEY="inline_scale" # Key for setting up image scaling for inline equations
50
50
  BLOCK_SCALE_KEY="block_scale" # Key for setting up image scaling for block equations
51
+ OPTIMIZE_KEY="optimize" # Key for enabling SVG optimization using SVGO
51
52
 
52
53
  # Default values
53
54
  DEFAULT_BACKEND="pdflatex"
@@ -61,6 +62,7 @@ module Jekyll
61
62
  DEFAULT_OUTPUTDIR="assets/texeqn"
62
63
  DEFAULT_INLINE_SCALE="2.4"
63
64
  DEFAULT_BLOCK_SCALE="2.4"
65
+ DEFAULT_OPTIMIZE="false"
64
66
 
65
67
  # Retrieve Jekyll configuration for this plugin
66
68
  @@config = Jekyll.configuration({})[ROOT]
@@ -119,30 +121,49 @@ module Jekyll
119
121
  # where to export the SVG, and "pdf", the pdfxx command that performs the
120
122
  # TeX => PDF conversion (easier because then this value is calculated only
121
123
  # once).
122
- def self.run_cmd(base)
124
+ def self.run_cmd(texbase, svgfile)
123
125
  text = ""
124
126
 
125
- # Cleanup if needed (in case of past error for instanec)
126
- if !File.exist?("#{@@basedir}/#{base}") then
127
- Dir.mkdir("#{@@basedir}/#{base}")
127
+ Jekyll.logger.debug("Clean up...")
128
+
129
+ # Cleanup if needed (in case of past error for instance)
130
+ if !File.exist?("#{texbase}") then
131
+ Dir.mkdir("#{texbase}")
132
+ end
133
+
134
+ # Ensure output dir exists
135
+ if !File.exist?("#{@@outdir}") then
136
+ Dir.mkdir("#{@@outdir}")
128
137
  end
129
138
 
130
139
  # Run pdfxx, compile TeX into PDF
131
- text = %x|#{@@pdf} -output-directory=#{@@basedir}/#{base}/ #{@@basedir}/#{base}.tex 2>&1|
140
+ Jekyll.logger.debug("Run LaTeX compiler (#{@pdf})")
141
+ text = %x|#{@@pdf} -output-directory=#{texbase}/ #{texbase}.tex 2>&1|
132
142
  if $?.exitstatus != 0 then
133
- raise "[#{base}] Error #{$?.exitstatus} while executing backend:\n#{text}"
143
+ raise "[#{texbase}] Error #{$?.exitstatus} while executing backend:\n#{text}"
134
144
  end
135
145
 
136
146
  # Use pdfcrop to crop the PDF
137
- text = %x|pdfcrop #{@@basedir}/#{base}/output.pdf #{@@basedir}/#{base}/output-crop.pdf 2>&1|
147
+ Jekyll.logger.debug("Crop PDF")
148
+ text = %x|pdfcrop #{texbase}/output.pdf #{texbase}/output-crop.pdf 2>&1|
138
149
  if $?.exitstatus != 0 then
139
- raise "[#{base}] Error #{$?.exitstatus} while croping PDF:\n#{text}"
150
+ raise "[#{texbase}] Error #{$?.exitstatus} while croping PDF:\n#{text}"
140
151
  end
141
-
152
+
142
153
  # Use pdf2svg to transform the cropped PDF into an SVG
143
- text = %x|pdf2svg #{@@basedir}/#{base}/output-crop.pdf #{@@outdir}/#{base}.svg 2>&1|
154
+ Jekyll.logger.debug("Convert PDF to SVG")
155
+ text = %x|pdf2svg #{texbase}/output-crop.pdf #{svgfile} 2>&1|
144
156
  if $?.exitstatus != 0 then
145
- raise "[#{base}] Error #{$?.exitstatus} while generating SVG:\n#{text}"
157
+ raise "[#{texbase}] Error #{$?.exitstatus} while generating SVG:\n#{text}"
158
+ end
159
+
160
+ # Optional: optimzie SVG using SVGO
161
+ if Util.get_option(Util::OPTIMIZE_KEY, Util::DEFAULT_OPTIMIZE) == "true" then
162
+ Jekyll.logger.debug("Optimize SVG file")
163
+ text = %x|svgo -i #{svgfile}|
164
+ if $?.exitstatus != 0 then
165
+ raise "[#{svgfile}] Error #{$?.exitstatus} while optimizeing SVG:\n#{text}"
166
+ end
146
167
  end
147
168
 
148
169
  end
@@ -154,8 +175,10 @@ module Jekyll
154
175
  # a hash function on the content to obtain (virtually) unique names.
155
176
  def self.filename(filepath, content)
156
177
  id = Digest::MD5.hexdigest content
157
- pagepath = filepath
158
- pagepath.gsub("/", "_").gsub(" ", "-")
178
+ pagepath = filepath.gsub("/", "_").gsub(" ", "-")
179
+ while pagepath[0] == '_' do # Weird jekyll behaviour: files starting with an underscore are not copied during build
180
+ pagepath = pagepath[1..-1]
181
+ end
159
182
  "#{pagepath}-#{id}"
160
183
  end
161
184
 
@@ -195,7 +218,8 @@ module Jekyll
195
218
  content.strip!
196
219
  path = context.registers[:page]['path']
197
220
  file = Generate.filename(path, content)
198
- texfile = "#{@@basedir}/#{file}.tex"
221
+ texbase = "#{@@basedir}/#{file}"
222
+ texfile = "#{texbase}.tex"
199
223
  svgfile = "#{@@outdir}/#{file}.svg"
200
224
 
201
225
  # If the SVG file already exists, no need to re-render it (usually)
@@ -204,9 +228,10 @@ module Jekyll
204
228
  if !File.exist?(texfile) && !File.exist?(svgfile) then
205
229
  Jekyll.logger.info("Generating image file #{file}")
206
230
  Generate.generate_file(context, content, begineqn, endeqn, texfile)
207
- Generate.run_cmd(file)
231
+ Jekyll.logger.info("Processing file #{file}")
232
+ Generate.run_cmd(texbase, svgfile)
208
233
  File.delete(texfile)
209
- if File.exist?("#{@@basedir}/#{file}") then
234
+ if File.exist?(texbase) then
210
235
  FileUtils.remove_dir("#{@@basedir}/#{file}")
211
236
  end
212
237
  end
@@ -232,6 +257,7 @@ module Jekyll
232
257
 
233
258
  def render(context)
234
259
  svg = Generate.do_render(context, @content, Util.get_option(Util::INLINE_SCALE_KEY, Util::DEFAULT_INLINE_SCALE).to_f, "$", "$")
260
+
235
261
  "<span class='#{Util.get_option(Util::INLINE_CLASS_KEY, "")}'><img width='#{svg[:width]}px' height='#{svg[:height]}px' src='/#{svg[:file]}'/></span>"
236
262
  end
237
263
  end
@@ -243,6 +269,7 @@ module Jekyll
243
269
  def render(context)
244
270
  content = super
245
271
  svg = Generate.do_render(context, content, Util.get_option(Util::BLOCK_SCALE_KEY, Util::DEFAULT_BLOCK_SCALE).to_f, "\\begin{displaymath}\n", "\n\\end{displaymath}")
272
+
246
273
  "<div class='#{Util.get_option(Util::BLOCK_CLASS_KEY, "")}'><img width='#{svg[:width]}px' height='#{svg[:height]}px' src='/#{svg[:file]}'/></div>"
247
274
  end
248
275
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-tex-eqn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - krab5
@@ -33,42 +33,54 @@ dependencies:
33
33
  name: digest
34
34
  requirement: !ruby/object:Gem::Requirement
35
35
  requirements:
36
- - - "~>"
36
+ - - ">="
37
37
  - !ruby/object:Gem::Version
38
38
  version: '3.0'
39
+ - - "<"
40
+ - !ruby/object:Gem::Version
41
+ version: '4.0'
39
42
  type: :runtime
40
43
  prerelease: false
41
44
  version_requirements: !ruby/object:Gem::Requirement
42
45
  requirements:
43
- - - "~>"
46
+ - - ">="
44
47
  - !ruby/object:Gem::Version
45
48
  version: '3.0'
49
+ - - "<"
50
+ - !ruby/object:Gem::Version
51
+ version: '4.0'
46
52
  - !ruby/object:Gem::Dependency
47
53
  name: fileutils
48
54
  requirement: !ruby/object:Gem::Requirement
49
55
  requirements:
50
- - - "~>"
56
+ - - ">="
51
57
  - !ruby/object:Gem::Version
52
- version: '1.4'
58
+ version: '1.2'
59
+ - - "<"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
53
62
  type: :runtime
54
63
  prerelease: false
55
64
  version_requirements: !ruby/object:Gem::Requirement
56
65
  requirements:
57
- - - "~>"
66
+ - - ">="
58
67
  - !ruby/object:Gem::Version
59
- version: '1.4'
68
+ version: '1.2'
69
+ - - "<"
70
+ - !ruby/object:Gem::Version
71
+ version: '2.0'
60
72
  - !ruby/object:Gem::Dependency
61
73
  name: bundler
62
74
  requirement: !ruby/object:Gem::Requirement
63
75
  requirements:
64
- - - "~>"
76
+ - - ">="
65
77
  - !ruby/object:Gem::Version
66
78
  version: '1.10'
67
79
  type: :development
68
80
  prerelease: false
69
81
  version_requirements: !ruby/object:Gem::Requirement
70
82
  requirements:
71
- - - "~>"
83
+ - - ">="
72
84
  - !ruby/object:Gem::Version
73
85
  version: '1.10'
74
86
  email: crab.delicieux@gmail.com
@@ -88,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
100
  requirements:
89
101
  - - ">="
90
102
  - !ruby/object:Gem::Version
91
- version: 2.4.0
103
+ version: 3.0.0
92
104
  required_rubygems_version: !ruby/object:Gem::Requirement
93
105
  requirements:
94
106
  - - ">="