jektex 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1247953962bc4063d49c80f23be942dba3f4ccbf52bc4f9612efb18ffe863358
4
- data.tar.gz: bad878b76ed57f3c0a720d84bba5625267124287bb7a8b92f079a4ed678ea441
3
+ metadata.gz: daa553320105731fb20840fc40d211a73f576f6847b8b3de0019d72313ac0c97
4
+ data.tar.gz: 4479c3dc694c196845460e4ed63263ad5bb900ed9b3a42fe68e4900001dfccda
5
5
  SHA512:
6
- metadata.gz: 2e859d1186b3aaae9d33cd1bcbfd96822f9d6470304c7ee23404b6ae6741163924caad83346811652e371738e6a6a7b6035e6df21c217ebf5fca3ef933d30d8c
7
- data.tar.gz: ad53f03463c684a321c5a4c43def449a64f18d9ceccf1091004cd0bb5ce73c55dab9edbc29793b92856f9077ba8642de450b4310f97a110d7fa5882d45697f1d
6
+ metadata.gz: 42333a3f6325918d8e1da7c6dd983c3f8404d10b2ae84449076ba768846793ec992af35e6962ebde5c3ae2619dfc2f4c3211370d9c75f6f6883707fbdf355c03
7
+ data.tar.gz: 24849a110d4ac120fcccab47f357d0c74ae8f7d640dbcd21c7741dc7cf88096aaef6afe088b99a486fe9589e6f67afa13703f09f395ad5c157f6b3ee542c8672
data/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
  Jekyll plugin for blazing fast server side cached LaTeX rendering with support of macros.
3
3
  Enjoy comfort of latex and markdown without cluttering your site with bloated javascript.
4
4
 
5
- ## About
5
+ ## Features
6
6
  - Renders LaTeX formulas during Jekyll rendering
7
- - Works without any javascript o clients side
7
+ - Works without any javascript on clients side
8
8
  - Is faster than any other server side Jekyll latex renderer
9
9
  - Supports user defined global macros
10
10
  - Has I/O efficient caching system
@@ -13,12 +13,13 @@ 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
16
17
 
17
18
  ## Usage
18
19
 
19
20
  ### Notation
20
21
  **Inline formula**
21
- Put formula between two pairs of `$` inside of paragraph.
22
+ Put formula between two pairs of dolar signs (`$$`) inside of paragraph.
22
23
 
23
24
  ```latex
24
25
  Lorem ipsum dolor sit amet, consectetur $$e^{i\theta}=\cos(\theta)+i\sin(\theta)$$
@@ -26,12 +27,12 @@ adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliq
26
27
  ```
27
28
 
28
29
  **Display formula**
29
- Put formula between two pairs of `$` and surround it between two empty lines.
30
+ Put formula between two pairs of dolar sings (`$$`) and surround it by two empty lines.
30
31
  ```latex
31
- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
32
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
32
33
  incididunt ut labore et dolore magna aliqua.
33
34
 
34
- $$ i\hbar\frac{\partial}{\partial t} \Psi(\mathbf{r},t) = \left [ \frac{-\hbar^2}{2\mu}\nabla^2 + V(\mathbf{r},t)\right ] \Psi(\mathbf{r},t) $$
35
+ $$ \left[ \frac{-\hbar^2}{2\mu}\nabla^2 + V(\mathbf{r},t)\right] \Psi(\mathbf{r},t) $$
35
36
 
36
37
  Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex
37
38
  ea commodo consequat.
@@ -39,9 +40,8 @@ ea commodo consequat.
39
40
 
40
41
  _Why Jektex does not use conventional single `$` for inline formulas and double `$$` for
41
42
  display mode?
42
- Unfortunately this is how [kramdown](https://kramdown.gettalong.org/)
43
- (Jekyll's markdown parser) works and it would probably do be easier to write custom
44
- markdown parser than hacking kramdown to behave differently._
43
+ This is how [kramdown](https://kramdown.gettalong.org/)(Jekyll's markdown parser) works
44
+ so I decided to respect this convention. It makes this plugin more consistent and universal._
45
45
 
46
46
  ### Macros
47
47
  You can define global macros in your `_config.yml` file:
@@ -49,35 +49,47 @@ You can define global macros in your `_config.yml` file:
49
49
  ```yaml
50
50
  # Jektex macros
51
51
  jektex-macros:
52
- - ["\\Q", "\\mathbb{Q}"]
53
- - ["\\C", "\\mathbb{C}"]
52
+ - ["\\Q", "\\mathbb{Q}"]
53
+ - ["\\C", "\\mathbb{C}"]
54
54
  ```
55
55
 
56
+ ### Cache control
57
+
58
+ **Clearing cache**
59
+ To clear cached expressions you have to delete `.jektex-cache` directory in your
60
+ project directory.
61
+
62
+ **Disabling cache**
63
+ You can disable caching with `disable_disk_cache = false` in `_config.yml`.
64
+
56
65
  ## Installation
66
+ This plugin is available as a [RubyGem](https://rubygems.org/gems/jektex).
57
67
 
58
- ### Using bundler
68
+ **Using bundler**
59
69
  Add `jektex` to your `Gemfile` like this:
60
70
 
61
- ```yaml
71
+ ```ruby
62
72
  group :jekyll_plugins do
63
- gem "jektex"
73
+ gem "jektex"
64
74
  end
65
75
  ```
66
76
 
67
77
  and run `bundle install`
68
78
 
69
- ### Without bundler
70
- Just run `gem install jektex` and add jektex to your plugin list in your `_config.yml`
71
- file:
72
- ```
73
- plugins:
74
- - jektex
79
+ **Without bundler**
80
+ Just run `gem install jektex`
75
81
 
82
+ **After installation**
83
+ Add jektex to your plugin list in your `_config.yml` file:
84
+ ```yaml
85
+ plugins:
86
+ - jektex
76
87
  ```
77
88
 
78
- ### Style sheets
79
- Do not forget to add `katex.min.css` to you html head:
89
+ and do not forget to add `katex.min.css` to you html head:
80
90
  ```html
81
91
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.15.2/dist/katex.min.css" integrity="sha384-MlJdn/WNKDGXveldHDdyRP1R4CTHr3FeuDNfhsLPYrq2t0UBkUdK2jyTnXPEK1NQ" crossorigin="anonymous">
82
92
  ```
83
- It is much better practice to download css file and loaded as an asset from your server directly.
93
+ It is much better practice to download **css** file and loaded as an asset from your server directly.
94
+ You can find more information on [KaTeX's website](https://katex.org/docs/browser.html).
95
+
data/lib/jektex/jektex.rb CHANGED
@@ -14,11 +14,11 @@ $count_newly_generated_expressions = 0
14
14
  $cache = nil
15
15
  $disable_disk_cache = false
16
16
 
17
- def convert(doc)
18
- # convert HTML enetities back to characters
19
- post = HTMLEntities.new.decode(doc.to_s)
20
- post = post.gsub(/(\\\()((.|\n)*?)(?<!\\)\\\)/) { |m| escape_method($1, $2, doc.path) }
21
- post = post.gsub(/(\\\[)((.|\n)*?)(?<!\\)\\\]/) { |m| escape_method($1, $2, doc.path) }
17
+ def convert(page)
18
+ # convert HTML entities back to characters
19
+ post = HTMLEntities.new.decode(page.output.to_s)
20
+ post = post.gsub(/(\\\()((.|\n)*?)(?<!\\)\\\)/) { |m| escape_method($1, $2, page.path) }
21
+ post = post.gsub(/(\\\[)((.|\n)*?)(?<!\\)\\\]/) { |m| escape_method($1, $2, page.path) }
22
22
  return post
23
23
  end
24
24
 
@@ -47,7 +47,7 @@ def escape_method( type, string, doc_path )
47
47
  # create the cache directory, if it doesn't exist
48
48
  begin
49
49
  # render using ExecJS
50
- @result = KATEX.call("katex.renderToString", string,
50
+ @result = KATEX.call("katex.renderToString", string,
51
51
  {displayMode: @display, macros: $global_macros})
52
52
  rescue SystemExit, Interrupt
53
53
  # save cache to disk
@@ -70,14 +70,14 @@ end
70
70
 
71
71
  def print_stats
72
72
  print " LaTeX: " +
73
- ($count_newly_generated_expressions).to_s +
74
- " expressions rendered (" + $cache.size.to_s +
73
+ ($count_newly_generated_expressions).to_s +
74
+ " expressions rendered (" + $cache.size.to_s +
75
75
  " already cached) \r"
76
76
  $stdout.flush
77
77
  end
78
78
 
79
- Jekyll::Hooks.register :documents, :post_render do |doc|
80
- doc.output = convert(doc)
79
+ Jekyll::Hooks.register :pages, :post_render do |page|
80
+ page.output = convert(page)
81
81
  end
82
82
 
83
83
  Jekyll::Hooks.register :site, :after_init do |site|
@@ -91,7 +91,7 @@ Jekyll::Hooks.register :site, :after_init do |site|
91
91
  if $global_macros.size == 0
92
92
  puts " LaTeX: no macros loaded"
93
93
  else
94
- puts " LaTeX: " + $global_macros.size.to_s + " macro" +
94
+ puts " LaTeX: " + $global_macros.size.to_s + " macro" +
95
95
  ($global_macros.size == 1 ? "" : "s") + " loaded"
96
96
  end
97
97
 
@@ -115,7 +115,6 @@ end
115
115
  Jekyll::Hooks.register :site, :post_write do
116
116
  # print new line to prevent overwriting previous output
117
117
  print "\n"
118
- puts
119
118
  # check if caching is enabled
120
119
  if $disable_disk_cache == false
121
120
  # save cache to disk
@@ -1,3 +1,3 @@
1
1
  module Jektex
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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.2
4
+ version: 0.0.3
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-13 00:00:00.000000000 Z
11
+ date: 2022-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: execjs