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.
- checksums.yaml +4 -4
- data/lib/jekyll-tex-eqn.rb +41 -13
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6bf0089e27fafd98d16aa5d8a8c7d4feaaa9ea1a0fc135bf8afa594936c1501a
|
|
4
|
+
data.tar.gz: a792c706fff9b4fbd55d3cf5896042e3215a7fb5ef31f0930ba910d4b7038253
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b5880241dd57e19b3072a2dcb4cbcbb9081172c6a9496f19d5928a62d2feeefb488e5e7be6216b0079bbe1c6c26fb7709a37890f8072ffe8eb358c9578211474
|
|
7
|
+
data.tar.gz: 45fda985ffdd7f6f1530f533944db009a786f10eb50f895200f2d0d1eff96f87e9784b6ce4b2ae6d614ecfe159396a9b3894ccdb9e8c01377b1bfe682d73cc61
|
data/lib/jekyll-tex-eqn.rb
CHANGED
|
@@ -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(
|
|
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?("#{
|
|
127
|
-
Dir.mkdir("#{
|
|
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
|
-
|
|
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 "[#{
|
|
143
|
+
raise "[#{texbase}] Error #{$?.exitstatus} while executing backend:\n#{text}"
|
|
134
144
|
end
|
|
135
145
|
|
|
136
146
|
# Use pdfcrop to crop the PDF
|
|
137
|
-
|
|
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 "[#{
|
|
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
|
-
|
|
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 "[#{
|
|
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
|
-
|
|
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
|
-
|
|
231
|
+
Jekyll.logger.info("Processing file #{file}")
|
|
232
|
+
Generate.run_cmd(texbase, svgfile)
|
|
207
233
|
File.delete(texfile)
|
|
208
|
-
if File.exist?(
|
|
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
|