Skip to content

Commit 776ec5a

Browse files
committed
Add LaTeX documentation from https://latexref.xyz
From https://ctan.org/pkg/latex2e-help-texinfo, the license is Public Domain.
1 parent cce7c49 commit 776ec5a

File tree

6 files changed

+89
-0
lines changed

6 files changed

+89
-0
lines changed

lib/docs/filters/latex/clean_html.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module Docs
2+
class Latex
3+
class CleanHtmlFilter < Filter
4+
def call
5+
css('hr, div.header, div.referenceinfo').remove
6+
css('div.shortcontents, div.contents, h2.shortcontents-heading, h2.contents-heading, h1.settitle').remove if root_page?
7+
8+
css('span[id] + h1, span[id] + h2, span[id] + h3, span[id] + h4, span[id] + h5, span[id] + h6').each do |node|
9+
id = node.previous['id']
10+
node.previous.remove
11+
node['id'] = id.sub(/-\d$/, '') if id
12+
end
13+
14+
css('h1, h2, h3, h4').each { |node| node.content = node.content.sub /^[0-9A-Z]+(\.[0-9]+)* /, '' }
15+
16+
doc
17+
end
18+
end
19+
end
20+
end

lib/docs/filters/latex/entries.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module Docs
2+
class Latex
3+
class EntriesFilter < Docs::EntriesFilter
4+
5+
@@entries = Hash.new
6+
7+
def initialize(*)
8+
super
9+
10+
return unless root_page?
11+
12+
css('.contents > ul > li').each do |node|
13+
lev1 = node.at_css('> a:first-child').text.sub /^[0-9A-Z]+(\.[0-9]+)* /, ''
14+
node.css('a').each do |link|
15+
href = link['href'].split('#')[0].parameterize.downcase
16+
@@entries[href] = lev1
17+
end
18+
end
19+
20+
end
21+
22+
def get_name
23+
at_css('h1, h2, h3, h4, h5, h6').content.sub /^[0-9A-Z]+(\.[0-9]+)* /, ''
24+
end
25+
26+
def get_type
27+
begin
28+
return @@entries[slug.downcase]
29+
rescue
30+
return "Missing type with slug #{slug}"
31+
end
32+
end
33+
34+
def include_default_entry?
35+
true
36+
end
37+
38+
def additional_entries
39+
return []
40+
end
41+
42+
private
43+
44+
end
45+
end
46+
end

lib/docs/scrapers/latex.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module Docs
2+
class Latex < UrlScraper
3+
self.name = 'LaTeX'
4+
self.slug = 'latex'
5+
self.type = 'simple'
6+
self.links = {
7+
home: 'https://ctan.org/pkg/latex2e-help-texinfo/'
8+
}
9+
10+
self.base_url = 'http://latexref.xyz'
11+
12+
html_filters.push 'latex/entries', 'latex/clean_html'
13+
14+
options[:skip_patterns] = [/^\/dev\//, /\.(dvi|pdf)$/]
15+
16+
options[:attribution] = <<-HTML
17+
&copy; 2007–2018 Karl Berry<br>
18+
Public Domain Software
19+
HTML
20+
21+
end
22+
end

public/icons/docs/latex/16.png

305 Bytes
Loading
568 Bytes
Loading

public/icons/docs/latex/SOURCE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Compiling \LaTeX with pdflatex https://www.tug.org/applications/pdftex/

0 commit comments

Comments
 (0)