jektex 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +72 -23
- data/lib/jektex/jektex.rb +47 -15
- data/lib/jektex/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 290626aa91c28cc4961baf40ec00dde81928da68e0a923ee84999027e7f3c9b0
|
4
|
+
data.tar.gz: 4ec8d501a4ab6f1b068ec01bb21a7d84bd844a5bca7d105bdc0c9c6e2652eec8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccdddba235b4d0462ccb5e4d2ee4cbf5b97e9964c10fd0395e814635281563c6363a381422feeefdd9eb6a895877a47aba6fae95de36c98a6f710785ed18ba51
|
7
|
+
data.tar.gz: 4d0a8dad642c30c5f26ca5903d715e3728d918bb17fe1eaeaf3ce8ad814a25e9c50d0df15533522275665978971ee269164a2969cf73db9823b71b9ea29a7217
|
data/README.md
CHANGED
@@ -13,7 +13,6 @@ Enjoy comfort of latex and markdown without cluttering your site with bloated ja
|
|
13
13
|
- Does not interfere with Jekyll workflow and project structure
|
14
14
|
- Marks invalid syntax in document
|
15
15
|
- Prints location of invalid expression during rendering
|
16
|
-
- Tags places within the rendered documents with syntax errors
|
17
16
|
- Highly configurable but still having sensible defaults
|
18
17
|
|
19
18
|
## Usage
|
@@ -21,7 +20,6 @@ Enjoy comfort of latex and markdown without cluttering your site with bloated ja
|
|
21
20
|
### Notation
|
22
21
|
**Inline formula**
|
23
22
|
Put formula between two pairs of dolar signs (`$$`) inside of paragraph.
|
24
|
-
|
25
23
|
```latex
|
26
24
|
Lorem ipsum dolor sit amet, consectetur $$e^{i\theta}=\cos(\theta)+i\sin(\theta)$$
|
27
25
|
adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
@@ -44,40 +42,88 @@ display mode?
|
|
44
42
|
This is how [kramdown](https://kramdown.gettalong.org/)(Jekyll's markdown parser) works
|
45
43
|
so I decided to respect this convention. It makes this plugin more consistent and universal._
|
46
44
|
|
47
|
-
###
|
48
|
-
|
45
|
+
### Config
|
46
|
+
Jektex si highly configurable from your `_config.yml` file
|
47
|
+
|
48
|
+
**Disabling cache**
|
49
|
+
You can disable caching with `disable_disk_cache = true` in `_config.yml`. Cache is
|
50
|
+
enabled by default. You can find more information on [Jekyll official website](https://jekyllrb.com/docs/configuration/options/).
|
49
51
|
|
52
|
+
**Setting cache location**
|
53
|
+
By default jektex cache will be saved in `.jekyll-cache` directory. This results in it's
|
54
|
+
deletion when you call `jekyll clean`. To prevent cache deletion or you just want to
|
55
|
+
change location of cache for another reason you can achieve that by specifying
|
56
|
+
`cache_dir` in `_config.yml`.
|
50
57
|
```yaml
|
51
|
-
# Jektex
|
52
|
-
jektex
|
53
|
-
|
54
|
-
- ["\\C", "\\mathbb{C}"]
|
58
|
+
# Jektex cache dir location
|
59
|
+
jektex:
|
60
|
+
cache_dir: ".jektex-cache"
|
55
61
|
```
|
56
62
|
|
57
|
-
|
63
|
+
**Ignore**
|
64
|
+
By default jektex tries to render LaTeX in all files not excluded by Jekyll. But
|
65
|
+
sometimes you get in situation when you do not want to render some files. For example
|
66
|
+
_RSS feed_ with excerpts containing LaTeX. As a solution jektex offers `ignore` option.
|
67
|
+
You can use conventional wild cards using `*`. For example:
|
68
|
+
```yaml
|
69
|
+
# Jektex ignore files
|
70
|
+
jektex:
|
71
|
+
ignore: ["*.xml", "README.md", "_drafts/*" ]
|
72
|
+
```
|
58
73
|
|
59
|
-
|
60
|
-
|
61
|
-
project directory.
|
74
|
+
This example configuration ignores all `.xml` files, `README.md` and all files
|
75
|
+
in `_drafts` directory.
|
62
76
|
|
63
|
-
|
64
|
-
|
65
|
-
|
77
|
+
Another option for ignoring specific posts is setting `jektex` tag in front matter of
|
78
|
+
post to `false`. For example:
|
79
|
+
```yaml
|
80
|
+
---
|
81
|
+
title: "How Jektex works"
|
82
|
+
category: "Development"
|
83
|
+
jektex: false
|
84
|
+
layout: post
|
85
|
+
---
|
86
|
+
```
|
66
87
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
88
|
+
Setting `jektex` tag to `true` or not setting at all will result in jektex rendering LaTeX
|
89
|
+
expressions in that post.
|
90
|
+
|
91
|
+
**Macros**
|
92
|
+
You can define global macros like this:
|
93
|
+
```yaml
|
94
|
+
# Jektex macros
|
95
|
+
jektex:
|
96
|
+
macros:
|
97
|
+
- ["\\Q", "\\mathbb{Q}"]
|
98
|
+
- ["\\C", "\\mathbb{C}"]
|
99
|
+
```
|
100
|
+
And yes you have to escape backlash(`\`) with another backlash. This is caused by
|
101
|
+
[yaml definition](https://yaml.org/). YOU SHOULD ALWAYS delete jektex cache after changing
|
102
|
+
definition of a macro for change to take effect.
|
72
103
|
|
73
|
-
|
104
|
+
**Complete examples**
|
105
|
+
Recommended config:
|
106
|
+
```yaml
|
107
|
+
jektex:
|
108
|
+
cache_dir: ".jektex-cache"
|
109
|
+
ignore: ["*.xml"]
|
110
|
+
macros:
|
111
|
+
- ["\\Q", "\\mathbb{Q}"]
|
112
|
+
- ["\\C", "\\mathbb{C}"]
|
113
|
+
```
|
114
|
+
Having no configuration is equivalent to this:
|
115
|
+
```yaml
|
116
|
+
jektex:
|
117
|
+
cache_dir: ".jekyll-cache"
|
118
|
+
ignore: []
|
119
|
+
macros: []
|
120
|
+
```
|
74
121
|
|
75
122
|
## Installation
|
76
123
|
This plugin is available as a [RubyGem](https://rubygems.org/gems/jektex).
|
77
124
|
|
78
125
|
**Using bundler**
|
79
126
|
Add `jektex` to your `Gemfile` like this:
|
80
|
-
|
81
127
|
```ruby
|
82
128
|
group :jekyll_plugins do
|
83
129
|
gem "jektex"
|
@@ -100,6 +146,9 @@ and do not forget to add `katex.min.css` to you html head:
|
|
100
146
|
```html
|
101
147
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.15.2/dist/katex.min.css" integrity="sha384-MlJdn/WNKDGXveldHDdyRP1R4CTHr3FeuDNfhsLPYrq2t0UBkUdK2jyTnXPEK1NQ" crossorigin="anonymous">
|
102
148
|
```
|
103
|
-
It is much better practice to download **css** file and
|
149
|
+
It is much better practice to download **css** file and load it as an asset from your server directly.
|
104
150
|
You can find more information on [KaTeX's website](https://katex.org/docs/browser.html).
|
105
151
|
|
152
|
+
## Contributions and bug reports
|
153
|
+
Feel free to repost any bugs or even make feature request in [issues on official repository](https://github.com/yagarea/jektex/issues).
|
154
|
+
I am opened for pull requests as well.
|
data/lib/jektex/jektex.rb
CHANGED
@@ -8,16 +8,34 @@ DEFAULT_CACHE_DIR = ".jekyll-cache"
|
|
8
8
|
CACHE_FILE = "jektex-cache.marshal"
|
9
9
|
KATEX = ExecJS.compile(open(PATH_TO_JS).read)
|
10
10
|
PARSE_ERROR_PLACEHOLDER = "<b style='color: red;'>PARSE ERROR</b>"
|
11
|
+
FRONT_MATTER_TAG = "jektex"
|
11
12
|
$global_macros = Hash.new
|
12
13
|
$count_newly_generated_expressions = 0
|
13
14
|
$path_to_cache = File.join(DEFAULT_CACHE_DIR, CACHE_FILE)
|
14
15
|
$cache = nil
|
15
16
|
$disable_disk_cache = false
|
17
|
+
$ignored = Array.new
|
18
|
+
|
19
|
+
def is_ignored?(page)
|
20
|
+
for patern in $ignored
|
21
|
+
if File.fnmatch?(patern, page.relative_path, File::FNM_DOTMATCH) then
|
22
|
+
return true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
return false
|
26
|
+
end
|
27
|
+
|
28
|
+
def render(page)
|
29
|
+
# check if document is not set to be ignored
|
30
|
+
if page.data == nil or is_ignored?(page) or page.data[FRONT_MATTER_TAG] == "false" then
|
31
|
+
return page.output
|
32
|
+
end
|
16
33
|
|
17
|
-
def convert(page)
|
18
34
|
# convert HTML entities back to characters
|
19
35
|
post = HTMLEntities.new.decode(page.output.to_s)
|
36
|
+
# render inline expressions
|
20
37
|
post = post.gsub(/(\\\()((.|\n)*?)(?<!\\)\\\)/) { |m| escape_method($1, $2, page.path) }
|
38
|
+
# render display expressions
|
21
39
|
post = post.gsub(/(\\\[)((.|\n)*?)(?<!\\)\\\]/) { |m| escape_method($1, $2, page.path) }
|
22
40
|
return post
|
23
41
|
end
|
@@ -52,7 +70,7 @@ def escape_method( type, string, doc_path )
|
|
52
70
|
rescue SystemExit, Interrupt
|
53
71
|
# save cache to disk
|
54
72
|
File.open($path_to_cache, "w"){|to_file| Marshal.dump($cache, to_file)}
|
55
|
-
# this stops jekyll being immune to
|
73
|
+
# this stops jekyll being immune to interrupts and kill command
|
56
74
|
raise
|
57
75
|
rescue Exception => e
|
58
76
|
# catch parse error
|
@@ -77,44 +95,58 @@ def print_stats
|
|
77
95
|
end
|
78
96
|
|
79
97
|
Jekyll::Hooks.register :pages, :post_render do |page|
|
80
|
-
page.output =
|
98
|
+
page.output = render(page)
|
81
99
|
end
|
82
100
|
|
83
101
|
Jekyll::Hooks.register :documents, :post_render do |doc|
|
84
|
-
doc.output =
|
102
|
+
doc.output = render(doc)
|
85
103
|
end
|
86
104
|
|
87
105
|
Jekyll::Hooks.register :site, :after_init do |site|
|
88
|
-
|
89
|
-
|
90
|
-
|
106
|
+
if site.config["jektex"] == nil then
|
107
|
+
# if no config is defined make empty one
|
108
|
+
config = Hash.new
|
109
|
+
else
|
110
|
+
# load jektex config from config file
|
111
|
+
config = site.config["jektex"]
|
112
|
+
end
|
113
|
+
# load macros
|
114
|
+
if config["macros"] != nil then
|
115
|
+
for macro_definition in config["macros"]
|
91
116
|
$global_macros[macro_definition[0]] = macro_definition[1]
|
92
117
|
end
|
93
118
|
end
|
119
|
+
|
94
120
|
# print macro information
|
95
|
-
if $global_macros.size == 0
|
121
|
+
if $global_macros.size == 0 then
|
96
122
|
puts " LaTeX: no macros loaded"
|
97
123
|
else
|
98
124
|
puts " LaTeX: " + $global_macros.size.to_s + " macro" +
|
99
125
|
($global_macros.size == 1 ? "" : "s") + " loaded"
|
100
126
|
end
|
101
127
|
|
102
|
-
# check if
|
103
|
-
if
|
104
|
-
$
|
128
|
+
# check if there is defined custom cache location in config
|
129
|
+
if config["cache_dir"] != nil then
|
130
|
+
$path_to_cache = File.join(config["cache_dir"].to_s, CACHE_FILE)
|
105
131
|
end
|
106
132
|
|
107
|
-
#
|
108
|
-
if
|
109
|
-
$
|
133
|
+
# load list of ignored files
|
134
|
+
if config["ignore"] != nil then
|
135
|
+
$ignored = config["ignore"]
|
110
136
|
end
|
111
137
|
|
112
138
|
# load content of cache file if it exists
|
113
|
-
if(File.exist?($path_to_cache))
|
139
|
+
if(File.exist?($path_to_cache)) then
|
114
140
|
$cache = File.open($path_to_cache, "r"){|from_file| Marshal.load(from_file)}
|
115
141
|
else
|
116
142
|
$cache = Hash.new
|
117
143
|
end
|
144
|
+
|
145
|
+
# check if cache is disable in config
|
146
|
+
if site.config["disable_disk_cache"] != nil then
|
147
|
+
$disable_disk_cache = site.config["disable_disk_cache"]
|
148
|
+
end
|
149
|
+
|
118
150
|
end
|
119
151
|
|
120
152
|
Jekyll::Hooks.register :site, :after_reset do
|
data/lib/jektex/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jektex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Černý
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: execjs
|