special_latex 1.0.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 +7 -0
- data/lib/special_latex.rb +224 -0
- data/spec/special_latex_spec.rb +135 -0
- metadata +62 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: be48f1323a3ce5aae9096bd8d1456152137eb432
|
|
4
|
+
data.tar.gz: d2ca22f109cade1e04062b88e774055130fbe604
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 2fa69ce0e21d617ff65b5eec1f0f1de4145469e7bed79409d2fbaef39600b3b3a11244d51a55c84c65552bc8bef7a82ca414f4e9ceb8c55a580bd5f1b2d7b375
|
|
7
|
+
data.tar.gz: 5cb93c2769818dd010ee68db4a5aab1ee9e0a206468bfefae0704c3adc106a5762c0e1673348455406b153da25cc025eaa3b59444da559d47b022ae83085e58d
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
class SpecialLatex
|
|
2
|
+
@command_map = {
|
|
3
|
+
"alpha" => "α",
|
|
4
|
+
"beta" => "β",
|
|
5
|
+
"gamma" => "γ",
|
|
6
|
+
"delta" => "δ",
|
|
7
|
+
"epsilon" => "ε",
|
|
8
|
+
"zeta" => "ζ",
|
|
9
|
+
"eta" => "η",
|
|
10
|
+
"theta" => "θ",
|
|
11
|
+
"iota" => "ι",
|
|
12
|
+
"kappa" => "κ",
|
|
13
|
+
"lambda" => "λ",
|
|
14
|
+
"mu" => "μ",
|
|
15
|
+
"nu" => "ν",
|
|
16
|
+
"xi" => "ξ",
|
|
17
|
+
"pi" => "π",
|
|
18
|
+
"rho" => "ρ",
|
|
19
|
+
"sigma" => "σ",
|
|
20
|
+
"tau" => "τ",
|
|
21
|
+
"upsilon" => "υ",
|
|
22
|
+
"phi" => "φ",
|
|
23
|
+
"chi" => "χ",
|
|
24
|
+
"psi" => "ψ",
|
|
25
|
+
"omega" => "ω",
|
|
26
|
+
"Gamma" => "Γ",
|
|
27
|
+
"Lambda" => "Λ",
|
|
28
|
+
"Sigma" => "Σ",
|
|
29
|
+
"Psi" => "Ψ",
|
|
30
|
+
"Delta" => "Δ",
|
|
31
|
+
"Xi" => "Ξ",
|
|
32
|
+
"Upsilon" => "Υ",
|
|
33
|
+
"Omega" => "Ω",
|
|
34
|
+
"Theta" => "Θ",
|
|
35
|
+
"Pi" => "Π",
|
|
36
|
+
"Phi" => "Φ",
|
|
37
|
+
"ae" => "æ",
|
|
38
|
+
"AE" => "Æ",
|
|
39
|
+
"oe" => "œ",
|
|
40
|
+
"OE" => "Œ",
|
|
41
|
+
"aa" => "å",
|
|
42
|
+
"AA" => "Å",
|
|
43
|
+
"o" => "ø",
|
|
44
|
+
"O" => "Ø",
|
|
45
|
+
"ss" => "ß",
|
|
46
|
+
"euro" => "€",
|
|
47
|
+
"textdegree" => "°",
|
|
48
|
+
"%" => "%",
|
|
49
|
+
"$" => "$",
|
|
50
|
+
"{" => "{",
|
|
51
|
+
"}" => "}",
|
|
52
|
+
"_" => "_",
|
|
53
|
+
"P" => "¶",
|
|
54
|
+
"dag" => "†",
|
|
55
|
+
"ddag" => "‡",
|
|
56
|
+
"textbar" => "|",
|
|
57
|
+
"textgreater" => ">",
|
|
58
|
+
"textless" => "<",
|
|
59
|
+
"textendash" => "–",
|
|
60
|
+
"textemdash" => "—",
|
|
61
|
+
"texttrademark" => "™",
|
|
62
|
+
"textregistered" => "®",
|
|
63
|
+
"textendash" => "–",
|
|
64
|
+
"textemdash" => "—",
|
|
65
|
+
"textexclamdown" => "¡",
|
|
66
|
+
"textquestiondown" => "¿",
|
|
67
|
+
"pounds" => "£",
|
|
68
|
+
"#" => "#",
|
|
69
|
+
"&" => "&",
|
|
70
|
+
"S" => "§",
|
|
71
|
+
"copyright" => "©",
|
|
72
|
+
"alpha" => "α",
|
|
73
|
+
"l" => "ł"
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@ascii_map = {
|
|
77
|
+
"`a" => "à",
|
|
78
|
+
"`e" => "è",
|
|
79
|
+
"`i" => "ì",
|
|
80
|
+
"`o" => "ò",
|
|
81
|
+
"`u" => "ù",
|
|
82
|
+
"`A" => "À",
|
|
83
|
+
"`E" => "È",
|
|
84
|
+
"`I" => "Ì",
|
|
85
|
+
"'a" => "á",
|
|
86
|
+
"'e" => "é",
|
|
87
|
+
"'i" => "í",
|
|
88
|
+
"'o" => "ó",
|
|
89
|
+
"'u" => "ú",
|
|
90
|
+
"'A" => "Á",
|
|
91
|
+
"'E" => "É",
|
|
92
|
+
"'I" => "v",
|
|
93
|
+
"'O" => "Ó",
|
|
94
|
+
"'U" => "Ú",
|
|
95
|
+
"^a" => "â",
|
|
96
|
+
"^e" => "ê",
|
|
97
|
+
"^i" => "î",
|
|
98
|
+
"^o" => "ô",
|
|
99
|
+
"^u" => "û",
|
|
100
|
+
"^A" => "Â",
|
|
101
|
+
"^E" => "Ê",
|
|
102
|
+
"^I" => "Î",
|
|
103
|
+
"^O" => "Ô",
|
|
104
|
+
"^U" => "Û",
|
|
105
|
+
"\"a" => "ä",
|
|
106
|
+
"\"e" => "ë",
|
|
107
|
+
"\"i" => "ï",
|
|
108
|
+
"\"o" => "ö",
|
|
109
|
+
"\"u" => "ü",
|
|
110
|
+
"\"y" => "ÿ",
|
|
111
|
+
"\"A" => "Ä",
|
|
112
|
+
"\"E" => "Ë",
|
|
113
|
+
"\"I" => "Ï",
|
|
114
|
+
"\"O" => "Ö",
|
|
115
|
+
"\"U" => "Ü",
|
|
116
|
+
"\"Y" => "Ÿ",
|
|
117
|
+
"Ho" => "ő",
|
|
118
|
+
"HO" => "Ő",
|
|
119
|
+
"Hu" => "ű",
|
|
120
|
+
"HU" => "Ű",
|
|
121
|
+
"~a" => "ã",
|
|
122
|
+
"~n" => "ñ",
|
|
123
|
+
"~o" => "õ",
|
|
124
|
+
"~A" => "Ã",
|
|
125
|
+
"~N" => "Ñ",
|
|
126
|
+
"~O" => "Õ",
|
|
127
|
+
"cc" => "ç",
|
|
128
|
+
"cC" => "Ç",
|
|
129
|
+
"ka" => "ą",
|
|
130
|
+
"kA" => "Ą",
|
|
131
|
+
"ki" => "į",
|
|
132
|
+
"kI" => "Į",
|
|
133
|
+
"ku" => "ų",
|
|
134
|
+
"kU" => "Ų",
|
|
135
|
+
"ke" => "ę",
|
|
136
|
+
"kE" => "Ę",
|
|
137
|
+
"ko" => "ǫ",
|
|
138
|
+
"kO" => "Ǫ",
|
|
139
|
+
"=a" => "ā",
|
|
140
|
+
"=A" => "Ā",
|
|
141
|
+
"=e" => "ē",
|
|
142
|
+
"=E" => "Ē",
|
|
143
|
+
"=i" => "ī",
|
|
144
|
+
"=I" => "Ī",
|
|
145
|
+
"=o" => "ō",
|
|
146
|
+
"=O" => "Ō",
|
|
147
|
+
"=u" => "ū",
|
|
148
|
+
"=U" => "Ū",
|
|
149
|
+
"=y" => "ȳ",
|
|
150
|
+
"=Y" => "Ȳ",
|
|
151
|
+
"=æ" => "ǣ",
|
|
152
|
+
"=Æ" => "Ǣ",
|
|
153
|
+
"=g" => "ḡ",
|
|
154
|
+
"=G" => "Ḡ",
|
|
155
|
+
"bb" => "ḇ",
|
|
156
|
+
"bB" => "Ḇ",
|
|
157
|
+
"bd" => "ḏ",
|
|
158
|
+
"bD" => "Ḏ",
|
|
159
|
+
"bh" => "ẖ",
|
|
160
|
+
"bk" => "ḵ",
|
|
161
|
+
"bK" => "Ḵ",
|
|
162
|
+
"bl" => "ḻ",
|
|
163
|
+
"bL" => "Ḻ",
|
|
164
|
+
"bn" => "ṉ",
|
|
165
|
+
"bN" => "Ṉ",
|
|
166
|
+
"br" => "ṟ",
|
|
167
|
+
"bR" => "Ṟ",
|
|
168
|
+
"bt" => "ṯ",
|
|
169
|
+
"bT" => "Ṯ",
|
|
170
|
+
"bz" => "ẕ",
|
|
171
|
+
"bZ" => "Ẕ",
|
|
172
|
+
"ra" => "å",
|
|
173
|
+
"rA" => "Å",
|
|
174
|
+
"ua" => "ă",
|
|
175
|
+
"uA" => "Ă",
|
|
176
|
+
"ue" => "ĕ",
|
|
177
|
+
"uE" => "Ĕ",
|
|
178
|
+
"ui" => "ĭ",
|
|
179
|
+
"uI" => "Ĭ",
|
|
180
|
+
"uo" => "ŏ",
|
|
181
|
+
"uO" => "Ŏ",
|
|
182
|
+
"uu" => "ŭ",
|
|
183
|
+
"uU" => "Ŭ"
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
@connecting_map = {
|
|
187
|
+
"`" => "\u0300",
|
|
188
|
+
"'" => "\u0301",
|
|
189
|
+
"^" => "\u0302",
|
|
190
|
+
"\"" => "\u0308",
|
|
191
|
+
"H" => "\u030B",
|
|
192
|
+
"~" => "\u0303",
|
|
193
|
+
"c" => "\u0327",
|
|
194
|
+
"k" => "\u0328",
|
|
195
|
+
"=" => "\u0304",
|
|
196
|
+
"b" => "\u0331",
|
|
197
|
+
"." => "\u0307",
|
|
198
|
+
"d" => "\u0323",
|
|
199
|
+
"r" => "\u030A",
|
|
200
|
+
"u" => "\u0306",
|
|
201
|
+
"v" => "\u030C"
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
@command_regex = /\\(.+?)(\{\s*\}|(\s|$)|\{(.+?)})/
|
|
205
|
+
|
|
206
|
+
def self.convert(str)
|
|
207
|
+
str.gsub(@command_regex) do |s|
|
|
208
|
+
if @command_map.key?($1) then
|
|
209
|
+
@command_map[$1]
|
|
210
|
+
elsif not $4.empty? then
|
|
211
|
+
combined = $1 + $4
|
|
212
|
+
if @ascii_map.key?(combined) then
|
|
213
|
+
@ascii_map[combined]
|
|
214
|
+
elsif @connecting_map.key?($1) then
|
|
215
|
+
$4 + @connecting_map[$1]
|
|
216
|
+
else
|
|
217
|
+
s
|
|
218
|
+
end
|
|
219
|
+
else
|
|
220
|
+
s
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
end
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
require "special_latex"
|
|
2
|
+
|
|
3
|
+
describe SpecialLatex do
|
|
4
|
+
describe ".convert" do
|
|
5
|
+
context "given an empty string" do
|
|
6
|
+
it "returns nothing" do
|
|
7
|
+
expect(SpecialLatex.convert("")).to eql("")
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
context "given a with circumflex" do
|
|
11
|
+
it "returns the ascii char" do
|
|
12
|
+
expect(SpecialLatex.convert("\\^{a}")).to eql("â")
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
context "given t with acute accent" do
|
|
16
|
+
it "returns the char with connecting character" do
|
|
17
|
+
expect(SpecialLatex.convert("\\'{t}")).to eql("t́")
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
context "given ligatures" do
|
|
21
|
+
it "returns the oe lowercase ligature" do
|
|
22
|
+
expect(SpecialLatex.convert("\\oe")).to eql("œ")
|
|
23
|
+
end
|
|
24
|
+
it "returns the oe uppercase ligature" do
|
|
25
|
+
expect(SpecialLatex.convert("\\OE")).to eql("Œ")
|
|
26
|
+
end
|
|
27
|
+
it "returns the ae lowercase ligature" do
|
|
28
|
+
expect(SpecialLatex.convert("\\ae")).to eql("æ")
|
|
29
|
+
end
|
|
30
|
+
it "returns the ae uppercase ligature" do
|
|
31
|
+
expect(SpecialLatex.convert("\\AE")).to eql("Æ")
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
context "given special letters" do
|
|
35
|
+
it "returns lowercase a ring" do
|
|
36
|
+
expect(SpecialLatex.convert("\\aa")).to eql("å")
|
|
37
|
+
end
|
|
38
|
+
it "returns uppercase a ring" do
|
|
39
|
+
expect(SpecialLatex.convert("\\AA")).to eql("Å")
|
|
40
|
+
end
|
|
41
|
+
it "returns lowercase o slash" do
|
|
42
|
+
expect(SpecialLatex.convert("\\o")).to eql("ø")
|
|
43
|
+
end
|
|
44
|
+
it "returns uppercase o slash" do
|
|
45
|
+
expect(SpecialLatex.convert("\\O")).to eql("Ø")
|
|
46
|
+
end
|
|
47
|
+
it "returns german double s" do
|
|
48
|
+
expect(SpecialLatex.convert("\\ss")).to eql("ß")
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
context "given a special symbol" do
|
|
52
|
+
it "returns the euro symbol" do
|
|
53
|
+
expect(SpecialLatex.convert("\\euro")).to eql("€")
|
|
54
|
+
end
|
|
55
|
+
it "returns the degree symbol" do
|
|
56
|
+
expect(SpecialLatex.convert("\\textdegree")).to eql("°")
|
|
57
|
+
end
|
|
58
|
+
it "returns the percent symbol" do
|
|
59
|
+
expect(SpecialLatex.convert("\\%")).to eql("%")
|
|
60
|
+
end
|
|
61
|
+
it "returns the dollar symbol" do
|
|
62
|
+
expect(SpecialLatex.convert("\\$")).to eql("$")
|
|
63
|
+
end
|
|
64
|
+
it "returns the left bracket" do
|
|
65
|
+
expect(SpecialLatex.convert("\\{")).to eql("{")
|
|
66
|
+
end
|
|
67
|
+
it "returns the right bracket" do
|
|
68
|
+
expect(SpecialLatex.convert("\\}")).to eql("}")
|
|
69
|
+
end
|
|
70
|
+
it "returns the underscore" do
|
|
71
|
+
expect(SpecialLatex.convert("\\_")).to eql("_")
|
|
72
|
+
end
|
|
73
|
+
it "returns the paragraph mark" do
|
|
74
|
+
expect(SpecialLatex.convert("\\P")).to eql("¶")
|
|
75
|
+
end
|
|
76
|
+
it "returns the daggar symbol" do
|
|
77
|
+
expect(SpecialLatex.convert("\\dag")).to eql("†")
|
|
78
|
+
end
|
|
79
|
+
it "returns the double daggar symbol" do
|
|
80
|
+
expect(SpecialLatex.convert("\\ddag")).to eql("‡")
|
|
81
|
+
end
|
|
82
|
+
it "returns the pipe" do
|
|
83
|
+
expect(SpecialLatex.convert("\\textbar")).to eql("|")
|
|
84
|
+
end
|
|
85
|
+
it "returns the greater than symbol" do
|
|
86
|
+
expect(SpecialLatex.convert("\\textgreater")).to eql(">")
|
|
87
|
+
end
|
|
88
|
+
it "returns the less than symbol" do
|
|
89
|
+
expect(SpecialLatex.convert("\\textless")).to eql("<")
|
|
90
|
+
end
|
|
91
|
+
it "returns an endash" do
|
|
92
|
+
expect(SpecialLatex.convert("\\textendash")).to eql("–")
|
|
93
|
+
end
|
|
94
|
+
it "returns an emdash" do
|
|
95
|
+
expect(SpecialLatex.convert("\\textemdash")).to eql("—")
|
|
96
|
+
end
|
|
97
|
+
it "returns a trademark" do
|
|
98
|
+
expect(SpecialLatex.convert("\\texttrademark")).to eql("™")
|
|
99
|
+
end
|
|
100
|
+
it "returns a registered trademark" do
|
|
101
|
+
expect(SpecialLatex.convert("\\textregistered")).to eql("®")
|
|
102
|
+
end
|
|
103
|
+
it "returns an endash" do
|
|
104
|
+
expect(SpecialLatex.convert("\\textendash")).to eql("–")
|
|
105
|
+
end
|
|
106
|
+
it "returns an emdash" do
|
|
107
|
+
expect(SpecialLatex.convert("\\textemdash")).to eql("—")
|
|
108
|
+
end
|
|
109
|
+
it "returns an upside down exclaimation" do
|
|
110
|
+
expect(SpecialLatex.convert("\\textexclamdown")).to eql("¡")
|
|
111
|
+
end
|
|
112
|
+
it "returns an upside down question mark" do
|
|
113
|
+
expect(SpecialLatex.convert("\\textquestiondown")).to eql("¿")
|
|
114
|
+
end
|
|
115
|
+
it "returns a pound symbol" do
|
|
116
|
+
expect(SpecialLatex.convert("\\pounds")).to eql("£")
|
|
117
|
+
end
|
|
118
|
+
it "returns a hash" do
|
|
119
|
+
expect(SpecialLatex.convert("\\#")).to eql("#")
|
|
120
|
+
end
|
|
121
|
+
it "returns an ampersand" do
|
|
122
|
+
expect(SpecialLatex.convert("\\&")).to eql("&")
|
|
123
|
+
end
|
|
124
|
+
it "returns a section sign" do
|
|
125
|
+
expect(SpecialLatex.convert("\\S")).to eql("§")
|
|
126
|
+
end
|
|
127
|
+
it "returns a copyright symbol" do
|
|
128
|
+
expect(SpecialLatex.convert("\\copyright")).to eql("©")
|
|
129
|
+
end
|
|
130
|
+
it "returns greek letters" do
|
|
131
|
+
expect(SpecialLatex.convert("\\alpha")).to eql("α")
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: special_latex
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Andrew Rogers
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-09-03 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rspec
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
description: Converts certain LaTeX special character commands into those special
|
|
28
|
+
characters.
|
|
29
|
+
email:
|
|
30
|
+
- andrew@anime-night.com
|
|
31
|
+
executables: []
|
|
32
|
+
extensions: []
|
|
33
|
+
extra_rdoc_files: []
|
|
34
|
+
files:
|
|
35
|
+
- lib/special_latex.rb
|
|
36
|
+
- spec/special_latex_spec.rb
|
|
37
|
+
homepage:
|
|
38
|
+
licenses:
|
|
39
|
+
- MIT
|
|
40
|
+
metadata: {}
|
|
41
|
+
post_install_message:
|
|
42
|
+
rdoc_options: []
|
|
43
|
+
require_paths:
|
|
44
|
+
- lib
|
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: '0'
|
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
requirements: []
|
|
56
|
+
rubyforge_project:
|
|
57
|
+
rubygems_version: 2.2.5
|
|
58
|
+
signing_key:
|
|
59
|
+
specification_version: 4
|
|
60
|
+
summary: LaTeX special characters
|
|
61
|
+
test_files:
|
|
62
|
+
- spec/special_latex_spec.rb
|