jekyll-t4j 0.2.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -18
- data/lib/jekyll-t4j/engine/dvisvgm.rb +58 -0
- data/lib/jekyll-t4j/engine/dvisvgm.tex +8 -0
- data/lib/jekyll-t4j/engine/katex.js +1 -0
- data/lib/jekyll-t4j/engine/katex.mhchem.js +1 -0
- data/lib/jekyll-t4j/engine/katex.rb +28 -0
- data/lib/jekyll-t4j/engine.rb +138 -0
- data/lib/jekyll-t4j/merger.rb +18 -34
- data/lib/jekyll-t4j/renderer.rb +69 -31
- data/lib/jekyll-t4j/version.rb +1 -1
- data/lib/jekyll-t4j.rb +13 -9
- metadata +25 -13
- data/lib/jekyll-t4j/engines/dvisvgm.rb +0 -32
- data/lib/jekyll-t4j/engines.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a1870ef42a1f2b51f55427bf9fc304e59224e0d473c9f1e0c43297ad2347709
|
4
|
+
data.tar.gz: 47330b060c44e1850c8691d2d88e302483c4069bf166b6f9dd4720b92170275b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0842f23b676c35dfdbca726b144c243c0331d56200833af4e47c61210a5b833d0e86cd02cfd022f34b69b0af24272d46630e50521da98125343640115c22c66
|
7
|
+
data.tar.gz: 16d051b87d412c97fa69ed6222aadd4367506733b39963ccd91896f15a7eb8874b761bdd3db3bce4c2a3c1d8cc0e6445c5039eba1c14c2fe67d2e430dc3e2e5a
|
data/README.md
CHANGED
@@ -1,12 +1,18 @@
|
|
1
1
|
# Jekyll::T4J
|
2
2
|
|
3
|
-
jekyll-t4j is a
|
3
|
+
jekyll-t4j is a Jekyll plugin providing (nearly) full support of LaTeX.
|
4
|
+
|
5
|
+
- **Comprehensive**: support almost all packages, including tikz, chemfig, etc.
|
6
|
+
- **Fast**: employ KaTeX to boost speed. Use cache, precompiled preamble, bulk rendering.
|
7
|
+
- **Server side rendering**: all stuffs are done in server.
|
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.
|
4
10
|
|
5
11
|
Feel free to write any LaTeX! 🎉
|
6
12
|
|
7
|
-
##
|
13
|
+
## Getting Started
|
8
14
|
|
9
|
-
|
15
|
+
Let's start by a simple instance, write a post `2023-02-04-hello-latex.md` and fill it with:
|
10
16
|
|
11
17
|
```
|
12
18
|
---
|
@@ -15,14 +21,16 @@ title: Hello LaTeX
|
|
15
21
|
date: 2023-02-04 14:53:32 +0800
|
16
22
|
---
|
17
23
|
|
18
|
-
This is an inline math
|
24
|
+
This is an inline math $r=\sqrt{x^2+y^2}$.
|
19
25
|
|
20
26
|
$$\chemfig{*6((--[::-60]HO)-=(-O-[:30])-(-OH)=-=)}$$
|
21
27
|
|
22
28
|
And this is vanillyl alcohol.
|
23
29
|
```
|
24
30
|
|
25
|
-
|
31
|
+
As you can see, its usage is the same as KaTeX or MathJax, but we only allow delimiters `$...$`, `$$...$$`, `\(...\)`, `\[...\]`.
|
32
|
+
|
33
|
+
Because we use the chemfig package, so open your `_config.yml` file and write:
|
26
34
|
|
27
35
|
```yaml
|
28
36
|
t4j:
|
@@ -32,23 +40,13 @@ t4j:
|
|
32
40
|
|
33
41
|
Finally, build your site, complete!
|
34
42
|
|
35
|
-
|
36
|
-
|
37
|
-
As shown above, you can configuire jekyll-t4j via `_config.yml`. Here is the template:
|
38
|
-
|
39
|
-
```yaml
|
40
|
-
t4j:
|
41
|
-
packages:
|
42
|
-
- pkgA
|
43
|
-
- pkgB[xxx] # 'xxx' is the option passed to 'pkgB'
|
44
|
-
- pkgC
|
45
|
-
```
|
43
|
+
You can learn more about T4J [here](https://github.com/crow02531/jekyll-t4j/wiki).
|
46
44
|
|
47
45
|
## Installation
|
48
46
|
|
49
|
-
First of all, you need to have a TeX distribution. Just download and install [MikTeX](https://miktex.org/) or [
|
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.
|
50
48
|
|
51
|
-
Then, install jekyll-t4j
|
49
|
+
Then, install jekyll-t4j like other Jekyll plugins. Add this line to your application's Gemfile:
|
52
50
|
|
53
51
|
```ruby
|
54
52
|
gem 'jekyll-t4j'
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "tmpdir"
|
4
|
+
|
5
|
+
module Jekyll::T4J
|
6
|
+
module Engine
|
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
|
27
|
+
|
28
|
+
def self.dvisvgm_raw(snippet)
|
29
|
+
dvisvgm_raw_bulk([snippet])[0]
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.dvisvgm_raw_bulk(snippets)
|
33
|
+
# create 'content.tex'
|
34
|
+
pwd = Dir.mktmpdir
|
35
|
+
File.write "#{pwd}/content.tex", <<~HD
|
36
|
+
\\begin{document}
|
37
|
+
\\begingroup#{snippets.join("\\endgroup\\newpage\\begingroup")}\\endgroup
|
38
|
+
\\end{document}
|
39
|
+
HD
|
40
|
+
|
41
|
+
# call 'latex' to compile: tex->dvi
|
42
|
+
shell("latex --fmt=\"#{File.join(@@_pwd_fmt_, "preamble.fmt")}\" -halt-on-error content", pwd, 2)
|
43
|
+
# call 'dvisvgm' to convert dvi to svg(s)
|
44
|
+
shell("dvisvgm -n -e -p 1- -o %1p content", pwd)
|
45
|
+
|
46
|
+
# fetch results
|
47
|
+
results = []
|
48
|
+
for i in 1..snippets.size
|
49
|
+
results << File.read("#{pwd}/#{i.to_s}.svg")
|
50
|
+
end
|
51
|
+
|
52
|
+
# return
|
53
|
+
results
|
54
|
+
ensure
|
55
|
+
FileUtils.remove_entry pwd if pwd
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|