jekyll-t4j 0.3.0 → 0.4.0

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: 4f7546786489dba969477bac00c45f4e89d15fefe3f875e2567b725d86c81673
4
- data.tar.gz: 8145c980e01d7bae20bf611957a61073602789c07f070248c9c85465b241ddaa
3
+ metadata.gz: 0a1870ef42a1f2b51f55427bf9fc304e59224e0d473c9f1e0c43297ad2347709
4
+ data.tar.gz: 47330b060c44e1850c8691d2d88e302483c4069bf166b6f9dd4720b92170275b
5
5
  SHA512:
6
- metadata.gz: 363df4ceb85c4e053571d6593b87009c1c79a404cb109d16f85a3f2b1325e3155bb86c0eb18f0b4780741d390994069b6608fc326fd73915c8fc58c4c84b3821
7
- data.tar.gz: be623b5331e9e492f6484db617290c8c0f05416040613fb90da3e6dd7794dcf8b75d948a480809fa56da7b31888c4f13eaa286ea6a6a1dc17476b47962a09a5f
6
+ metadata.gz: b0842f23b676c35dfdbca726b144c243c0331d56200833af4e47c61210a5b833d0e86cd02cfd022f34b69b0af24272d46630e50521da98125343640115c22c66
7
+ data.tar.gz: 16d051b87d412c97fa69ed6222aadd4367506733b39963ccd91896f15a7eb8874b761bdd3db3bce4c2a3c1d8cc0e6445c5039eba1c14c2fe67d2e430dc3e2e5a
data/README.md CHANGED
@@ -3,10 +3,10 @@
3
3
  jekyll-t4j is a Jekyll plugin providing (nearly) full support of LaTeX.
4
4
 
5
5
  - **Comprehensive**: support almost all packages, including tikz, chemfig, etc.
6
- - **Fast**: employ KaTeX to boost speed. Use cache, bulk rendering.
6
+ - **Fast**: employ KaTeX to boost speed. Use cache, precompiled preamble, bulk rendering.
7
7
  - **Server side rendering**: all stuffs are done in server.
8
8
 
9
- T4J integrates Jekyll with your local TeX distribution, so you need to have either [MikTeX](https://miktex.org/) or [Tex Live](https://tug.org/texlive/) installed.
9
+ T4J integrates Jekyll with your local TeX distribution, so you need to have either [MikTeX](https://miktex.org/) or [TeX Live](https://tug.org/texlive/) installed.
10
10
 
11
11
  Feel free to write any LaTeX! 🎉
12
12
 
@@ -44,7 +44,7 @@ You can learn more about T4J [here](https://github.com/crow02531/jekyll-t4j/wiki
44
44
 
45
45
  ## Installation
46
46
 
47
- First of all, you need to have a TeX distribution. Just download and install [MikTeX](https://miktex.org/) or [Tex Live](https://tug.org/texlive/).
47
+ First of all, you need to have a TeX distribution. Just download and install [MikTeX](https://miktex.org/) or [TeX Live](https://tug.org/texlive/). Other TeX distirbution is also available.
48
48
 
49
49
  Then, install jekyll-t4j like other Jekyll plugins. Add this line to your application's Gemfile:
50
50
 
@@ -1,48 +1,52 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "tmpdir"
4
- require "open3"
5
4
 
6
5
  module Jekyll::T4J
7
6
  module Engine
8
- @@_dvisvgm_tex_ = File.join(__dir__, "dvisvgm.tex")
7
+ @@_pwd_fmt_ = nil
8
+
9
+ def self.setup_dvisvgm
10
+ if not @@_pwd_fmt_ then
11
+ @@_pwd_fmt_ = Dir.mktmpdir
12
+ at_exit {FileUtils.remove_entry @@_pwd_fmt_}
13
+
14
+ # write 'preamble.tex'
15
+ File.write "#{@@_pwd_fmt_}/preamble.tex", <<~HD
16
+ \\documentclass{article}
17
+ #{Jekyll::T4J.cfg_pkgs}
18
+ \\input{#{File.join(__dir__, "dvisvgm.tex")}}
19
+ \\pagenumbering{gobble}
20
+ \\dump
21
+ HD
22
+
23
+ # call 'latex' to precompile
24
+ shell("latex -ini -halt-on-error -jobname=\"preamble\" \"&latex preamble\"", @@_pwd_fmt_)
25
+ end
26
+ end
9
27
 
10
28
  def self.dvisvgm_raw(snippet)
11
29
  dvisvgm_raw_bulk([snippet])[0]
12
30
  end
13
31
 
14
32
  def self.dvisvgm_raw_bulk(snippets)
15
- # setup: create 'content.tex'
33
+ # create 'content.tex'
16
34
  pwd = Dir.mktmpdir
17
- File.write "#{pwd}/content.tex", <<~HEREDOC
18
- \\documentclass{article}
19
- #{Jekyll::T4J.cfg_pkgs}
20
- \\input{#{@@_dvisvgm_tex_}}
35
+ File.write "#{pwd}/content.tex", <<~HD
21
36
  \\begin{document}
22
- \\pagenumbering{gobble}
23
37
  \\begingroup#{snippets.join("\\endgroup\\newpage\\begingroup")}\\endgroup
24
38
  \\end{document}
25
- HEREDOC
26
-
27
- shell = ->(cmd) {
28
- log, s = Open3.capture2e(cmd, :chdir => pwd)
29
- raise log if not s.success?
30
- }
39
+ HD
31
40
 
32
41
  # call 'latex' to compile: tex->dvi
33
- shell.("latex -halt-on-error -quiet content")
34
- shell.("latex -halt-on-error -quiet content")
42
+ shell("latex --fmt=\"#{File.join(@@_pwd_fmt_, "preamble.fmt")}\" -halt-on-error content", pwd, 2)
35
43
  # call 'dvisvgm' to convert dvi to svg(s)
36
- shell.("dvisvgm -n -e -p 1- -v 3 content")
44
+ shell("dvisvgm -n -e -p 1- -o %1p content", pwd)
37
45
 
38
46
  # fetch results
39
47
  results = []
40
- if snippets.size == 1 then
41
- results << File.read("#{pwd}/content.svg")
42
- else
43
- for i in 1..snippets.size
44
- results << File.read("#{pwd}/content-#{i.to_s}.svg")
45
- end
48
+ for i in 1..snippets.size
49
+ results << File.read("#{pwd}/#{i.to_s}.svg")
46
50
  end
47
51
 
48
52
  # return