mathjax-renderer 0.0.5 → 0.0.6
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 +63 -3
- data/lib/mathjax_renderer/renderer.rb +13 -4
- data/lib/mathjax_renderer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 108c1668656658f3c89100c86dcbaee043b19343
|
4
|
+
data.tar.gz: 9635fb1117c4084b4b6480c7ef4b851d3fdca2f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e02966b4f64ab784df3176473320abfb0e2ffb43dc899665383450bc30e91bf271a4f748efd0cf4a7d8391c4298529159e895e6f0c23019761111579d6c0e97e
|
7
|
+
data.tar.gz: d0f48a885c73debde6bb8b86c65544e3f8b51c5de7dc293dba87356e6703056bdca1d7b9c59360561e6e2fd8021426cffa4ae05954f7be52296f223833cca591
|
data/README.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Mathjax::Renderer
|
2
2
|
|
3
|
-
|
3
|
+
This gem is to pre-render MathJax expressions or export them as images. Since MathJax uses client-side
|
4
|
+
Javascript and styles to convert MathML (along with other formats) to HTML, this is not compatible
|
5
|
+
with article readers like Pocket as they do not run scripts. mathjax-renderer solves this by
|
6
|
+
generating images from MathJax expressions which can be inserted to the site instead of the MathML
|
7
|
+
expression, thus making them visible to readers. Also, there is an option to generate the HTML,
|
8
|
+
so you can remove the client-side scripts.
|
4
9
|
|
5
10
|
## Installation
|
6
11
|
|
@@ -20,11 +25,66 @@ Or install it yourself as:
|
|
20
25
|
|
21
26
|
## Usage
|
22
27
|
|
23
|
-
|
28
|
+
mathjax-renderer can generate the HTML from running the MathJax scripts, and it can be used to directly
|
29
|
+
generate an image from the result. It uses a global cache, so it is fast for the second time for the
|
30
|
+
same input.
|
31
|
+
|
32
|
+
### Requirements
|
33
|
+
|
34
|
+
mathjax-renderer uses Chrome with Xvfb, so they need to be installed (sorry, not gonna work on Windows).
|
35
|
+
|
36
|
+
### Generating the HTML
|
37
|
+
|
38
|
+
To generated the HTML, just call:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
Mathjax_Renderer::Renderer.new(mathml_string).html
|
42
|
+
```
|
43
|
+
|
44
|
+
Then, the resulting HTML can be directly inserted to the page. This also needs the MathJax fonts, so
|
45
|
+
don't forget to include them as well:
|
46
|
+
|
47
|
+
```
|
48
|
+
@font-face {font-family: MathJax_Main; src: url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/woff/MathJax_Main-Regular.woff?rev=2.5.0') format('woff'), url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/otf/MathJax_Main-Regular.otf?rev=2.5.0') format('opentype')}
|
49
|
+
@font-face {font-family: MathJax_Main-bold; src: url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/woff/MathJax_Main-Bold.woff?rev=2.5.0') format('woff'), url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/otf/MathJax_Main-Bold.otf?rev=2.5.0') format('opentype')}
|
50
|
+
@font-face {font-family: MathJax_Main-italic; src: url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/woff/MathJax_Main-Italic.woff?rev=2.5.0') format('woff'), url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/otf/MathJax_Main-Italic.otf?rev=2.5.0') format('opentype')}
|
51
|
+
@font-face {font-family: MathJax_Math-italic; src: url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/woff/MathJax_Math-Italic.woff?rev=2.5.0') format('woff'), url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/otf/MathJax_Math-Italic.otf?rev=2.5.0') format('opentype')}
|
52
|
+
@font-face {font-family: MathJax_Caligraphic; src: url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/woff/MathJax_Caligraphic-Regular.woff?rev=2.5.0') format('woff'), url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/otf/MathJax_Caligraphic-Regular.otf?rev=2.5.0') format('opentype')}
|
53
|
+
@font-face {font-family: MathJax_Size1; src: url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/woff/MathJax_Size1-Regular.woff?rev=2.5.0') format('woff'), url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/otf/MathJax_Size1-Regular.otf?rev=2.5.0') format('opentype')}
|
54
|
+
@font-face {font-family: MathJax_Size2; src: url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/woff/MathJax_Size2-Regular.woff?rev=2.5.0') format('woff'), url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/otf/MathJax_Size2-Regular.otf?rev=2.5.0') format('opentype')}
|
55
|
+
@font-face {font-family: MathJax_Size3; src: url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/woff/MathJax_Size3-Regular.woff?rev=2.5.0') format('woff'), url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/otf/MathJax_Size3-Regular.otf?rev=2.5.0') format('opentype')}
|
56
|
+
@font-face {font-family: MathJax_Size4; src: url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/woff/MathJax_Size4-Regular.woff?rev=2.5.0') format('woff'), url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/otf/MathJax_Size4-Regular.otf?rev=2.5.0') format('opentype')}
|
57
|
+
```
|
58
|
+
|
59
|
+
_Note:_ don't forget that you already have these as a transitive dependency to rails-assets-MathJax.
|
60
|
+
Be nice and use those instead.
|
61
|
+
|
62
|
+
### Generating image
|
63
|
+
|
64
|
+
To generate the image as well, just supply a base folder to store the images:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
Mathjax_Renderer::Renderer.new(mathml_string, image_directory).image_name
|
68
|
+
```
|
69
|
+
|
70
|
+
This generates the image and gets back the name in the target directory.
|
71
|
+
|
72
|
+
There are a few configurations possible:
|
73
|
+
|
74
|
+
* *min_width:* The resulting image will be at least wide in pixels. Pocket enlarges images that are too small,
|
75
|
+
making them a bit bigger disables this behaviour
|
76
|
+
* *extra_style:* These will be appended to a style element. Use it to set text color, background color,
|
77
|
+
or any other styles that would have been applied to the HTML in your site.
|
78
|
+
* *padding:* A padding in pixels will be added to both dimensions.
|
79
|
+
|
80
|
+
## Caveats
|
81
|
+
|
82
|
+
mathjax-renderer internally uses a WEBrick server to generate the results in a random free port. It is
|
83
|
+
started when the renderer is first called, and remains running.
|
24
84
|
|
25
85
|
## Contributing
|
26
86
|
|
27
|
-
1. Fork it ( https://github.com/
|
87
|
+
1. Fork it ( https://github.com/sashee/mathjax-renderer/fork )
|
28
88
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
89
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
90
|
4. Push to the branch (`git push origin my-new-feature`)
|
@@ -28,7 +28,7 @@ module Mathjax_Renderer
|
|
28
28
|
Headless.ly do
|
29
29
|
|
30
30
|
Capybara.register_driver :chrome do |app|
|
31
|
-
Capybara::Selenium::Driver.new(app, :browser => :chrome)
|
31
|
+
Capybara::Selenium::Driver.new(app, :browser => :chrome, :args => ['no-sandbox','no-default-browser-check','no-first-run','disable-default-apps'])
|
32
32
|
end
|
33
33
|
|
34
34
|
Capybara.default_driver = :chrome
|
@@ -38,7 +38,9 @@ module Mathjax_Renderer
|
|
38
38
|
|
39
39
|
def mathjax_ready?(page)
|
40
40
|
html = Nokogiri::HTML(page.html)
|
41
|
-
!html.css('.MathJax').empty? &&
|
41
|
+
!html.css('.MathJax').empty? &&
|
42
|
+
html.css('.MathJax_Processing').empty? &&
|
43
|
+
html.css('.MathJax_Processed').empty?
|
42
44
|
end
|
43
45
|
|
44
46
|
Timeout.timeout(5) do
|
@@ -159,9 +161,16 @@ module Mathjax_Renderer
|
|
159
161
|
require 'webrick'
|
160
162
|
mathjax_dir = Gem::Specification.find_by_name("rails-assets-MathJax").gem_dir
|
161
163
|
|
162
|
-
self.server = WEBrick::HTTPServer.new(
|
164
|
+
self.server = WEBrick::HTTPServer.new(
|
165
|
+
:Port => 0,
|
166
|
+
:DocumentRoot => "#{mathjax_dir}/app/assets",
|
167
|
+
:AccessLog => [],
|
168
|
+
:Logger => WEBrick::Log::new('/dev/null', 7)
|
169
|
+
)
|
163
170
|
|
164
|
-
server.mount '/javascripts/MathJax/fonts',
|
171
|
+
server.mount '/javascripts/MathJax/fonts',
|
172
|
+
WEBrick::HTTPServlet::FileHandler,
|
173
|
+
"#{mathjax_dir}/app/assets/fonts/MathJax/fonts"
|
165
174
|
|
166
175
|
begin
|
167
176
|
server.start
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mathjax-renderer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sashee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|