jekyll-latex-pdf 0.4.2 → 0.5.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/.rubocop.yml +197 -144
- data/CHANGELOG.md +9 -2
- data/Gemfile.lock +1 -1
- data/README.md +82 -18
- data/bin/setup +5 -3
- data/data/kramdown/apa6.latex +7 -1
- data/data/kramdown/jekyll-latex-pdf.latex +1 -0
- data/jekyll-latex-pdf.gemspec +3 -0
- data/lib/jekyll/latex/pdf.rb +9 -4
- data/lib/jekyll/latex/pdf/defaults.rb +48 -0
- data/lib/jekyll/latex/pdf/document.rb +28 -10
- data/lib/jekyll/latex/pdf/figure.rb +2 -0
- data/lib/jekyll/latex/pdf/figure/figure.rb +58 -0
- data/lib/jekyll/latex/pdf/generator.rb +14 -2
- data/lib/jekyll/latex/pdf/kramdown_data.rb +32 -0
- data/lib/jekyll/latex/pdf/latex.rb +72 -49
- data/lib/jekyll/latex/pdf/liquid.rb +17 -12
- data/lib/jekyll/latex/pdf/scholar/bibliography.rb +6 -1
- data/lib/jekyll/latex/pdf/scholar/cite.rb +9 -4
- data/lib/jekyll/latex/pdf/tikz.rb +4 -0
- data/lib/jekyll/latex/pdf/tikz/tikz-html.rb +108 -0
- data/lib/jekyll/latex/pdf/tikz/tikz-latex.rb +34 -0
- data/lib/jekyll/latex/pdf/utilities.rb +33 -0
- data/lib/jekyll/latex/pdf/version.rb +1 -1
- metadata +9 -7
- data/lib/jekyll/latex/pdf/options.rb +0 -83
- data/rubocop/jekyll.rb +0 -5
- data/rubocop/jekyll/assert_equal_literal_actual.rb +0 -149
- data/rubocop/jekyll/no_p_allowed.rb +0 -23
- data/rubocop/jekyll/no_puts_allowed.rb +0 -23
@@ -6,18 +6,18 @@ module Jekyll
|
|
6
6
|
# Generates an environment where we temporarily can add new tags to the templet,
|
7
7
|
# without changing the registered tags.
|
8
8
|
class TempLiquid
|
9
|
-
|
10
|
-
|
9
|
+
|
10
|
+
def saved_liquid_tags
|
11
|
+
@saved_liquid_tags ||= {}
|
11
12
|
end
|
12
13
|
|
13
14
|
def register_tag(tag_key, tag_value)
|
15
|
+
saved_liquid_tags[tag_key] = Liquid::Template.tags[tag_key]
|
14
16
|
Liquid::Template.register_tag(tag_key, tag_value)
|
15
|
-
@tmp_keys ||= []
|
16
|
-
@tmp_keys << tag_key
|
17
17
|
end
|
18
18
|
|
19
19
|
def register_tags
|
20
|
-
|
20
|
+
TempLiquid.tags.each do |tag_key, tag_value|
|
21
21
|
register_tag(tag_key, tag_value)
|
22
22
|
Jekyll.logger.debug "Register tag:", tag_key.to_s
|
23
23
|
end
|
@@ -28,22 +28,27 @@ module Jekyll
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def restore_liquid_tags
|
31
|
-
|
32
|
-
|
33
|
-
Liquid::Template.register_tag(k, @saved_liquid_tags[k])
|
34
|
-
else
|
35
|
-
Liquit::Template.tags.delete(k)
|
36
|
-
end
|
31
|
+
saved_liquid_tags.each do |tag_key, tag_value|
|
32
|
+
Liquid::Template.register_tag tag_key, tag_value
|
37
33
|
end
|
38
34
|
end
|
39
35
|
|
40
36
|
def self.run
|
41
37
|
s = TempLiquid.new
|
42
|
-
s.save_liquid_tags
|
43
38
|
s.register_tags
|
44
39
|
yield s
|
45
40
|
s.restore_liquid_tags
|
46
41
|
end
|
42
|
+
|
43
|
+
def self.tags
|
44
|
+
@@liquid_tags_register || {}
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.register_tag(name, klass)
|
48
|
+
@@liquid_tags_register ||= {}
|
49
|
+
@@liquid_tags_register[name.to_s] = klass
|
50
|
+
end
|
51
|
+
|
47
52
|
end
|
48
53
|
end
|
49
54
|
end
|
@@ -2,10 +2,14 @@
|
|
2
2
|
|
3
3
|
module Jekyll
|
4
4
|
module Latex
|
5
|
+
# This module generates pdf files using latex (must be installed on the system) and
|
6
|
+
# should be highly configurable.
|
5
7
|
module Pdf
|
6
8
|
## here we add support for jekyll-scholar, a great module for scientific writing.
|
7
9
|
module Scholar
|
10
|
+
# Overrides the jekyll-scholar bibliography tag to be used for latex generation.
|
8
11
|
class Bibliography < Liquid::Tag
|
12
|
+
|
9
13
|
include Utilities
|
10
14
|
|
11
15
|
def initialize(tag_name, arguments, tokens)
|
@@ -16,10 +20,11 @@ module Jekyll
|
|
16
20
|
def render(_context)
|
17
21
|
nomarkdown "\\printbibliography"
|
18
22
|
end
|
23
|
+
|
19
24
|
end
|
20
25
|
end
|
21
26
|
|
22
|
-
|
27
|
+
TempLiquid.register_tag("bibliography", Scholar::Bibliography)
|
23
28
|
end
|
24
29
|
end
|
25
30
|
end
|
@@ -2,10 +2,14 @@
|
|
2
2
|
|
3
3
|
module Jekyll
|
4
4
|
module Latex
|
5
|
+
# This module generates pdf files using latex (must be installed on the system) and
|
6
|
+
# should be highly configurable.
|
5
7
|
module Pdf
|
6
|
-
|
8
|
+
# here we add support for jekyll-scholar, a great module for scientific writing.
|
7
9
|
module Scholar
|
10
|
+
# Overrides the jekyll-scholar cite tag to be used for generating latex documents.
|
8
11
|
class Cite < Liquid::Tag
|
12
|
+
|
9
13
|
include Utilities
|
10
14
|
def initialize(tag_name, arguments, tokens)
|
11
15
|
super
|
@@ -15,16 +19,17 @@ module Jekyll
|
|
15
19
|
|
16
20
|
def render(_context)
|
17
21
|
# set_context_to context+
|
18
|
-
if @keys.
|
22
|
+
if @keys.kind_of? String
|
19
23
|
nomarkdown "\\parencite\{#{@keys.strip}\}"
|
20
24
|
else
|
21
|
-
nomarkdown "\\parencite\{" + @keys.collect {
|
25
|
+
nomarkdown "\\parencite\{" + @keys.collect {|x| x.strip || x }.join(",") + "\}"
|
22
26
|
end
|
23
27
|
end
|
28
|
+
|
24
29
|
end
|
25
30
|
end
|
26
31
|
|
27
|
-
|
32
|
+
TempLiquid.register_tag("cite", Scholar::Cite)
|
28
33
|
end
|
29
34
|
end
|
30
35
|
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Authored my Maxfan http://github.com/Maxfan-zone http://maxfan.org
|
3
|
+
# Adjusted to the need of jekyll-latex-pdf by Martin Kaffanke
|
4
|
+
# This is used to convert tikz code into svg file and load in you jekyll site
|
5
|
+
#
|
6
|
+
# Install:
|
7
|
+
#
|
8
|
+
# 1. Copy this file in your _plugins/ directory. You can customize it, of course.
|
9
|
+
# 2. Make sure texlive and pdf2svg are installed on your computer.
|
10
|
+
# 3. Set path to pdf2svg in _config.yml in "pdf2svg" variable
|
11
|
+
#
|
12
|
+
# Input:
|
13
|
+
#
|
14
|
+
# {% tikz filename %}
|
15
|
+
# \tikz code goes here
|
16
|
+
# {% endtikz %}
|
17
|
+
#
|
18
|
+
# This will generate a /img/post-title-from-filename/filename.svg in your jekyll directory
|
19
|
+
#
|
20
|
+
# And then return this in your HTML output file:
|
21
|
+
#
|
22
|
+
# <embed src="/img/post-title-from-filename/tikz-filename.svg" type="image/svg+xml" />
|
23
|
+
#
|
24
|
+
|
25
|
+
require "open3"
|
26
|
+
|
27
|
+
module Jekyll
|
28
|
+
module Latex
|
29
|
+
module Pdf
|
30
|
+
module Tikz
|
31
|
+
class TikzHtml < Liquid::Block
|
32
|
+
|
33
|
+
include Utilities
|
34
|
+
|
35
|
+
attr_reader :config, :site
|
36
|
+
|
37
|
+
def initialize(tag_name, markup, tokens)
|
38
|
+
super
|
39
|
+
@file_name = markup.gsub(/\s+/, "")
|
40
|
+
|
41
|
+
@header = <<-'END'
|
42
|
+
\documentclass{standalone}
|
43
|
+
\usepackage{tikz}
|
44
|
+
\begin{document}
|
45
|
+
\begin{tikzpicture}
|
46
|
+
END
|
47
|
+
|
48
|
+
@footer = <<-'END'
|
49
|
+
\end{tikzpicture}
|
50
|
+
\end{document}
|
51
|
+
END
|
52
|
+
|
53
|
+
@config = Defaults.defaults.dup
|
54
|
+
end
|
55
|
+
|
56
|
+
def render(context)
|
57
|
+
set_context_to context
|
58
|
+
|
59
|
+
tikz_code = @header + super + @footer
|
60
|
+
|
61
|
+
tmp_directory = File.join(Dir.pwd, ".tikz-cache", File.basename(context["page"]["url"], ".*"))
|
62
|
+
tex_path = File.join(tmp_directory, "#{@file_name}.tex")
|
63
|
+
pdf_path = File.join(tmp_directory, "#{@file_name}.pdf")
|
64
|
+
FileUtils.mkdir_p tmp_directory
|
65
|
+
|
66
|
+
dest_directory = File.join(Dir.pwd, @site.config["pdf"]["tikz_path"], File.basename(context["page"]["url"], ".*"))
|
67
|
+
svg_path = File.join(dest_directory, "#{@file_name}.svg")
|
68
|
+
png_path = File.join(dest_directory, "#{@file_name}.png")
|
69
|
+
FileUtils.mkdir_p dest_directory
|
70
|
+
|
71
|
+
# if the file doesn't exist or the tikz code is not the same with the file, then compile the file
|
72
|
+
if !File.exist?(tex_path) || !tikz_same?(tex_path, tikz_code) || !File.exist?(svg_path)
|
73
|
+
File.open(tex_path, 'w') {|file| file.write(tikz_code.to_s) }
|
74
|
+
cmds = [[@site.config["pdf"]["pdf_engine"],
|
75
|
+
"--interaction=batchmode",
|
76
|
+
"--output-format=pdf", tex_path],
|
77
|
+
["pdf2svg", pdf_path, svg_path],
|
78
|
+
["gm", "convert", svg_path, "-quality", "90", png_path]]
|
79
|
+
|
80
|
+
run_cmds cmds, tmp_directory
|
81
|
+
end
|
82
|
+
|
83
|
+
web_svg_path = File.join(@site.config["pdf"]["tikz_path"],
|
84
|
+
File.basename(context["page"]["url"], ".*"),
|
85
|
+
"#{@file_name}.svg")
|
86
|
+
web_png_path = File.join(@site.config["pdf"]["tikz_path"],
|
87
|
+
File.basename(context["page"]["url"], ".*"),
|
88
|
+
"#{@file_name}.png")
|
89
|
+
"\n<object data=\"/#{web_svg_path}\" type=\"image/svg+xml\">" \
|
90
|
+
"<img src=\"/#{web_png_path}\" alt=\"#{@file_name}\" />" \
|
91
|
+
"</object>\n"
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def tikz_same?(file, code)
|
97
|
+
File.open(file, 'r') do |tikzfile|
|
98
|
+
tikzfile.read == code
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
Liquid::Template.register_tag('tikz', TikzHtml)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Latex
|
5
|
+
module Pdf
|
6
|
+
module Tikz
|
7
|
+
class TikzPdf < Liquid::Block
|
8
|
+
|
9
|
+
include Utilities
|
10
|
+
|
11
|
+
def initialize(tag_name, markup, tokens)
|
12
|
+
super
|
13
|
+
# @file_name = markup.gsub(/\s+/, "")
|
14
|
+
|
15
|
+
@header = <<~'END'
|
16
|
+
\begin{tikzpicture}
|
17
|
+
END
|
18
|
+
|
19
|
+
@footer = <<~'END'
|
20
|
+
\end{tikzpicture}
|
21
|
+
END
|
22
|
+
end
|
23
|
+
|
24
|
+
def render(context)
|
25
|
+
nomarkdown_p(@header + super + @footer)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
TempLiquid.register_tag("tikz", Tikz::TikzPdf)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -3,10 +3,43 @@
|
|
3
3
|
module Jekyll
|
4
4
|
module Latex
|
5
5
|
module Pdf
|
6
|
+
# Add methods which can be useful anywhere in the package.
|
6
7
|
module Utilities
|
8
|
+
# Surround a string with nomarkdown tags to tell kramdown that this is
|
9
|
+
# plain latex.
|
7
10
|
def nomarkdown(string_to_wrap)
|
8
11
|
"{::nomarkdown type=\"latex\"}" + string_to_wrap + "{:/}"
|
9
12
|
end
|
13
|
+
|
14
|
+
def nomarkdown_p(string_to_wrap)
|
15
|
+
"\n" + nomarkdown(string_to_wrap) + "\n"
|
16
|
+
end
|
17
|
+
|
18
|
+
# Run some commands und stop on errors.
|
19
|
+
def run_cmds(cmds, tempdir)
|
20
|
+
status = 0
|
21
|
+
out = "\n"
|
22
|
+
cmds.each do |cmd|
|
23
|
+
Open3.popen2(*cmd, chdir: tempdir) do |_i, oe, t|
|
24
|
+
oe.each {|l| out += l + "\n" }
|
25
|
+
|
26
|
+
status = t.value
|
27
|
+
end
|
28
|
+
unless 0 == status
|
29
|
+
Jekyll.logger.warn "jekyll-latex-pdf", "Error running #{cmd.join ' '}"
|
30
|
+
Jekyll.logger.warn "Return status: #{status}"
|
31
|
+
Jekyll.logger.warn out
|
32
|
+
end
|
33
|
+
end
|
34
|
+
[out, status]
|
35
|
+
end
|
36
|
+
|
37
|
+
# stolen from jekyll-scholar
|
38
|
+
def set_context_to(context)
|
39
|
+
@context, @site, = context, context.registers[:site]
|
40
|
+
config.merge!(site.config['scholar'] || {})
|
41
|
+
self
|
42
|
+
end
|
10
43
|
end
|
11
44
|
end
|
12
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-latex-pdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Kaffanke
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -160,20 +160,22 @@ files:
|
|
160
160
|
- jekyll-latex-pdf.gemspec
|
161
161
|
- lib/jekyll-latex-pdf.rb
|
162
162
|
- lib/jekyll/latex/pdf.rb
|
163
|
+
- lib/jekyll/latex/pdf/defaults.rb
|
163
164
|
- lib/jekyll/latex/pdf/document.rb
|
165
|
+
- lib/jekyll/latex/pdf/figure.rb
|
166
|
+
- lib/jekyll/latex/pdf/figure/figure.rb
|
164
167
|
- lib/jekyll/latex/pdf/generator.rb
|
168
|
+
- lib/jekyll/latex/pdf/kramdown_data.rb
|
165
169
|
- lib/jekyll/latex/pdf/latex.rb
|
166
170
|
- lib/jekyll/latex/pdf/liquid.rb
|
167
|
-
- lib/jekyll/latex/pdf/options.rb
|
168
171
|
- lib/jekyll/latex/pdf/scholar.rb
|
169
172
|
- lib/jekyll/latex/pdf/scholar/bibliography.rb
|
170
173
|
- lib/jekyll/latex/pdf/scholar/cite.rb
|
174
|
+
- lib/jekyll/latex/pdf/tikz.rb
|
175
|
+
- lib/jekyll/latex/pdf/tikz/tikz-html.rb
|
176
|
+
- lib/jekyll/latex/pdf/tikz/tikz-latex.rb
|
171
177
|
- lib/jekyll/latex/pdf/utilities.rb
|
172
178
|
- lib/jekyll/latex/pdf/version.rb
|
173
|
-
- rubocop/jekyll.rb
|
174
|
-
- rubocop/jekyll/assert_equal_literal_actual.rb
|
175
|
-
- rubocop/jekyll/no_p_allowed.rb
|
176
|
-
- rubocop/jekyll/no_puts_allowed.rb
|
177
179
|
homepage: https://gitlab.com/grauschnabel/jekyll-latex-pdf
|
178
180
|
licenses:
|
179
181
|
- MIT
|
@@ -1,83 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Jekyll
|
4
|
-
module Latex
|
5
|
-
module Pdf
|
6
|
-
class Options
|
7
|
-
@@liquid_tags = {}
|
8
|
-
def initialize(*args)
|
9
|
-
template_dirname = File.expand_path(File.join(File.dirname(__FILE__),
|
10
|
-
"..", "..", "..", "..",
|
11
|
-
"data", "kramdown"))
|
12
|
-
|
13
|
-
@options = { :pdf_engine => "lualatex",
|
14
|
-
:bib_engine => "biber",
|
15
|
-
:template => File.join(template_dirname, "jekyll-latex-pdf.latex"),
|
16
|
-
:default_template_path => template_dirname,
|
17
|
-
:template_path => "_latex",
|
18
|
-
:date_as_note => false, }
|
19
|
-
|
20
|
-
@data = {}
|
21
|
-
@allowed_keys = @options.keys
|
22
|
-
|
23
|
-
add_options(*args)
|
24
|
-
end
|
25
|
-
|
26
|
-
def hash_args(*args)
|
27
|
-
hashed_args = args.detect { |f| f.class == Hash }
|
28
|
-
hashed_args.each_with_object({}) { |(k, v), memo| memo[k.to_sym] = v; }
|
29
|
-
end
|
30
|
-
|
31
|
-
def expand_template(template)
|
32
|
-
template.concat(".latex") unless template.end_with?(".latex")
|
33
|
-
end
|
34
|
-
|
35
|
-
def update_template(template)
|
36
|
-
t = expand_template File.expand_path(File.join(@options[:template_path], template))
|
37
|
-
if File.file? t
|
38
|
-
return t
|
39
|
-
else
|
40
|
-
t = expand_template File.expand_path(File.join(@options[:default_template_path], template))
|
41
|
-
if File.file? t
|
42
|
-
return t
|
43
|
-
else
|
44
|
-
Jekyll.warn "jekyll-latex-pdf", "Could not find template #{t}."
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def add_options(*args)
|
50
|
-
hashed_args = hash_args(*args)
|
51
|
-
hashed_args[:template] = update_template(hashed_args[:template]) if hashed_args[:template]
|
52
|
-
|
53
|
-
allowed_args = hashed_args.select { |key, _| @allowed_keys.include? key }
|
54
|
-
@options.merge! allowed_args
|
55
|
-
add_data(hashed_args.reject { |key, _| @allowed_keys.include? key })
|
56
|
-
end
|
57
|
-
|
58
|
-
def options
|
59
|
-
@options[:data] = @data
|
60
|
-
@options
|
61
|
-
end
|
62
|
-
|
63
|
-
def [](key)
|
64
|
-
@options[key]
|
65
|
-
end
|
66
|
-
|
67
|
-
def add_data(*args)
|
68
|
-
@data.merge! hash_args(*args)
|
69
|
-
end
|
70
|
-
|
71
|
-
attr_reader :data
|
72
|
-
|
73
|
-
def self.tags
|
74
|
-
@@liquid_tags
|
75
|
-
end
|
76
|
-
|
77
|
-
def self.register_tag(name, klass)
|
78
|
-
@@liquid_tags[name.to_s] = klass
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|