jekyll-tex-eqn 1.0.0 → 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 +41 -13
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3fbf98c7e73031e3ab1cbec82fd152216a81c8fd6f533d0d0d256866df97e1cc
4
- data.tar.gz: 15b85655ef755d8fc103f7b41919b3a51788daa754b7486c87280f442d507c5b
3
+ metadata.gz: 6bf0089e27fafd98d16aa5d8a8c7d4feaaa9ea1a0fc135bf8afa594936c1501a
4
+ data.tar.gz: a792c706fff9b4fbd55d3cf5896042e3215a7fb5ef31f0930ba910d4b7038253
5
5
  SHA512:
6
- metadata.gz: 6ef5e34d8024ab5071143fac362bce5dff54c4243ae8024a615db981b14f618a54d69e1e4e2ba879b9f7de4133f57418beda91a280819d7af9768a891bcf2802
7
- data.tar.gz: b7d9b911473ed030da7badef3832f8770b2d6a2c98a0357976451fbd7292a3c390310413c2b09f49c2bdec4465d432cd617f0d5c04a372708daf6d90b0edb0dd
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
 
127
+ Jekyll.logger.debug("Clean up...")
128
+
125
129
  # Cleanup if needed (in case of past error for instance)
126
- if !File.exist?("#{@@basedir}/#{base}") then
127
- Dir.mkdir("#{@@basedir}/#{base}")
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
@@ -155,6 +176,9 @@ module Jekyll
155
176
  def self.filename(filepath, content)
156
177
  id = Digest::MD5.hexdigest content
157
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
158
182
  "#{pagepath}-#{id}"
159
183
  end
160
184
 
@@ -194,7 +218,8 @@ module Jekyll
194
218
  content.strip!
195
219
  path = context.registers[:page]['path']
196
220
  file = Generate.filename(path, content)
197
- texfile = "#{@@basedir}/#{file}.tex"
221
+ texbase = "#{@@basedir}/#{file}"
222
+ texfile = "#{texbase}.tex"
198
223
  svgfile = "#{@@outdir}/#{file}.svg"
199
224
 
200
225
  # If the SVG file already exists, no need to re-render it (usually)
@@ -203,9 +228,10 @@ module Jekyll
203
228
  if !File.exist?(texfile) && !File.exist?(svgfile) then
204
229
  Jekyll.logger.info("Generating image file #{file}")
205
230
  Generate.generate_file(context, content, begineqn, endeqn, texfile)
206
- Generate.run_cmd(file)
231
+ Jekyll.logger.info("Processing file #{file}")
232
+ Generate.run_cmd(texbase, svgfile)
207
233
  File.delete(texfile)
208
- if File.exist?("#{@@basedir}/#{file}") then
234
+ if File.exist?(texbase) then
209
235
  FileUtils.remove_dir("#{@@basedir}/#{file}")
210
236
  end
211
237
  end
@@ -231,6 +257,7 @@ module Jekyll
231
257
 
232
258
  def render(context)
233
259
  svg = Generate.do_render(context, @content, Util.get_option(Util::INLINE_SCALE_KEY, Util::DEFAULT_INLINE_SCALE).to_f, "$", "$")
260
+
234
261
  "<span class='#{Util.get_option(Util::INLINE_CLASS_KEY, "")}'><img width='#{svg[:width]}px' height='#{svg[:height]}px' src='/#{svg[:file]}'/></span>"
235
262
  end
236
263
  end
@@ -242,6 +269,7 @@ module Jekyll
242
269
  def render(context)
243
270
  content = super
244
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
+
245
273
  "<div class='#{Util.get_option(Util::BLOCK_CLASS_KEY, "")}'><img width='#{svg[:width]}px' height='#{svg[:height]}px' src='/#{svg[:file]}'/></div>"
246
274
  end
247
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: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - krab5