jektex 0.0.8 → 0.1.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: 9405c84a9c1c4d137d5f9fe152943a72613a52fb741ea8dc3074c64368257b77
4
- data.tar.gz: fcf023964df85b84be1ebab055fd778f923a63e3857facc083e451370168b366
3
+ metadata.gz: a428ba8f2f9f71ee79b44ed698d5314bf89e240eb577f82a1e0e976878875f2b
4
+ data.tar.gz: 3db9e56ab288eec2e3f9457b4693851b0345f1ec7afabeaabaeba6884aa1c792
5
5
  SHA512:
6
- metadata.gz: 1fda6a4eda19f919edc732da120ccfe2a20c520476465d53d79a98eb80087d94b438a84b863194009213781f5b15d180a5e7b22a6ca1eeb35e4bf3676da709c2
7
- data.tar.gz: 7f3bd08cb26988e28c5ff910148404dcc0dee7f83478bbd04786aa5bf73ca5ea50fc93117e536c417549cb98f2192a27b20bdea99e598d3fcc15b49ef9b71208
6
+ metadata.gz: '058eeb45c2e9c2bea5b8294084732d6c4b54e7344c360338bb62f6c9e5a8b2c55e99507be1de78cde4b81a14781a68ee4f530253e90980398ce4ea7c0da418ec'
7
+ data.tar.gz: b6de46d7eb8f639bb7c06ebd0f7aea6df75647d4f8c930fc779d580ec21c33bfa01c9fd909b0cc577c8862310df58c3e59680271ebba99fc95e9e403659bd345
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/jektex.svg)](https://rubygems.org/gems/jektex)
2
2
 
3
- # Jektex
3
+ # ![Jektex](https://blackblog.cz/assets/img/projects/jektex.svg)
4
4
  A Jekyll plugin for blazing-fast server-side cached LaTeX rendering, with support for macros.
5
5
  Enjoy the comfort of LaTeX and Markdown without cluttering your site with bloated JavaScript.
6
6
 
@@ -16,9 +16,9 @@ Enjoy the comfort of LaTeX and Markdown without cluttering your site with bloate
16
16
  - Marks invalid expressions in document, printing its location during rendering
17
17
  - Is highly configurable with sensible defaults
18
18
  - Makes sure that cache does not contain expression rendered with outdated configuration
19
+ - Supports two major LaTeX notations
19
20
 
20
21
  ## Usage
21
-
22
22
  Jektex supports both the built-in Kramdown math notation, and the newer LaTeX-only math notation.
23
23
 
24
24
  ### Kramdown notation
@@ -43,7 +43,7 @@ ea commodo consequat.
43
43
 
44
44
  _Why Jektex does not use conventional single `$` for inline formulas and double `$$` for
45
45
  display mode?
46
- This is how [kramdown](https://kramdown.gettalong.org/)(Jekyll's markdown parser) works
46
+ This is how [kramdown](https://kramdown.gettalong.org/) (Jekyll's markdown parser) works
47
47
  so I decided to respect this convention. It makes this plugin more consistent and universal._
48
48
 
49
49
 
@@ -69,6 +69,9 @@ Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliqu
69
69
  ea commodo consequat.
70
70
  ```
71
71
 
72
+ ### Logo macro
73
+ There is a build in macro for jektex logo. You can use it as `\jektex`.
74
+
72
75
  ### Config
73
76
  Jektex si highly configurable via your `_config.yml` file.
74
77
 
@@ -82,7 +85,6 @@ By default, Jektex cache will be saved in `.jekyll-cache` directory.
82
85
  This results in its deletion when you call `jekyll clean`.
83
86
  To prevent cache deletion or to change the cache location, you can specify `cache_dir` in `_config.yml`:
84
87
  ```yaml
85
- # Jektex cache dir location
86
88
  jektex:
87
89
  cache_dir: ".jektex-cache"
88
90
  ```
@@ -92,7 +94,6 @@ By default, Jektex tries to render LaTeX in all files rendered by Jekyll.
92
94
  This can sometimes be undesirable, for example when rendering an _RSS feed_ with excerpts containing LaTeX.
93
95
  Jektex solves this by using the `ignore` option:
94
96
  ```yaml
95
- # Jektex ignore files
96
97
  jektex:
97
98
  ignore: ["*.xml", "README.md", "_drafts/*" ]
98
99
  ```
@@ -103,7 +104,7 @@ This example configuration ignores all `.xml` files, `README.md` and all files i
103
104
  Another way to ignore specific posts is setting the `jektex` attribute in front matter to `false`:
104
105
  ```yaml
105
106
  ---
106
- ttle: "How Jektex works"
107
+ title: "How Jektex works"
107
108
  category: "Development"
108
109
  jektex: false
109
110
  layout: post
@@ -115,7 +116,6 @@ Setting `jektex` tag to `true` or not setting at all will result in Jektex rende
115
116
  **Using macros**
116
117
  You can define global macros:
117
118
  ```yaml
118
- # Jektex macros
119
119
  jektex:
120
120
  macros:
121
121
  - ["\\Q", "\\mathbb{Q}"]
@@ -124,12 +124,21 @@ jektex:
124
124
  And yes, you have to escape the backlash (`\`) with another backlash.
125
125
  This is due to the [yaml specification](https://yaml.org/).
126
126
 
127
+ **Silencing Jektex output**
128
+ Jektex periodically informs the user about rendered/cached equations.
129
+ If this is not desired, you can set the `silent` option (`false` by default).
130
+ ```yaml
131
+ jektex:
132
+ silent: true
133
+ ```
134
+
127
135
  **Complete examples**
128
136
  Recommended config:
129
137
  ```yaml
130
138
  jektex:
131
139
  cache_dir: ".jektex-cache"
132
140
  ignore: ["*.xml"]
141
+ silent: false
133
142
  macros:
134
143
  - ["\\Q", "\\mathbb{Q}"]
135
144
  - ["\\C", "\\mathbb{C}"]
@@ -140,6 +149,7 @@ Having no configuration is equivalent to this:
140
149
  jektex:
141
150
  cache_dir: ".jekyll-cache"
142
151
  ignore: []
152
+ silent: false
143
153
  macros: []
144
154
  ```
145
155
 
@@ -174,6 +184,6 @@ It is much better practice to download the [**css** file](https://cdn.jsdelivr.n
174
184
  You can find more information on [KaTeX's website](https://katex.org/docs/browser.html).
175
185
 
176
186
  ## Contributions and bug reports
177
- Feel free to repost any bugs or even make feature request in [issues on official repository](https://github.com/yagarea/jektex/issues).
187
+ Feel free to report any bugs or even make feature request in [issues on official repository](https://github.com/yagarea/jektex/issues).
178
188
  I am opened for pull requests as well.
179
189
 
data/lib/jektex/jektex.rb CHANGED
@@ -9,6 +9,7 @@ CACHE_FILE = "jektex-cache.marshal"
9
9
  KATEX = ExecJS.compile(open(PATH_TO_JS).read)
10
10
  FRONT_MATTER_TAG = "jektex"
11
11
  INDENT = " " * 13
12
+ HTML_ENTITY_PARSER = HTMLEntities.new
12
13
 
13
14
  $global_macros = Hash.new
14
15
  $updated_global_macros = Array.new
@@ -18,6 +19,7 @@ $count_newly_generated_expressions = 0
18
19
  $path_to_cache = File.join(DEFAULT_CACHE_DIR, CACHE_FILE)
19
20
  $cache = nil
20
21
  $disable_disk_cache = false
22
+ $silent = false
21
23
 
22
24
  $ignored = Array.new
23
25
 
@@ -54,7 +56,7 @@ def render_latex_notation(page)
54
56
  # check if document is not set to be ignored
55
57
  return page.content if !page.data || is_ignored?(page)
56
58
  # convert HTML entities back to characters
57
- post = HTMLEntities.new.decode(page.content.to_s)
59
+ post = page.content.to_s
58
60
  # render inline expressions
59
61
  post = post.gsub(/(\\\()((.|\n)*?)(?<!\\)\\\)/) { |m| escape_method($1, $2, page.relative_path) }
60
62
  # render display mode expressions
@@ -66,7 +68,7 @@ def render_kramdown_notation(page)
66
68
  # check if document is not set to be ignored
67
69
  return page.output if !page.data || is_ignored?(page)
68
70
  # convert HTML entities back to characters
69
- post = HTMLEntities.new.decode(page.output.to_s)
71
+ post = page.output.to_s
70
72
  # render inline expressions
71
73
  post = post.gsub(/(\\\()((.|\n)*?)(?<!\\)\\\)/) { |m| escape_method($1, $2, page.relative_path) }
72
74
  # render display mode expressions
@@ -74,10 +76,10 @@ def render_kramdown_notation(page)
74
76
  return post
75
77
  end
76
78
 
77
- def escape_method( type, expression, doc_path )
79
+ def escape_method(type, expression, doc_path)
78
80
  # detect if expression is in display mode
79
81
  is_in_display_mode = type.downcase =~ /\[/
80
-
82
+ expression = HTML_ENTITY_PARSER.decode(expression)
81
83
  # generate a hash from the math expression
82
84
  expression_hash = Digest::SHA2.hexdigest(expression) + is_in_display_mode.to_s
83
85
 
@@ -85,7 +87,7 @@ def escape_method( type, expression, doc_path )
85
87
  if($cache.has_key?(expression_hash) && !contains_updated_global_macro?(expression))
86
88
  # check if expressin conains updated macro
87
89
  $count_newly_generated_expressions += 1
88
- print_stats
90
+ print_stats unless $silent
89
91
  return $cache[expression_hash]
90
92
 
91
93
  # else generate one and store it
@@ -104,7 +106,7 @@ def escape_method( type, expression, doc_path )
104
106
  raise
105
107
  rescue ExecJS::ProgramError => pe
106
108
  # catch parse error
107
- puts "\e[31m #{pe.message.gsub("ParseError: ", "")}\n\t#{doc_path}\e[0m"
109
+ puts "\e[31m #{pe.message.gsub("ParseError: ", "")}\n\t#{doc_path}\e[0m" unless $silent
108
110
  # render expression with error highlighting enabled
109
111
  return KATEX.call("katex.renderToString", expression,
110
112
  { displayMode: is_in_display_mode,
@@ -116,7 +118,7 @@ def escape_method( type, expression, doc_path )
116
118
  $cache[expression_hash] = result
117
119
  # update count of newly generated expressions
118
120
  $count_newly_generated_expressions += 1
119
- print_stats
121
+ print_stats unless $silent
120
122
  return result
121
123
  end
122
124
  end
@@ -145,7 +147,7 @@ Jekyll::Hooks.register :site, :after_init do |site|
145
147
  config = site.config["jektex"] || Hash.new
146
148
 
147
149
  # check if there is defined custom cache location in config
148
- $path_to_cache = File.join(config["cache_dir"].to_s, CACHE_FILE) if config.has_key?("cache_dir")
150
+ $path_to_cache = File.join(config["cache_dir"].to_s, CACHE_FILE) if config.has_key?("cache_dir")
149
151
 
150
152
  # load content of cache file if it exists
151
153
  if File.exist?($path_to_cache)
@@ -164,19 +166,29 @@ Jekyll::Hooks.register :site, :after_init do |site|
164
166
  end
165
167
  end
166
168
 
169
+ # check is silent mode is activated
170
+ $silent = config["silent"] if config.has_key?("silent")
167
171
  # make list of updated macros
168
172
  $updated_global_macros = get_list_of_updated_global_macros($global_macros, $cache["cached_global_macros"])
173
+
169
174
  # print macro information
170
- if $global_macros.empty?
171
- puts "#{INDENT}LaTeX: no macros loaded"
172
- else
173
- puts "#{INDENT}LaTeX: #{$global_macros.size} macro" \
174
- "#{$global_macros.size == 1 ? "" : "s"} loaded" +
175
- ($updated_global_macros.empty? ? "" : " (#{$updated_global_macros.size} updated)")
175
+ unless $silent
176
+ if $global_macros.empty?
177
+ puts "#{INDENT}LaTeX: no macros loaded" unless $silent
178
+ else
179
+ puts "#{INDENT}LaTeX: #{$global_macros.size} macro" \
180
+ "#{$global_macros.size == 1 ? "" : "s"} loaded" +
181
+ ($updated_global_macros.empty? ? "" : " (#{$updated_global_macros.size} updated)") unless $silent
182
+ end
176
183
  end
177
184
 
185
+ # add jektex logo macro
186
+ $global_macros['\jektex'] =
187
+ '\text{\raisebox{-0.55ex}{J}\kern{-0.3ex}E\kern{-0.25ex}\raisebox{-0.5ex}{K}\kern{-0.7ex}}\TeX'
188
+
178
189
  # load list of ignored files
179
190
  $ignored = config["ignore"] if config.has_key?("ignore")
191
+ $ignored.append("#{$path_to_cache}/*")
180
192
  end
181
193
 
182
194
  Jekyll::Hooks.register :site, :after_reset do
@@ -186,9 +198,9 @@ end
186
198
 
187
199
  Jekyll::Hooks.register :site, :post_write do
188
200
  # print stats once more to prevent them from being overwriten by error log
189
- print_stats
201
+ print_stats unless $silent
190
202
  # print new line to prevent overwriting previous output
191
- print "\n"
203
+ print "\n" unless $silent
192
204
  # check if caching is enabled
193
205
  if !$disable_disk_cache
194
206
  # save global macros to cache
@@ -200,3 +212,4 @@ Jekyll::Hooks.register :site, :post_write do
200
212
  end
201
213
  end
202
214
 
215
+