jekyll-t4j 0.2.2 → 0.3.0
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/README.md +15 -17
- data/lib/jekyll-t4j/engine/dvisvgm.rb +54 -0
- data/lib/jekyll-t4j/engine/dvisvgm.tex +8 -0
- data/lib/jekyll-t4j/engine/katex.js +18798 -0
- data/lib/jekyll-t4j/engine/katex.rb +19 -0
- data/lib/jekyll-t4j/engine.rb +118 -0
- data/lib/jekyll-t4j/merger.rb +18 -34
- data/lib/jekyll-t4j/renderer.rb +68 -31
- data/lib/jekyll-t4j/version.rb +1 -1
- data/lib/jekyll-t4j.rb +11 -10
- metadata +26 -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: 4f7546786489dba969477bac00c45f4e89d15fefe3f875e2567b725d86c81673
|
4
|
+
data.tar.gz: 8145c980e01d7bae20bf611957a61073602789c07f070248c9c85465b241ddaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 363df4ceb85c4e053571d6593b87009c1c79a404cb109d16f85a3f2b1325e3155bb86c0eb18f0b4780741d390994069b6608fc326fd73915c8fc58c4c84b3821
|
7
|
+
data.tar.gz: be623b5331e9e492f6484db617290c8c0f05416040613fb90da3e6dd7794dcf8b75d948a480809fa56da7b31888c4f13eaa286ea6a6a1dc17476b47962a09a5f
|
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, 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
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/).
|
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,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "tmpdir"
|
4
|
+
require "open3"
|
5
|
+
|
6
|
+
module Jekyll::T4J
|
7
|
+
module Engine
|
8
|
+
@@_dvisvgm_tex_ = File.join(__dir__, "dvisvgm.tex")
|
9
|
+
|
10
|
+
def self.dvisvgm_raw(snippet)
|
11
|
+
dvisvgm_raw_bulk([snippet])[0]
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.dvisvgm_raw_bulk(snippets)
|
15
|
+
# setup: create 'content.tex'
|
16
|
+
pwd = Dir.mktmpdir
|
17
|
+
File.write "#{pwd}/content.tex", <<~HEREDOC
|
18
|
+
\\documentclass{article}
|
19
|
+
#{Jekyll::T4J.cfg_pkgs}
|
20
|
+
\\input{#{@@_dvisvgm_tex_}}
|
21
|
+
\\begin{document}
|
22
|
+
\\pagenumbering{gobble}
|
23
|
+
\\begingroup#{snippets.join("\\endgroup\\newpage\\begingroup")}\\endgroup
|
24
|
+
\\end{document}
|
25
|
+
HEREDOC
|
26
|
+
|
27
|
+
shell = ->(cmd) {
|
28
|
+
log, s = Open3.capture2e(cmd, :chdir => pwd)
|
29
|
+
raise log if not s.success?
|
30
|
+
}
|
31
|
+
|
32
|
+
# call 'latex' to compile: tex->dvi
|
33
|
+
shell.("latex -halt-on-error -quiet content")
|
34
|
+
shell.("latex -halt-on-error -quiet content")
|
35
|
+
# call 'dvisvgm' to convert dvi to svg(s)
|
36
|
+
shell.("dvisvgm -n -e -p 1- -v 3 content")
|
37
|
+
|
38
|
+
# fetch results
|
39
|
+
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
|
46
|
+
end
|
47
|
+
|
48
|
+
# return
|
49
|
+
results
|
50
|
+
ensure
|
51
|
+
FileUtils.remove_entry pwd if pwd
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|