wtex 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +19 -0
- data/README +2 -0
- data/README.ja.pdf +0 -0
- data/README.ja.txt +249 -0
- data/bin/wikitex +50 -0
- data/lib/wtex.rb +271 -0
- data/skel/Makefile +16 -0
- data/skel/body.txt +2 -0
- data/skel/head.tex +3 -0
- data/skel/out/tmpl.dvi +1 -0
- data/skel/tmpl.tex.report +81 -0
- data/skel/tmpl.tex.tbook +85 -0
- data/t/t.rb +13 -0
- data/t/test_wtex.rb +455 -0
- data/t/test_wtex_bin.rb +37 -0
- data/t/test_wtex_inline.rb +149 -0
- data/t/test_wtex_skip.rb +218 -0
- metadata +99 -0
data/t/test_wtex_bin.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# Author:: Akira FUNAI
|
4
|
+
# Copyright:: Copyright (c) 2011 Akira FUNAI
|
5
|
+
|
6
|
+
require "#{::File.dirname __FILE__}/t"
|
7
|
+
require 'fileutils'
|
8
|
+
|
9
|
+
class TC_WTeX_Bin < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@tmp_dir = ::File.expand_path('./tmp', ::File.dirname(__FILE__))
|
13
|
+
::FileUtils.rm_r ::Dir.glob("#{@tmp_dir}/*")
|
14
|
+
end
|
15
|
+
|
16
|
+
def teardown
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_bin
|
20
|
+
::Dir.chdir(@tmp_dir) do
|
21
|
+
system('../../bin/wikitex init foobar 2>/dev/null')
|
22
|
+
assert(
|
23
|
+
::File.exists?('./foobar'),
|
24
|
+
"'init' command should copy skeltons to the target directory"
|
25
|
+
)
|
26
|
+
|
27
|
+
::Dir.chdir('./foobar') do
|
28
|
+
system('../../../bin/wikitex convert')
|
29
|
+
assert(
|
30
|
+
::File.size?('./body.tex'),
|
31
|
+
"'convert' command should convert body.txt into out/body.tex"
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# Author:: Akira FUNAI
|
4
|
+
# Copyright:: Copyright (c) 2011 Akira FUNAI
|
5
|
+
|
6
|
+
require "#{::File.dirname __FILE__}/t"
|
7
|
+
|
8
|
+
class TC_WTeX_Inline < Test::Unit::TestCase
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@wt = WTeX.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_tex_ruby_basic
|
18
|
+
assert_equal(
|
19
|
+
"これは\\ruby{漢字}{かんじ}です\n",
|
20
|
+
@wt.tex('これは漢字《かんじ》です'),
|
21
|
+
'WTeX#tex should deal with Japanese ruby characters'
|
22
|
+
)
|
23
|
+
assert_equal(
|
24
|
+
"これは\\ruby{カタカナ}{かたかな}です\n",
|
25
|
+
@wt.tex('これはカタカナ《かたかな》です'),
|
26
|
+
'WTeX#tex should deal with Japanese ruby characters'
|
27
|
+
|
28
|
+
)
|
29
|
+
assert_equal(
|
30
|
+
"これは\\ruby{コンピュータ}{電子計算機}です\n",
|
31
|
+
@wt.tex('これはコンピュータ《電子計算機》です'),
|
32
|
+
'WTeX#tex should deal with Japanese ruby characters'
|
33
|
+
|
34
|
+
)
|
35
|
+
assert_equal(
|
36
|
+
"\\ruby{コンピュータ}{電子計算機}\n",
|
37
|
+
@wt.tex('コンピュータ《電子計算機》'),
|
38
|
+
'WTeX#tex should deal with Japanese ruby characters'
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_tex_ruby_border_implicit
|
43
|
+
assert_equal(
|
44
|
+
"でした。\\\\\n\\ruby{算盤}{そろばん}\n",
|
45
|
+
@wt.tex("でした。\n算盤《そろばん》"),
|
46
|
+
'WTeX#tex should detect boundaries of strings with/without rubies implicitly'
|
47
|
+
)
|
48
|
+
assert_equal(
|
49
|
+
"はい、\\ruby{算盤}{そろばん}\n",
|
50
|
+
@wt.tex('はい、算盤《そろばん》'),
|
51
|
+
'WTeX#tex should detect boundaries of strings with/without rubies implicitly'
|
52
|
+
)
|
53
|
+
assert_equal(
|
54
|
+
" \\ruby{算盤}{そろばん}\n",
|
55
|
+
@wt.tex(' 算盤《そろばん》'),
|
56
|
+
'WTeX#tex should detect boundaries of strings with/without rubies implicitly'
|
57
|
+
)
|
58
|
+
assert_equal(
|
59
|
+
" \\ruby{算盤}{そろばん}\n",
|
60
|
+
@wt.tex(' 算盤《そろばん》'),
|
61
|
+
'WTeX#tex should detect boundaries of strings with/without rubies implicitly'
|
62
|
+
)
|
63
|
+
assert_equal(
|
64
|
+
"「はい」\\ruby{算盤}{そろばん}\n",
|
65
|
+
@wt.tex('「はい」算盤《そろばん》'),
|
66
|
+
'WTeX#tex should detect boundaries of strings with/without rubies implicitly'
|
67
|
+
)
|
68
|
+
assert_equal(
|
69
|
+
"ん?\\ruby{算盤}{そろばん}\n",
|
70
|
+
@wt.tex('ん?算盤《そろばん》'),
|
71
|
+
'WTeX#tex should detect boundaries of strings with/without rubies implicitly'
|
72
|
+
)
|
73
|
+
assert_equal(
|
74
|
+
"♪\\ruby{算盤}{そろばん}\n",
|
75
|
+
@wt.tex('♪算盤《そろばん》'),
|
76
|
+
'WTeX#tex should detect boundaries of strings with/without rubies implicitly'
|
77
|
+
)
|
78
|
+
assert_equal(
|
79
|
+
"…\\ruby{算盤}{そろばん}\n",
|
80
|
+
@wt.tex('…算盤《そろばん》'),
|
81
|
+
'WTeX#tex should detect boundaries of strings with/without rubies implicitly'
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_tex_ruby_border_explicit
|
86
|
+
assert_equal(
|
87
|
+
"大規模\\ruby{輻輳}{ふくそう}\n",
|
88
|
+
@wt.tex('大規模|輻輳《ふくそう》'),
|
89
|
+
'WTeX#tex should detect boundaries of ruby characters by a pipe character'
|
90
|
+
)
|
91
|
+
assert_equal(
|
92
|
+
"大規模\\ruby{輻輳}{ふくそう}\n",
|
93
|
+
@wt.tex('大規模|輻輳《ふくそう》'),
|
94
|
+
'WTeX#tex should detect boundaries of ruby characters by a pipe character'
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_tex_ruby_multiple
|
99
|
+
assert_equal(
|
100
|
+
"\\ruby{コンピュータ}{電子計算機}、\\ruby{算盤}{そろばん}\n",
|
101
|
+
@wt.tex('コンピュータ《電子計算機》、算盤《そろばん》'),
|
102
|
+
'WTeX#tex should deal with mutiple ruby commands'
|
103
|
+
)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_tex_strong
|
107
|
+
assert_equal(
|
108
|
+
"{\\large\\bf foobar}\n",
|
109
|
+
@wt.tex('**foobar**'),
|
110
|
+
'WTeX#tex should deal with strong characters'
|
111
|
+
)
|
112
|
+
assert_equal(
|
113
|
+
"{\\LARGE\\bf foobar}\n",
|
114
|
+
@wt.tex('***foobar***'),
|
115
|
+
'WTeX#tex should deal with strong characters'
|
116
|
+
)
|
117
|
+
assert_equal(
|
118
|
+
"{\\Huge\\bf foobar}\n",
|
119
|
+
@wt.tex('****foobar****'),
|
120
|
+
'WTeX#tex should deal with strong characters'
|
121
|
+
)
|
122
|
+
|
123
|
+
assert_equal(
|
124
|
+
"qux {\\large\\bf foobar} aaa\n",
|
125
|
+
@wt.tex('qux **foobar** aaa'),
|
126
|
+
'WTeX#tex should deal with strong characters'
|
127
|
+
)
|
128
|
+
assert_equal(
|
129
|
+
"qux {\\Huge\\bf foobar} aaa\n",
|
130
|
+
@wt.tex('qux ****foobar**** aaa'),
|
131
|
+
'WTeX#tex should deal with strong characters'
|
132
|
+
)
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_tex_underline
|
136
|
+
assert_equal(
|
137
|
+
"\\WTunderline{foobar}\n",
|
138
|
+
@wt.tex('__foobar__'),
|
139
|
+
'WTeX#tex should deal with underlined characters'
|
140
|
+
)
|
141
|
+
|
142
|
+
assert_equal(
|
143
|
+
"foo \\WTunderline{foobar} bar\n",
|
144
|
+
@wt.tex('foo __foobar__ bar'),
|
145
|
+
'WTeX#tex should deal with underlined characters'
|
146
|
+
)
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
data/t/test_wtex_skip.rb
ADDED
@@ -0,0 +1,218 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# Author:: Akira FUNAI
|
4
|
+
# Copyright:: Copyright (c) 2011 Akira FUNAI
|
5
|
+
|
6
|
+
require "#{::File.dirname __FILE__}/t"
|
7
|
+
|
8
|
+
class TC_WTeX_Skip < Test::Unit::TestCase
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@wt = WTeX.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_tex_escape_specials
|
18
|
+
assert_equal(
|
19
|
+
"\\\#{} \\%{} \\&{} \\_{}\n",
|
20
|
+
@wt.tex('# % & _'),
|
21
|
+
'WTeX#tex should escape all special characters in non-TeX paragraphs'
|
22
|
+
)
|
23
|
+
assert_equal(
|
24
|
+
"\\textless{} \\textgreater{} \\textasciitilde{} \\textbar{} \\textasciicircum{}\n",
|
25
|
+
@wt.tex('< > ^ | ~'),
|
26
|
+
'WTeX#tex should escape all special characters in non-TeX paragraphs'
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_tex_skip_command
|
31
|
+
assert_equal(
|
32
|
+
"foo \\bar baz\n",
|
33
|
+
@wt.tex("foo \\bar baz"),
|
34
|
+
'WTeX#tex should skip TeX commands beginning with backslash'
|
35
|
+
)
|
36
|
+
assert_equal(
|
37
|
+
"foo \\bar baz \\qux\n",
|
38
|
+
@wt.tex("foo \\bar baz \\qux"),
|
39
|
+
'WTeX#tex should skip TeX commands beginning with backslash'
|
40
|
+
)
|
41
|
+
assert_equal(
|
42
|
+
"foo \\bar baz \\qux\n",
|
43
|
+
@wt.tex("foo \\bar baz \\qux\n"),
|
44
|
+
'WTeX#tex should skip TeX commands beginning with backslash'
|
45
|
+
)
|
46
|
+
assert_equal(
|
47
|
+
"foo \\bar baz \\qux \\$\n",
|
48
|
+
@wt.tex("foo \\bar baz \\qux \\$\n"),
|
49
|
+
'WTeX#tex should skip TeX commands beginning with backslash'
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_tex_skip_text_math_mode
|
54
|
+
assert_equal(
|
55
|
+
"$\\backslash$\n",
|
56
|
+
@wt.tex('$\backslash$'),
|
57
|
+
'WTeX#tex should skip inside TeX math modes'
|
58
|
+
)
|
59
|
+
assert_equal(
|
60
|
+
"$\\backslash$ foo $\\backslash$ bar\n",
|
61
|
+
@wt.tex('$\backslash$ foo $\backslash$ bar'),
|
62
|
+
'WTeX#tex should skip inside TeX math modes'
|
63
|
+
)
|
64
|
+
|
65
|
+
assert_equal(
|
66
|
+
"$big\\$dollar$\n",
|
67
|
+
@wt.tex('$big\\$dollar$'),
|
68
|
+
'WTeX#tex should be aware of escaped dollar marks inside TeX math modes'
|
69
|
+
)
|
70
|
+
assert_equal(
|
71
|
+
"$big\\$dollar \\$wow$\n",
|
72
|
+
@wt.tex('$big\\$dollar \\$wow$'),
|
73
|
+
'WTeX#tex should be aware of escaped dollar marks inside TeX math modes'
|
74
|
+
)
|
75
|
+
|
76
|
+
w = <<'_eos'
|
77
|
+
foo$
|
78
|
+
sqrt{x} + sqrt{y}
|
79
|
+
$ bar
|
80
|
+
_eos
|
81
|
+
assert_equal(
|
82
|
+
w,
|
83
|
+
@wt.tex(w),
|
84
|
+
'WTeX#tex should be aware of TeX math modes in multiple lines'
|
85
|
+
)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_tex_broken_text_math_mode
|
89
|
+
assert_equal(
|
90
|
+
"\\${}foo\n",
|
91
|
+
@wt.tex('$foo'),
|
92
|
+
'WTeX#tex should escape broken TeX math modes'
|
93
|
+
)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_tex_escape_display_math_mode
|
97
|
+
[
|
98
|
+
"$$foo@baz$$\n",
|
99
|
+
"foo $$foo@baz$$ $$qux@bar$$ foo\n",
|
100
|
+
<<'_eos',
|
101
|
+
foo $$
|
102
|
+
{$bar}
|
103
|
+
{#baz\{%qux
|
104
|
+
$$ foo
|
105
|
+
_eos
|
106
|
+
].each {|w|
|
107
|
+
assert_equal(
|
108
|
+
w,
|
109
|
+
@wt.tex(w),
|
110
|
+
'WTeX#tex should skip inside TeX math modes'
|
111
|
+
)
|
112
|
+
}
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_tex_skip_verb
|
116
|
+
assert_equal(
|
117
|
+
"\\verb|$%{|\n",
|
118
|
+
@wt.tex('\verb|$%{|'),
|
119
|
+
'WTeX#tex should skip inside verb commands'
|
120
|
+
)
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_tex_broken_verb
|
124
|
+
assert_equal(
|
125
|
+
"$\\backslash$verb\\textbar{}abc\n",
|
126
|
+
@wt.tex('\verb|abc'),
|
127
|
+
'WTeX#tex should escape broken verb commands'
|
128
|
+
)
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_tex_skip_curly_brackets
|
132
|
+
assert_equal(
|
133
|
+
"{$%#}\n",
|
134
|
+
@wt.tex('{$%#}'),
|
135
|
+
'WTeX#tex should skip inside curly brackets'
|
136
|
+
)
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_tex_skip_nested_curly_brackets
|
140
|
+
[
|
141
|
+
"{${%#}foo}\n",
|
142
|
+
"{${%#}f{o}o}\n",
|
143
|
+
"{{${%#}}f{o}o}\n",
|
144
|
+
"{{${%#}f{o}o}}\n",
|
145
|
+
"{${%#}f{o}o{}}\n",
|
146
|
+
"{{}${%#}f{o}o}\n",
|
147
|
+
<<'_eos',
|
148
|
+
foo {
|
149
|
+
{$bar}
|
150
|
+
{#baz{%qux}
|
151
|
+
}} foo
|
152
|
+
_eos
|
153
|
+
].each {|w|
|
154
|
+
assert_equal(
|
155
|
+
w,
|
156
|
+
@wt.tex(w),
|
157
|
+
'WTeX#tex should skip nested curly brackets'
|
158
|
+
)
|
159
|
+
}
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_tex_escaped_curly_brackets
|
163
|
+
[
|
164
|
+
"{foo\\}$bar}\n",
|
165
|
+
"{foo\\{$bar}\n",
|
166
|
+
"{\\{foo$bar}\n",
|
167
|
+
"{foo$bar\\}}\n",
|
168
|
+
"{foo\\}$bar\\}$baz}\n",
|
169
|
+
<<'_eos',
|
170
|
+
foo {
|
171
|
+
{$bar}
|
172
|
+
{#baz\{%qux
|
173
|
+
}} foo
|
174
|
+
_eos
|
175
|
+
].each {|w|
|
176
|
+
assert_equal(
|
177
|
+
w,
|
178
|
+
@wt.tex(w),
|
179
|
+
'WTeX#tex should be aware of escaped curly brackets'
|
180
|
+
)
|
181
|
+
}
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_tex_skip_environment
|
185
|
+
[
|
186
|
+
"\\begin{itembox}foo$bar\\end{itembox}\n",
|
187
|
+
"abc \\begin{itembox}foo$bar\\end{itembox} xyz\n",
|
188
|
+
# "\\begin {itembox}foo$bar\\end {itembox} xyz\n",
|
189
|
+
"\\begin{itembox}foo\\begin{mmm}$bar\\end{mmm}\\end{itembox}\n",
|
190
|
+
"\\begin{itembox}foo\\begin{mmm}$bar\\end{mmm}\\end{itembox} foo\n",
|
191
|
+
<<'_eos',
|
192
|
+
\begin{itembox}
|
193
|
+
foo {
|
194
|
+
{$bar}
|
195
|
+
{#baz\\{%qux
|
196
|
+
}} foo
|
197
|
+
\end{itembox} bar
|
198
|
+
_eos
|
199
|
+
<<'_eos',
|
200
|
+
\begin{itembox}
|
201
|
+
foo {
|
202
|
+
\begin{itembox}
|
203
|
+
{$bar}
|
204
|
+
\end{itembox}
|
205
|
+
{#baz\{%qux
|
206
|
+
}} foo \\end{itembox}
|
207
|
+
\end{itembox} bar
|
208
|
+
_eos
|
209
|
+
].each {|w|
|
210
|
+
assert_equal(
|
211
|
+
w,
|
212
|
+
@wt.tex(w),
|
213
|
+
'WTeX#tex should skip inside TeX environments'
|
214
|
+
)
|
215
|
+
}
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wtex
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Akira FUNAI
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-02-20 00:00:00 +09:00
|
18
|
+
default_executable: wikitex
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: jeweler
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 4
|
30
|
+
- 0
|
31
|
+
version: 1.4.0
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
description: |
|
35
|
+
WTeX converts blended source written both in Wiki and TeX into a valid LaTeX source. Also, binary 'wikitex' will prepare templates & Makefile for making the final PDF.
|
36
|
+
|
37
|
+
email: akira@funai.com
|
38
|
+
executables:
|
39
|
+
- wikitex
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files:
|
43
|
+
- LICENSE
|
44
|
+
- README
|
45
|
+
- README.ja.pdf
|
46
|
+
- README.ja.txt
|
47
|
+
files:
|
48
|
+
- README
|
49
|
+
- README.ja.pdf
|
50
|
+
- README.ja.txt
|
51
|
+
- bin/wikitex
|
52
|
+
- lib/wtex.rb
|
53
|
+
- skel/Makefile
|
54
|
+
- skel/body.txt
|
55
|
+
- skel/head.tex
|
56
|
+
- skel/out/tmpl.dvi
|
57
|
+
- skel/tmpl.tex.report
|
58
|
+
- skel/tmpl.tex.tbook
|
59
|
+
- t/t.rb
|
60
|
+
- t/test_wtex.rb
|
61
|
+
- t/test_wtex_bin.rb
|
62
|
+
- t/test_wtex_inline.rb
|
63
|
+
- t/test_wtex_skip.rb
|
64
|
+
- LICENSE
|
65
|
+
has_rdoc: true
|
66
|
+
homepage: http://github.com/afunai/wtex
|
67
|
+
licenses: []
|
68
|
+
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options:
|
71
|
+
- --charset=UTF-8
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
version: "0"
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
requirements: []
|
89
|
+
|
90
|
+
rubyforge_project: wtex
|
91
|
+
rubygems_version: 1.3.6
|
92
|
+
signing_key:
|
93
|
+
specification_version: 3
|
94
|
+
summary: converts blended source written in Wiki and TeX into pure TeX or PDF
|
95
|
+
test_files:
|
96
|
+
- t/test_wtex.rb
|
97
|
+
- t/test_wtex_bin.rb
|
98
|
+
- t/test_wtex_skip.rb
|
99
|
+
- t/test_wtex_inline.rb
|