latex-to-unicode 0.1.1
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.
- data/lib/data.rb +925 -0
- data/lib/latex-to-unicode.rb +20 -0
- data/lib/latex_grammar.rb +815 -0
- data/lib/translate.rb +60 -0
- metadata +48 -0
data/lib/translate.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module LatexToUnicode
|
4
|
+
def self.translate(str, set)
|
5
|
+
q = str.dup
|
6
|
+
set.each do |k, v|
|
7
|
+
q.gsub!(k, v)
|
8
|
+
end
|
9
|
+
q
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.translate_fraction(num, den)
|
13
|
+
case [num.to_i, den.to_i]
|
14
|
+
when [1, 2] then '½'
|
15
|
+
when [1, 3] then '⅓'
|
16
|
+
when [1, 4] then '¼'
|
17
|
+
when [1, 5] then '⅕'
|
18
|
+
when [1, 6] then '⅙'
|
19
|
+
when [1, 8] then '⅛'
|
20
|
+
when [2, 3] then '⅔'
|
21
|
+
when [2, 5] then '⅖'
|
22
|
+
when [3, 4] then '¾'
|
23
|
+
when [3, 5] then '⅗'
|
24
|
+
when [3, 8] then '⅜'
|
25
|
+
when [4, 5] then '⅘'
|
26
|
+
when [5, 6] then '⅚'
|
27
|
+
when [5, 8] then '⅝'
|
28
|
+
when [7, 8] then '⅞'
|
29
|
+
else
|
30
|
+
"(#{num} / #{den})"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.translate_sqrt(radicand, radical)
|
35
|
+
case radical.to_i
|
36
|
+
when 2 then "√(#{radicand})"
|
37
|
+
when 3 then "∛(#{radicand})"
|
38
|
+
when 4 then "∜(#{radicand})"
|
39
|
+
else
|
40
|
+
"#{translate(radical, SUPERSCRIPTS)}√(#{radicand})"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.translate_combining(text, type)
|
45
|
+
text +
|
46
|
+
case type
|
47
|
+
when :hat then '̂' # this is the unicode "combining circumflex"
|
48
|
+
when :breve then '̆'
|
49
|
+
when :grave then '̀'
|
50
|
+
when :bar then '̄'
|
51
|
+
when :check then '̌'
|
52
|
+
when :acute then '́'
|
53
|
+
when :tilde then '̃'
|
54
|
+
when :vec then '⃗'
|
55
|
+
when :dot then '̇'
|
56
|
+
when :ddot then '̈'
|
57
|
+
when :mathring then '̊'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: latex-to-unicode
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Vikhyat Korrapati
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-14 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Replaces LaTeX math-mode markup with Unicode characters wherever possible.
|
15
|
+
email: c@vikhyat.net
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/latex-to-unicode.rb
|
21
|
+
- lib/data.rb
|
22
|
+
- lib/translate.rb
|
23
|
+
- lib/latex_grammar.rb
|
24
|
+
homepage: http://vikhyat.net/projects/latex_to_unicode/
|
25
|
+
licenses: []
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 1.8.24
|
45
|
+
signing_key:
|
46
|
+
specification_version: 3
|
47
|
+
summary: Latex math to Unicode character conversion.
|
48
|
+
test_files: []
|