aozora4reader 1.1.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.
- data/.document +5 -0
- data/ChangeLog +158 -0
- data/LICENSE +20 -0
- data/README.rdoc +60 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/aozora4reader.gemspec +57 -0
- data/bin/a4r +25 -0
- data/data/gaiji.txt +3698 -0
- data/data/gaiji2.txt +41 -0
- data/lib/aozora4reader.rb +741 -0
- data/memo.txt +7 -0
- data/sty/aozora.sty +661 -0
- data/sty/aozora4reader.sty +481 -0
- data/sty/aozorakindle.sty +463 -0
- data/test/helper.rb +10 -0
- data/test/test_aozora4reader.rb +138 -0
- metadata +76 -0
data/data/gaiji2.txt
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
「穀」の「禾」に代えて「釆」 \UTF{7cd3} #方丈記
|
|
2
|
+
「姉」の正字、「女+※[#第3水準1-85-57]のつくり」 \UTF{59ca} #最後の一句
|
|
3
|
+
##さんずい+闊 \UTF{24103} #檸檬
|
|
4
|
+
##「木+于」 \UTF{6745} #李陵
|
|
5
|
+
##「革+干」 \UTF{976C} #李陵
|
|
6
|
+
##「木+鑞のつくり」 \UTF{3bff} #01夜明け前
|
|
7
|
+
##「くさかんむり/稾」 \UTF{85f3} #01夜明け前
|
|
8
|
+
##「魚+昜」 \UTF{9c11} #01夜明け前
|
|
9
|
+
##小書き濁点付き平仮名つ {\small{}づ} #それから
|
|
10
|
+
##小書き平仮名ん {\small{}ん} #それから
|
|
11
|
+
「口+堯」 \UTF{5635} #それから
|
|
12
|
+
「口+斗」 \UTF{544c} #金色夜叉
|
|
13
|
+
##「(夕+匕)/手」 \UTF{22ab8} #金色夜叉
|
|
14
|
+
##「捏」の「日」に代えて「臼」 \UTF{63d8} #金色夜叉
|
|
15
|
+
##「孛+鳥」 \UTF{9D53} #故郷
|
|
16
|
+
ローマ数字1 \rensuji{I} #山羊の歌
|
|
17
|
+
ローマ数字2 \rensuji{II} #山羊の歌
|
|
18
|
+
ローマ数字3 \rensuji{III} #山羊の歌
|
|
19
|
+
ローマ数字4 \rensuji{IV} #山羊の歌
|
|
20
|
+
ローマ数字5 \rensuji{V} #山羊の歌
|
|
21
|
+
ローマ数字6 \rensuji{VI} #山羊の歌
|
|
22
|
+
ローマ数字7 \rensuji{VII}
|
|
23
|
+
ローマ数字8 \rensuji{VIII}
|
|
24
|
+
ローマ数字9 \rensuji{IX}
|
|
25
|
+
ローマ数字10 \rensuji{X}
|
|
26
|
+
##「にんべん+孱」 \UTF{50dd} #虞美人草
|
|
27
|
+
「にんべん+愁」 \UTF{50fd} #虞美人草
|
|
28
|
+
##「耳+吾」 \UTF{43b8} #虞美人草
|
|
29
|
+
##「甘+舌」 \UTF{751b} #虞美人草
|
|
30
|
+
「髟/胡」 \UTF{9b0d} #阿Q正伝
|
|
31
|
+
##「さんずい+散」 \UTF{6f75} #高野聖
|
|
32
|
+
「赤+報のつくり」 \UTF{8d67} #浮雲
|
|
33
|
+
「血+半」 \UTF{8845} #最終戦争論
|
|
34
|
+
蛇の目 \UTF{25c9} #青猫
|
|
35
|
+
「糸+遂」 \UTF{7e78} #クリスマス・カロル
|
|
36
|
+
##「木+余」 \UTF{688c} #茶の本
|
|
37
|
+
##「くさかんむり/設」 \UTF{850e} #茶の本
|
|
38
|
+
##「くさかんむり/舛」 \UTF{8348} #茶の本
|
|
39
|
+
##「ころもへん+譫のつくり」 \UTF{895c} #茶の本
|
|
40
|
+
##「囗<力」 \UTF{361e} #茶の本
|
|
41
|
+
##「白+光」 \UTF{3fe0} #神州纐纈城
|
|
@@ -0,0 +1,741 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
# Original source is "青空文庫→TeX(ver. 0.9.5 2004/5/5 psitau)"
|
|
4
|
+
# see: http://psitau.kitunebi.com/aozora.html
|
|
5
|
+
#
|
|
6
|
+
# Also another source is "青空キンドル [Beta]"
|
|
7
|
+
# see: http://a2k.aill.org/
|
|
8
|
+
|
|
9
|
+
require 'nkf'
|
|
10
|
+
|
|
11
|
+
class Aozora4Reader
|
|
12
|
+
|
|
13
|
+
PreambleLineNumber=13
|
|
14
|
+
KANJIPAT = "[々〇〻\u3400-\u9FFF\uF900-\uFAFF※ヶ〆]"
|
|
15
|
+
MAX_SAGE = 15
|
|
16
|
+
|
|
17
|
+
def self.a4r(file)
|
|
18
|
+
self.new(file).main
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def initialize(file)
|
|
22
|
+
@inputfile_name = file
|
|
23
|
+
|
|
24
|
+
@jisage = false
|
|
25
|
+
@log_text = []
|
|
26
|
+
@line_num=0
|
|
27
|
+
@gaiji = {}
|
|
28
|
+
@gaiji2 = {}
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# UTF-8で出力
|
|
32
|
+
def normalize(l)
|
|
33
|
+
##l.gsub!(/&/, '\\\\&')
|
|
34
|
+
l.to_s
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# 全角→半角
|
|
38
|
+
def to_single_byte(str)
|
|
39
|
+
s = str.dup
|
|
40
|
+
if s =~ /[0-9]/
|
|
41
|
+
s.tr!("1234567890", "1234567890")
|
|
42
|
+
elsif s =~ /[一二三四五六七八九〇]/
|
|
43
|
+
s.tr!("一二三四五六七八九〇", "1234567890")
|
|
44
|
+
end
|
|
45
|
+
case s
|
|
46
|
+
when /\d十\d/
|
|
47
|
+
s.sub!(/(\d)十(\d)/, '\1\2')
|
|
48
|
+
when /\d十/
|
|
49
|
+
s.sub!(/(\d)十/, '\{1}0')
|
|
50
|
+
when /十\d/
|
|
51
|
+
s.sub!(/十(\d)/, '1\1')
|
|
52
|
+
when /十/
|
|
53
|
+
s.sub!(/十/, "10")
|
|
54
|
+
end
|
|
55
|
+
if s =~/[!?]/
|
|
56
|
+
s.tr!("!?", "!?")
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
return s
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# ルビの削除(表題等)
|
|
63
|
+
def remove_ruby(str)
|
|
64
|
+
str.gsub(/\\ruby{([^}]+)}{[^}]*}/i){$1}
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# プリアンブルの出力
|
|
68
|
+
def preamble
|
|
69
|
+
title = remove_ruby(@title)
|
|
70
|
+
author = remove_ruby(@author)
|
|
71
|
+
str = <<"END_OF_PRE"
|
|
72
|
+
\\documentclass[a5paper]{tbook}
|
|
73
|
+
%\\documentclass[a5paper, twocolumn]{tbook}
|
|
74
|
+
%\\usepackage[deluxe]{otf}
|
|
75
|
+
\\usepackage[expert, deluxe]{otf}
|
|
76
|
+
%\\usepackage{utf}
|
|
77
|
+
% Bookmarkの文字化け対策(日本語向け)
|
|
78
|
+
\\ifnum 46273=\\euc"B4C1 % 46273 == 0xB4C1 == 漢(EUC-JP)
|
|
79
|
+
\\usepackage{atbegshi}%
|
|
80
|
+
\\AtBeginShipoutFirst{\\special{pdf:tounicode EUC-UCS2}}%
|
|
81
|
+
\\else
|
|
82
|
+
\\usepackage{atbegshi}%
|
|
83
|
+
\\AtBeginShipoutFirst{\\special{pdf:tounicode 90ms-RKSJ-UCS2}}%
|
|
84
|
+
\\fi
|
|
85
|
+
\\usepackage[dvipdfm,bookmarks=false,bookmarksnumbered=false,hyperfootnotes=false,%
|
|
86
|
+
pdftitle={#{title}},%
|
|
87
|
+
pdfauthor={#{author}}]{hyperref}
|
|
88
|
+
\\usepackage{furikana}
|
|
89
|
+
\\usepackage{type1cm}
|
|
90
|
+
\\usepackage[size=large]{aozora4reader}
|
|
91
|
+
\\def\\rubykatuji{\\rubyfamily\\tiny}
|
|
92
|
+
%\\def\\rubykatuji{\\tiny}%for UTF package
|
|
93
|
+
%\\renewenvironment{teihon}{\\comment}{\\endcomment}
|
|
94
|
+
|
|
95
|
+
END_OF_PRE
|
|
96
|
+
|
|
97
|
+
str
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# 底本の表示用
|
|
101
|
+
def postamble
|
|
102
|
+
str = <<"END_OF_POST"
|
|
103
|
+
\\theendnotes
|
|
104
|
+
\\begin{teihon}
|
|
105
|
+
\\clearpage\\null\\newpage\\thispagestyle{empty}
|
|
106
|
+
\\begin{minipage}<y>{\\textheight}
|
|
107
|
+
\\vspace{1\\baselineskip}
|
|
108
|
+
\\scriptsize
|
|
109
|
+
END_OF_POST
|
|
110
|
+
|
|
111
|
+
str
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# アクセントの処理用
|
|
115
|
+
# http://www.aozora.gr.jp/accent_separation.html
|
|
116
|
+
# http://cosmoshouse.com/tools/acc-conv-j.htm
|
|
117
|
+
def translate_accent(l)
|
|
118
|
+
l.gsub!(/([ij]):/){"\\\"{\\#{$1}}"}
|
|
119
|
+
l.gsub!(/([AIOEUaioeu])(['`~^])/){"\\#$2{#$1}"}
|
|
120
|
+
l.gsub!(/([AIOEUaioeu]):/){"\\\"{#$1}"}
|
|
121
|
+
l.gsub!(/([AIOEUaioeu])_/){"\\={#$1}"}
|
|
122
|
+
l.gsub!(/([!?])@/){"#$1'"}
|
|
123
|
+
l.gsub!(/([Aa])&/){"\\r{#$1}"}
|
|
124
|
+
l.gsub!(/AE&/){"\\AE{}"}
|
|
125
|
+
l.gsub!(/ae&/){"\\ae{}"}
|
|
126
|
+
l.gsub!(/OE&/){"\\OE{}"}
|
|
127
|
+
l.gsub!(/oe&/){"\\oe{}"}
|
|
128
|
+
l.gsub!(/s&/){"\\ss{}"}
|
|
129
|
+
l.gsub!(/([cC]),/){"\\c{#$1}"}
|
|
130
|
+
l.gsub!(/〔/,'')
|
|
131
|
+
l.gsub!(/〕/,'')
|
|
132
|
+
return l
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
# 外字の処理用
|
|
137
|
+
def translate_gaiji(l)
|
|
138
|
+
if l =~/※[#([^]]*)、([^、]]*)]/
|
|
139
|
+
if @gaiji2[$1]
|
|
140
|
+
l.gsub!(/※[#([^]]*)、([^、]]*)]/){@gaiji2[$1]}
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
## ※[#「姉」の正字、「女+※[#第3水準1-85-57]のつくり」、256-下-16]
|
|
144
|
+
if l =~/※[#([^]]*※[#[^]]*][^]]*)、([^、]]*)]/
|
|
145
|
+
if @gaiji2[$1]
|
|
146
|
+
l.gsub!(/※[#([^]]*※[#[^]]*][^]]*)、([^、]]*)]/){@gaiji2[$1]}
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
## ※[#「さんずい+闊」]
|
|
150
|
+
if l =~ /※[#「([^]]+?)」]/
|
|
151
|
+
if @gaiji2[$1]
|
|
152
|
+
l.gsub!(/※[#「([^]]+?)」]/){@gaiji2[$1]}
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
if l =~ /※[#[^]]*?※[#[^]]*?[12]\-\d{1,2}\-\d{1,2}[^]]*?][^]]*?]/
|
|
157
|
+
l.gsub!(/※[#([^]]*?)※[#([^]]*?([12]\-\d{1,2}\-\d{1,2})[^]]*?)]([^]]*?)]/){"※\\footnote{#$1"+@gaiji[$3]+"#$4}"}
|
|
158
|
+
end
|
|
159
|
+
if l =~ /※[#[^]]*?([12]\-\d{1,2}\-\d{1,2})[^]]*?]/
|
|
160
|
+
if @gaiji[$1]
|
|
161
|
+
l.gsub!(/※[#([^]]*?([12]\-\d{1,2}\-\d{1,2})[^]]*?)]/){@gaiji[$2]}
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
if l =~ /※[#濁点付き片仮名([ワヰヱヲ])、.*?]/
|
|
165
|
+
l.gsub!(/※[#濁点付き片仮名([ワヰヱヲ])、.*?]/){ "\\ajLig{#{$1}゛}"}
|
|
166
|
+
end
|
|
167
|
+
if l =~ /※[#感嘆符三つ.*]/
|
|
168
|
+
l.gsub!(/※[#感嘆符三つ.*?]/){ "\\rensuji{!!!}"}
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
if l =~ /※[#.*?([A-Za-z0-9_]+\.png).*?]/
|
|
172
|
+
l.gsub!(/※[#([^]]+?)]/, "\\includegraphics{#{$1}}")
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
if l =~ /※[#[^]]+?]/
|
|
176
|
+
l.gsub!(/※[#([^]]+?)]/, '※\\footnote{\1}')
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
if l =~ /※/
|
|
180
|
+
STDERR.puts("Remaining Unprocessed Gaiji Character in Line #@line_num.")
|
|
181
|
+
@log_text << normalize("未処理の外字が#{@line_num}行目にあります.\n")
|
|
182
|
+
end
|
|
183
|
+
return l
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
# ルビの処理用
|
|
187
|
+
def translate_ruby(l)
|
|
188
|
+
|
|
189
|
+
# 被ルビ文字列内に外字の注記があるばあい,ルビ文字列の後ろに移動する
|
|
190
|
+
# ただし,順番が入れ替わってしまう
|
|
191
|
+
while l =~ /※\\footnote\{[^(?:\\footnote)]+\}(?:#{KANJIPAT}|(?:\\UTF\{[0-9a-fA-F]+\}|\\CID\{[0-9]+\}))*?《.+?》/
|
|
192
|
+
l.sub!(/(※)(\\footnote\{[^(?:\\footnote)]+\})((?:#{KANJIPAT}|(?:\\UTF\{[0-9a-fA-F]+\}|\\CID\{[0-9]+\}))*?《.+?》)/, '\1\3\2')
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# 被ルビ文字列内に誤記などの注記が存在する場合は、ルビの後ろに移動する
|
|
196
|
+
while l =~ /(?:#{KANJIPAT}|(?:\\UTF\{[0-9a-fA-F]+\}|\\CID\{[0-9]+\}))+?[#[^]]*?](?:#{KANJIPAT}|(?:\\UTF\{[0-9a-fA-F]+\}|\\CID\{[0-9]+\}))*?《.+?》/
|
|
197
|
+
l.sub!(/((?:#{KANJIPAT}|(?:\\UTF\{[0-9a-fA-F]+\}|\\CID\{[0-9]+\}))+?)([#[^]]*?])((?:#{KANJIPAT}|(?:\\UTF\{[0-9a-fA-F]+\}|\\CID\{[0-9]+\}))*?《.+?》)/, '\1\3\2')
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# ルビ文字列内に誤記などの注記が存在する場合は、ルビの後ろに移動する
|
|
201
|
+
if l =~ /《[^》]*?[#[^]]*?][^》]*?》/
|
|
202
|
+
l.gsub!(/(《[^》]*?)([#[^]]*?])([^》]*?》)/, '\1\3\2')
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
# 一連のルビの処理
|
|
206
|
+
# 1 縦棒ありの場合
|
|
207
|
+
if l =~ /|/
|
|
208
|
+
l.gsub!(/|(.+?)《(.+?)》/, '\\ruby{\1}{\2}')
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
# 2 漢字および外字
|
|
212
|
+
if l =~ /(?:#{KANJIPAT}|(?:\\UTF\{[0-9a-fA-F]+\}|\\CID\{[0-9]+\}))+?《.+?》/
|
|
213
|
+
l.gsub!(/((?:#{KANJIPAT}|(?:\\UTF\{[0-9a-fA-F]+\}|\\CID\{[0-9]+\}))+?)《(.+?)》/, '\\ruby{\1}{\2}')
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
# 3 ひらがな
|
|
217
|
+
if l =~ /[あ-ん](?:[ぁ-んーヽヾ]|\\CID\{12107\})*?《.+?》/
|
|
218
|
+
l.gsub!(/([あ-ん](?:[ぁ-んーヽヾ]|\\CID\{12107\})*?)《(.+?)》/, '\\ruby{\1}{\2}')
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
# 4 カタカナ
|
|
222
|
+
if l =~ /[ア-ヴ](?:[ァ-ヴーゝゞ]|\\CID\{12107\})*?《.+?》/
|
|
223
|
+
l.gsub!(/([ア-ヴ](?:[ァ-ヴーゝゞ]|\\CID\{12107\})*?)《(.+?)》/, '\\ruby{\1}{\2}')
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
# 5 全角アルファベットなど
|
|
227
|
+
if l =~ /[A-Za-zΑ-Ωα-ωА-Яа-я・]+?《.+?》/
|
|
228
|
+
l.gsub!(/([A-Za-zΑ-Ωα-ωА-Яа-я・]+?)《(.+?)》/, '\\ruby{\1}{\2}')
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
# 6 半角英数字
|
|
232
|
+
if l =~ /[A-Za-z0-9#_\-\;\&.\'\^\`\\\{\} ]+?《.+?》/
|
|
233
|
+
l.gsub!(/([A-Za-z0-9#_\-\;\&.\'\^\`\\\{\} ]+?)《(.+?)》/, '\\ruby{\1}{\2}')
|
|
234
|
+
end
|
|
235
|
+
if l =~ /《.*?》/
|
|
236
|
+
STDERR.puts("Unknown ruby pattern found in #@line_num.")
|
|
237
|
+
@log_text << normalize("未処理のルビが#{@line_num}行目にあります.\n")
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
return l
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
# 傍点の処理用
|
|
244
|
+
def translate_bouten(l)
|
|
245
|
+
bouten_list = [
|
|
246
|
+
["傍点", "bou"],
|
|
247
|
+
["白ゴマ傍点","sirogomabou"],
|
|
248
|
+
["丸傍点","marubou"],
|
|
249
|
+
["白丸傍点","siromarubou"],
|
|
250
|
+
["黒三角傍点","kurosankakubou"],
|
|
251
|
+
["白三角傍点","sirosankakubou"],
|
|
252
|
+
["二重丸傍点","nijyuumarubou"],
|
|
253
|
+
["蛇の目傍点","jyanomebou"]]
|
|
254
|
+
|
|
255
|
+
bouten_list.each{ |name, fun|
|
|
256
|
+
if l =~ /[#「.+?」に#{name}]/
|
|
257
|
+
l.gsub!(/(.+?)[#.*?「\1」に#{name}]/){
|
|
258
|
+
str = $1
|
|
259
|
+
str.gsub!(/(\\UTF{.+?})/){ "{"+$1+"}"}
|
|
260
|
+
str.gsub!(/(\\ruby{.+?}{.+?})/i){ "{"+$1+"}"}
|
|
261
|
+
"\\#{fun}{"+str+"}"
|
|
262
|
+
}
|
|
263
|
+
end
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if l =~ /[#傍点].+?[#傍点終わり]/
|
|
267
|
+
l.gsub!(/[#傍点](.+?)[#傍点終わり]/){
|
|
268
|
+
str = $1
|
|
269
|
+
str.gsub!(/(\\UTF{.+?})/){ "{"+$1+"}"}
|
|
270
|
+
str.gsub!(/(\\ruby{.+?}{.+?})/i){ "{"+$1+"}"}
|
|
271
|
+
"\\bou{"+str+"}"
|
|
272
|
+
}
|
|
273
|
+
end
|
|
274
|
+
return l
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
# 傍線の処理用
|
|
278
|
+
def translate_bousen(l)
|
|
279
|
+
if l =~ /[#「.+?」に傍線]/
|
|
280
|
+
l.gsub!(/(.+?)[#「\1」に傍線]/, '\\bousen{\1}')
|
|
281
|
+
end
|
|
282
|
+
if l =~ /[#「.+?」に二重傍線]/
|
|
283
|
+
l.gsub!(/(.+?)[#「\1」に二重傍線]/, '\\bousen{\1}')
|
|
284
|
+
end
|
|
285
|
+
if l =~ /[#「.+?」に鎖線]/
|
|
286
|
+
l.gsub!(/(.+?)[#「\1」に鎖線]/, '\\bousen{\1}')
|
|
287
|
+
end
|
|
288
|
+
if l =~ /[#「.+?」に破線]/
|
|
289
|
+
l.gsub!(/(.+?)[#「\1」に破線]/, '\\bousen{\1}')
|
|
290
|
+
end
|
|
291
|
+
if l =~ /[#「.+?」に波線]/
|
|
292
|
+
l.gsub!(/(.+?)[#「\1」に波線]/, '\\bousen{\1}')
|
|
293
|
+
end
|
|
294
|
+
return l
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
# ルビの調整
|
|
298
|
+
def tuning_ruby(l)
|
|
299
|
+
|
|
300
|
+
# 1 直前が漢字の場合
|
|
301
|
+
if l =~ /(?:#{KANJIPAT}|(?:\\UTF\{[0-9a-fA-F]+\}|\\CID\{[0-9]+\}))\\ruby/
|
|
302
|
+
l.gsub!(/((?:#{KANJIPAT}|(?:\\UTF\{[0-9a-fA-F]+\}|\\CID\{[0-9]+\})))\\ruby/, '\1\\Ruby')
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
# 2 直後が漢字の場合
|
|
306
|
+
if l =~ /\\ruby\{(?:#{KANJIPAT}|(?:\\UTF\{[0-9a-fA-F]+\}|\\CID\{[0-9]+\}))+?\}\{(?:[^\\\{\}]|(?:\\UTF\{[0-9a-fA-F]+\}|\\CID\{[0-9]+\}))+?\}(?:#{KANJIPAT}|(?:\\UTF\{[0-9a-fA-F]+\}|\\CID\{[0-9]+\}))/
|
|
307
|
+
l.gsub!(/\\ruby(\{(?:#{KANJIPAT}|(?:\\UTF\{[0-9a-fA-F]+\}|\\CID\{[0-9]+\}))+?\}\{(?:[^\\\{\}]|(?:\\UTF\{[0-9a-fA-F]+\}|\\CID\{[0-9]+\}))+?\}(?:#{KANJIPAT}|(?:\\UTF\{[0-9a-fA-F]+\}|\\CID\{[0-9]+\})))/, '\\Ruby\1')
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
# 3 ルビが連続する場合
|
|
311
|
+
while l =~ /\\(?:ruby|RUBY|Ruby)\{(?:#{KANJIPAT}|(?:\\UTF\{[0-9a-fA-F]+\}|\\CID\{[0-9]+\}))+?\}\{(?:[^\\{}]|(?:\\UTF\{[0-9a-fA-F]+\}|\\CID\{[0-9]+\}))+?\}\\ruby/
|
|
312
|
+
l.sub!(/\\(?:ruby|RUBY|Ruby)(\{(?:#{KANJIPAT}|(?:\\UTF\{[0-9a-fA-F]+\}|\\CID\{[0-9]+\}))+?\}\{(?:[^\\{}]|(?:\\UTF\{[0-9a-fA-F]+\}|\\CID\{[0-9]+\}))+?\})\\ruby/, '\\RUBY\1\\RUBY')
|
|
313
|
+
end
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
# 傍点の調整
|
|
317
|
+
def tuning_bou(l)
|
|
318
|
+
# 傍点の中の「くの字点」を変換
|
|
319
|
+
while l =~ /(\\[a-z]*?bou\{(?:\w|(?:\\UTF\{[0-9a-fA-F]+\}|\\CID\{[0-9]+\}))+?)(\\ajD?Kunoji)\{\}((?:\w|(?:\\UTF\{[0-9a-fA-F]+\}|\\CID\{[0-9]+\}))*?)\}/
|
|
320
|
+
l.gsub!(/((\\([a-z]*?)bou)\{(?:\w|(?:\\UTF\{[0-9a-fA-F]+\}|\\CID\{[0-9]+\}))+?)(\\ajD?Kunoji)\{\}((?:\w|(?:\\UTF\{[0-9a-fA-F]+\}|\\CID\{[0-9]+\}))*?)\}/, '\1}\4with\3Bou\2{\5}')
|
|
321
|
+
end
|
|
322
|
+
if l =~ /\\[a-z]*?bou\{\}/
|
|
323
|
+
l.gsub!(/\\([a-z]*?)bou\{\}/, '{}')
|
|
324
|
+
end
|
|
325
|
+
return l
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
# 外字用ハッシュを作成
|
|
329
|
+
def load_gaiji
|
|
330
|
+
datadir = File.dirname(__FILE__)+"/../data"
|
|
331
|
+
File.open(datadir+"/gaiji.txt", "r:UTF-8") do |f|
|
|
332
|
+
while gaiji_line = f.gets
|
|
333
|
+
gaiji_line.chomp!
|
|
334
|
+
key, data = gaiji_line.split
|
|
335
|
+
@gaiji[key] = data
|
|
336
|
+
end
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
File.open(datadir+"/gaiji2.txt", "r:UTF-8") do |f|
|
|
340
|
+
while gaiji_line = f.gets
|
|
341
|
+
gaiji_line.chomp!
|
|
342
|
+
key, data = gaiji_line.split
|
|
343
|
+
data.gsub(/#.*$/,'')
|
|
344
|
+
@gaiji2[key] = data
|
|
345
|
+
end
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
#
|
|
351
|
+
# メインパート
|
|
352
|
+
#
|
|
353
|
+
def main
|
|
354
|
+
load_gaiji()
|
|
355
|
+
|
|
356
|
+
# 入出力ファイルの定義
|
|
357
|
+
outputfile_name = @inputfile_name.sub(/\.txt$/, ".tex")
|
|
358
|
+
inputfile = File.open(@inputfile_name, "r:SJIS")
|
|
359
|
+
outputfile = File.open(outputfile_name, "w:UTF-8")
|
|
360
|
+
|
|
361
|
+
# プリアンブルの処理
|
|
362
|
+
empty_line = 0
|
|
363
|
+
in_note = false
|
|
364
|
+
meta_data = []
|
|
365
|
+
while empty_line < 2
|
|
366
|
+
line = inputfile.gets.chomp
|
|
367
|
+
line = NKF::nkf('-wS', line)
|
|
368
|
+
if in_note
|
|
369
|
+
if line =~ /^-+$/
|
|
370
|
+
in_note = false
|
|
371
|
+
break
|
|
372
|
+
end
|
|
373
|
+
else
|
|
374
|
+
if line =~ /^-+$/
|
|
375
|
+
in_note = true
|
|
376
|
+
else
|
|
377
|
+
if line =~ /^$/
|
|
378
|
+
empty_line += 1
|
|
379
|
+
else
|
|
380
|
+
if line =~ /《.*?》/
|
|
381
|
+
translate_ruby(line)
|
|
382
|
+
end
|
|
383
|
+
meta_data << line
|
|
384
|
+
end
|
|
385
|
+
end
|
|
386
|
+
end
|
|
387
|
+
end
|
|
388
|
+
|
|
389
|
+
@line_num += meta_data.size
|
|
390
|
+
@title = normalize(meta_data.shift)
|
|
391
|
+
case meta_data.size
|
|
392
|
+
when 1
|
|
393
|
+
@author = normalize(meta_data.shift)
|
|
394
|
+
when 2
|
|
395
|
+
@subtitle = normalize(meta_data.shift)
|
|
396
|
+
@author = normalize(meta_data.shift)
|
|
397
|
+
when 3
|
|
398
|
+
@subtitle = normalize(meta_data.shift)
|
|
399
|
+
@author = normalize(meta_data.shift)
|
|
400
|
+
@subauthor = normalize(meta_data.shift)
|
|
401
|
+
else
|
|
402
|
+
@subtitle = normalize(meta_data.shift)
|
|
403
|
+
@meta_data = []
|
|
404
|
+
until meta_data.empty?
|
|
405
|
+
@meta_data << normalize(meta_data.shift)
|
|
406
|
+
end
|
|
407
|
+
@subauthor = @meta_data.pop
|
|
408
|
+
@author = @meta_data.pop
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
outputfile.write(preamble())
|
|
412
|
+
|
|
413
|
+
outputfile.print "\\title{"+@title+"}\n"
|
|
414
|
+
outputfile.print "\\subtitle{"+@subtitle+"}\n" if @subtitle
|
|
415
|
+
outputfile.print "\\author{"+@author+"}\n"
|
|
416
|
+
outputfile.print "\\subauthor{"+@subauthor+"}\n" if @subauthor
|
|
417
|
+
|
|
418
|
+
if @meta_data
|
|
419
|
+
@meta_data.each do |data|
|
|
420
|
+
outputfile.print "\\metadata{"+data+"}\n"
|
|
421
|
+
end
|
|
422
|
+
end
|
|
423
|
+
outputfile.print "\\date{}\n"
|
|
424
|
+
|
|
425
|
+
# 本文の処理
|
|
426
|
+
outputfile.print "\\begin{document}\n\\maketitle\n"
|
|
427
|
+
|
|
428
|
+
@line_num += PreambleLineNumber
|
|
429
|
+
while line = inputfile.gets
|
|
430
|
+
@line_num += 1
|
|
431
|
+
line.chomp!
|
|
432
|
+
line = NKF::nkf('-wS', line)
|
|
433
|
+
|
|
434
|
+
break if line =~ /^底本/
|
|
435
|
+
if line =~ /^ 「/
|
|
436
|
+
line.sub!(/^ 「/, "\\mbox{ }\\kern0mm\\inhibitglue「")
|
|
437
|
+
end
|
|
438
|
+
if line =~ /[ワヰヱヲ]゛/
|
|
439
|
+
line.gsub!(/ワ゛/, "\\ajLig{ワ゛}")
|
|
440
|
+
line.gsub!(/ヰ゛/, "\\ajLig{ヰ゛}")
|
|
441
|
+
line.gsub!(/ヱ゛/, "\\ajLig{ヱ゛}")
|
|
442
|
+
line.gsub!(/ヲ゛/, "\\ajLig{ヲ゛}")
|
|
443
|
+
end
|
|
444
|
+
if line =~ /[?!] /
|
|
445
|
+
line.gsub!(/([?!]) /, '\1{}')
|
|
446
|
+
end
|
|
447
|
+
if line =~ /——/
|
|
448
|
+
line.gsub!(/——/, "\\——{}")
|
|
449
|
+
end
|
|
450
|
+
if line =~ //\/
|
|
451
|
+
line.gsub!(//\/, "\\ajKunoji{}")
|
|
452
|
+
end
|
|
453
|
+
if line =~ //″\/
|
|
454
|
+
line.gsub!(//″\/, "\\ajDKunoji{}")
|
|
455
|
+
end
|
|
456
|
+
|
|
457
|
+
=begin
|
|
458
|
+
if line =~ /^ +.+/
|
|
459
|
+
line.gsub!(/^ +([一二三四五六七八九〇十].*)/, '\\section*{\1}')
|
|
460
|
+
end
|
|
461
|
+
=end
|
|
462
|
+
|
|
463
|
+
while line =~ /(.+?)[#(「\1」は横?[1|一]文字[^]]*?)]/
|
|
464
|
+
line = line.sub(/(.+?)[#(「\1」は横?[1|一]文字[^]]*?)]/){"\\ajLig{"+to_single_byte($1)+"}"}
|
|
465
|
+
end
|
|
466
|
+
if line =~ /[#改丁.*?]/
|
|
467
|
+
line.sub!(/[#改丁.*?]/, "\\cleardoublepage")
|
|
468
|
+
end
|
|
469
|
+
if line =~ /[#改[頁|ページ].*?]/
|
|
470
|
+
line.sub!(/[#改[頁|ページ].*?]/, "\\clearpage")
|
|
471
|
+
end
|
|
472
|
+
|
|
473
|
+
if line =~ /〔.*?〕/
|
|
474
|
+
translate_accent(line)
|
|
475
|
+
end
|
|
476
|
+
|
|
477
|
+
if line =~ /※/
|
|
478
|
+
translate_gaiji(line)
|
|
479
|
+
end
|
|
480
|
+
if line =~ /《.*?》/
|
|
481
|
+
translate_ruby(line)
|
|
482
|
+
end
|
|
483
|
+
if line =~ /[#(.+?)傍点]/
|
|
484
|
+
translate_bouten(line)
|
|
485
|
+
end
|
|
486
|
+
if line =~ /[#傍点].+?[#傍点終わり]/
|
|
487
|
+
translate_bouten(line)
|
|
488
|
+
end
|
|
489
|
+
if line =~ /[#「(.+?)」に(?:二重)?[傍鎖破波]線]/
|
|
490
|
+
translate_bousen(line)
|
|
491
|
+
end
|
|
492
|
+
if line =~ /[#この行.*?([1234567890一二三四五六七八九〇十]*)字下げ]/
|
|
493
|
+
outputfile.print "\\begin{jisage}{"+to_single_byte($1)+"}\n"
|
|
494
|
+
line = line.sub(/[#この行.*?字下げ]/, "")+"\n\\end{jisage}"
|
|
495
|
+
@line_num += 2
|
|
496
|
+
end
|
|
497
|
+
|
|
498
|
+
if line =~ /[#ここから地から.+字上げ]/
|
|
499
|
+
line.sub!(/[#ここから地から([1234567890一二三四五六七八九〇十]*)字上げ]/){"\\begin{flushright}\\advance\\rightskip"+to_single_byte($1)+"zw"}
|
|
500
|
+
@jisage = true
|
|
501
|
+
end
|
|
502
|
+
if line =~ /[#ここで字上げ終わり]/
|
|
503
|
+
line.sub!(/[#ここで字上げ終わり]/){"\\end{flushright}"}
|
|
504
|
+
@jisage = false
|
|
505
|
+
end
|
|
506
|
+
|
|
507
|
+
if line =~ /[#ここから改行天付き、折り返して.*?字下げ]/
|
|
508
|
+
if @jisage
|
|
509
|
+
outputfile.print "\\end{jisage}\n"
|
|
510
|
+
@line_num += 1
|
|
511
|
+
end
|
|
512
|
+
line.sub!(/[#ここから改行天付き、折り返して([1234567890一二三四五六七八九〇十]*)字下げ]/){"\\begin{jisage}{#{to_single_byte($1)}}\\setlength\\parindent{-"+to_single_byte($1)+"zw}"}
|
|
513
|
+
@jisage = true
|
|
514
|
+
end
|
|
515
|
+
|
|
516
|
+
if line =~ /[#.*?字下げ[^]]*?(?:終わり|まで)[^]]*?]/
|
|
517
|
+
line = line.sub(/[#.*?字下げ.*?(?:終わり|まで).*?]/, "")+"\\end{jisage}"
|
|
518
|
+
@jisage = false
|
|
519
|
+
end
|
|
520
|
+
if line =~ /[#(ここから|これより|ここより|以下).+字下げ.*?]/
|
|
521
|
+
if @jisage
|
|
522
|
+
outputfile.print "\\end{jisage}\n"
|
|
523
|
+
@line_num += 1
|
|
524
|
+
end
|
|
525
|
+
line.sub!(/[#(ここから|これより|ここより|以下).*?([1234567890一二三四五六七八九〇十]*)字下げ.*?]/){"\\begin{jisage}{"+to_single_byte($2)+"}"}
|
|
526
|
+
@jisage = true
|
|
527
|
+
end
|
|
528
|
+
if line =~ /^[#ここから地付き]$/
|
|
529
|
+
@jisage = true
|
|
530
|
+
line = "\\begin{flushright}"
|
|
531
|
+
end
|
|
532
|
+
if line =~ /^[#ここで地付き終わり]$/
|
|
533
|
+
line = "\\end{flushright}"
|
|
534
|
+
@jisage = false
|
|
535
|
+
end
|
|
536
|
+
|
|
537
|
+
if line =~ /[#.*?地付き.*?]$/
|
|
538
|
+
line = "\\begin{flushright}\n"+line.sub(/[#.*?地付き.*?]$/, "\\end{flushright}")
|
|
539
|
+
@line_num += 1
|
|
540
|
+
elsif line =~ /[#.*?地付き.*?]/
|
|
541
|
+
line = line.sub(/[#.*?地付き.*?]/, "\\begin{flushright}\n")+"\\end{flushright}"
|
|
542
|
+
@line_num += 1
|
|
543
|
+
end
|
|
544
|
+
if line =~ /[#.*?(?:行末|地)(?:から|より).*?([1234567890一二三四五六七八九〇十]*)字上.*?]$$/
|
|
545
|
+
line = "\\begin{flushright}\\advance\\rightskip"+to_single_byte($1)+"zw\n"+line.sub(/[#.*?(?:行末|地)(?:から|より).*?字上.*?]$/, "\\end{flushright}")
|
|
546
|
+
@line_num += 1
|
|
547
|
+
elsif line =~ /^(.*?)[#.*?(?:行末|地)(?:から|より).*?([1234567890一二三四五六七八九〇十]*)字上.*?](.*)$/
|
|
548
|
+
line = $1+"\\begin{flushright}\\advance\\rightskip"+to_single_byte($2)+"zw\n"+$3+"\\end{flushright}"
|
|
549
|
+
@line_num += 1
|
|
550
|
+
end
|
|
551
|
+
if line =~ /[#「.+?」は返り点]/
|
|
552
|
+
line.gsub!(/(.+)[#「\1」は返り点]/, '\\kaeriten{\ajKunten{\1}}')
|
|
553
|
+
end
|
|
554
|
+
if line =~ /[#[一二三上中下甲乙丙丁レ]*]/
|
|
555
|
+
line.gsub!(/[#([一二三上中下甲乙丙丁レ]*)]/, '\\kaeriten{\ajKunten{\1}}')
|
|
556
|
+
end
|
|
557
|
+
if line =~ /[#(.*?)]/
|
|
558
|
+
line.gsub!(/[#((.*?))]/, '\\okurigana{\1}')
|
|
559
|
+
end
|
|
560
|
+
if line =~ /[#「.+?」.*?ママ.*?注記]/
|
|
561
|
+
line.gsub!(/(.+)[#「\1」.*?ママ.*?注記]/, '\\ruby{\1}{ママ}')
|
|
562
|
+
end
|
|
563
|
+
|
|
564
|
+
if line =~ /[#[^]]+(([^)]+.png).*?)[^]]+]/
|
|
565
|
+
line.gsub!(/[#[^]]+(([^)]+.png).*?)[^]]+]/, '\\sashie{\1}')
|
|
566
|
+
end
|
|
567
|
+
|
|
568
|
+
if line =~ /[#([1234567890一二三四五六七八九〇十]*)字下げ]/
|
|
569
|
+
num = to_single_byte($1).to_i
|
|
570
|
+
if num > MAX_SAGE
|
|
571
|
+
num = MAX_SAGE
|
|
572
|
+
end
|
|
573
|
+
outputfile.print "\\begin{jisage}{#{num}}\n"
|
|
574
|
+
line = line.sub(/[#.*?字下げ]/, "")+"\n\\end{jisage}"
|
|
575
|
+
end
|
|
576
|
+
|
|
577
|
+
## ちょっと汚いけど二重指定の対策
|
|
578
|
+
if line =~ /[#「(.*?)」は縦中横][#「(.*?)」は中見出し]/
|
|
579
|
+
line.gsub!(/(.*?)[#「(\1)」は縦中横][#「(\1)」は中見出し]/){"{\\large \\rensuji{#{$1}}}"}
|
|
580
|
+
end
|
|
581
|
+
|
|
582
|
+
if line =~ /[#「(.*?)」は大見出し]/
|
|
583
|
+
line.gsub!(/(.*?)[#「(.*?)」は大見出し]/){"{\\Large #{$1}}"}
|
|
584
|
+
end
|
|
585
|
+
if line =~ /[#「(.*?)」は中見出し]/
|
|
586
|
+
line.gsub!(/(.*?)[#「(.*?)」は中見出し]/){"{\\large #{$1}}"}
|
|
587
|
+
end
|
|
588
|
+
if line =~ /[#「(.*?)」は小見出し]/
|
|
589
|
+
line.gsub!(/(.*?)[#「(.*?)」は小見出し]/){"{\\gtfamily #{$1}}"}
|
|
590
|
+
end
|
|
591
|
+
if line =~ /[#小見出し](.*?)[#小見出し終わり]/
|
|
592
|
+
line.gsub!(/[#小見出し](.*?)[#小見出し終わり]/){"{\\gtfamily #{$1}}"}
|
|
593
|
+
end
|
|
594
|
+
if line =~ /[#中見出し](.*?)[#中見出し終わり]/
|
|
595
|
+
line.gsub!(/[#中見出し](.*?)[#中見出し終わり]/){"{\\large #{$1}}"}
|
|
596
|
+
end
|
|
597
|
+
|
|
598
|
+
if line =~ /[#ここから中見出し]/
|
|
599
|
+
line.gsub!(/[#ここから中見出し]/){"{\\large"}
|
|
600
|
+
end
|
|
601
|
+
if line =~ /[#ここで中見出し終わり]/
|
|
602
|
+
line.gsub!(/[#ここで中見出し終わり]/){"}"}
|
|
603
|
+
end
|
|
604
|
+
|
|
605
|
+
if line =~ /[#ページの左右中央]/
|
|
606
|
+
## XXX とりあえず無視
|
|
607
|
+
line.gsub!(/[#ページの左右中央]/, "")
|
|
608
|
+
end
|
|
609
|
+
|
|
610
|
+
## XXX 字詰めは1行の文字数が少ないので無視
|
|
611
|
+
if line =~ /[#ここから([1234567890一二三四五六七八九〇十]*)字詰め]/
|
|
612
|
+
line.gsub!(/[#ここから([1234567890一二三四五六七八九〇十]*)字詰め]/, "")
|
|
613
|
+
end
|
|
614
|
+
if line =~ /[#ここで字詰め終わり]/
|
|
615
|
+
line.gsub!(/[#ここで字詰め終わり]/, "")
|
|
616
|
+
end
|
|
617
|
+
|
|
618
|
+
# XXX 割り注も無視
|
|
619
|
+
if line =~ /[#ここから割り注]/
|
|
620
|
+
line.gsub!(/[#ここから割り注]/, "")
|
|
621
|
+
end
|
|
622
|
+
if line =~ /[#ここで割り注終わり]/
|
|
623
|
+
line.gsub!(/[#ここで割り注終わり]/, "")
|
|
624
|
+
end
|
|
625
|
+
|
|
626
|
+
if line =~ /[#「(.*?)」は太字]/
|
|
627
|
+
line.gsub!(/(.+)[#「\1」は太字]/,'{\\textbf{\1}}')
|
|
628
|
+
end
|
|
629
|
+
if line =~ /[#「.+?」は縦中横]/
|
|
630
|
+
line.gsub!(/(.+)[#「\1」は縦中横]/, '\\rensuji{\1}')
|
|
631
|
+
end
|
|
632
|
+
if line =~ /[#「(1)(/)(\d+)」は分数]/
|
|
633
|
+
bunshi = to_single_byte($1)
|
|
634
|
+
bunbo = $3
|
|
635
|
+
line.gsub!(/(.+)[#「.+?」は分数]/, "\\rensuji{#{bunshi}/#{bunbo}}")
|
|
636
|
+
end
|
|
637
|
+
if line =~ /[#「.+?」は罫囲み]/
|
|
638
|
+
line.gsub!(/(.+)[#「\1」は罫囲み]/, '\\fbox{\1}')
|
|
639
|
+
end
|
|
640
|
+
if line =~ /[#「(.+?)」は(本文より)?([123456])段階大きな文字]/
|
|
641
|
+
line.gsub!(/([^[]+?)[#「\1」は(本文より)?([123456])段階大きな文字]/) {
|
|
642
|
+
num = to_single_byte($3).to_i
|
|
643
|
+
case num
|
|
644
|
+
when 1
|
|
645
|
+
"{\\large #{$1}}"
|
|
646
|
+
when 2
|
|
647
|
+
"{\\Large #{$1}}"
|
|
648
|
+
when 3
|
|
649
|
+
"{\\LARGE #{$1}}"
|
|
650
|
+
when 4
|
|
651
|
+
"{\\huge #{$1}}"
|
|
652
|
+
when 5
|
|
653
|
+
"{\\Huge #{$1}}"
|
|
654
|
+
when 6
|
|
655
|
+
"{\\Huge #{$1}}"
|
|
656
|
+
end
|
|
657
|
+
}
|
|
658
|
+
end
|
|
659
|
+
|
|
660
|
+
if line =~ /[#「.+?」は斜体]/
|
|
661
|
+
line.gsub!(/(.+)[#「\1」は斜体]/){
|
|
662
|
+
shatai = to_single_byte($1).tr("abcdefghijklmnopqrstuvwxyz","abcdefghijklmnopqrstuvwxyz")
|
|
663
|
+
"\\rensuji{\\textsl{"+shatai+"}}"
|
|
664
|
+
}
|
|
665
|
+
end
|
|
666
|
+
if line =~ /[#「[0-90-9]」は下付き小文字]/
|
|
667
|
+
line.gsub!(/([A-Za-za-zA-Zαβδγ])([0-90-9])[#「\2」は下付き小文字]/){
|
|
668
|
+
"$"+$1+"_{"+to_single_byte($2)+"}$"
|
|
669
|
+
}
|
|
670
|
+
end
|
|
671
|
+
if line =~ /([^ ]*)[#ゴシック体]$/
|
|
672
|
+
line.gsub!(/([^ ]*)[#ゴシック体]/){"{\\gtfamily #{$1}}"}
|
|
673
|
+
end
|
|
674
|
+
if line =~ /[#「.+?」はゴシック体]/
|
|
675
|
+
line.gsub!(/(.+?)[#「\1」はゴシック体]/){"{\\gtfamily #{$1}}"}
|
|
676
|
+
end
|
|
677
|
+
|
|
678
|
+
if line =~ /[#ここから横組み](.*?)[#ここで横組み終わり]/
|
|
679
|
+
line.gsub!(/[#ここから横組み](.*?)[#ここで横組み終わり]/){
|
|
680
|
+
yoko_str = $1
|
|
681
|
+
yoko_str.gsub!(/π/,"\\pi ")
|
|
682
|
+
yoko_str.gsub!(/=/,"=")
|
|
683
|
+
yoko_str.gsub!(/(\d+)[#「\1」は指数]/){"^{#{$1}}"}
|
|
684
|
+
"$"+yoko_str+"$"
|
|
685
|
+
}
|
|
686
|
+
end
|
|
687
|
+
line.tr!("┌┐┘└│─┏┓┛┗┃━→","┐┘└┌─│┓┛┗┏━┃↓")
|
|
688
|
+
if line =~ /[#改段]/
|
|
689
|
+
line.sub!(/[#改段]/, "\\clearpage")
|
|
690
|
+
end
|
|
691
|
+
if line =~ /[aioeu]\^/i
|
|
692
|
+
line.gsub!(/([aioeu])\^/i){ "\\\^{#{$1}}"}
|
|
693
|
+
end
|
|
694
|
+
if line =~ /[aioeu]\'/i
|
|
695
|
+
line.gsub!(/([aioeu])\'/i){ "\\\'{#{$1}}"}
|
|
696
|
+
end
|
|
697
|
+
if line =~ /[#天から.*?([1234567890一二三四五六七八九〇十]*)字下げ]/
|
|
698
|
+
num = to_single_byte($1).to_i
|
|
699
|
+
if num > MAX_SAGE
|
|
700
|
+
num = MAX_SAGE
|
|
701
|
+
end
|
|
702
|
+
outputfile.print "\\begin{jisage}{#{num}}\n"
|
|
703
|
+
line = line.sub(/[#天から.*?字下げ]/, "")+"\n\\end{jisage}"
|
|
704
|
+
end
|
|
705
|
+
|
|
706
|
+
line.gsub!(/[#図形 □(四角)に内接する◆]/, '{\setlength{\fboxsep}{0pt}\fbox{◆}}')
|
|
707
|
+
|
|
708
|
+
if line =~ /[#[^]]+?]/
|
|
709
|
+
line.gsub!(/[#([^]]+?)]/, '\\endnote{\1}')
|
|
710
|
+
end
|
|
711
|
+
if line =~ /\\[a-z]*?bou/
|
|
712
|
+
tuning_bou(line)
|
|
713
|
+
end
|
|
714
|
+
if line =~ /\\ajD?Kunoji\{\}\}/
|
|
715
|
+
line.gsub!(/(\\ajD?Kunoji)\{\}\}/, '\1}')
|
|
716
|
+
end
|
|
717
|
+
if line =~ /\\ruby/
|
|
718
|
+
tuning_ruby(line)
|
|
719
|
+
end
|
|
720
|
+
if line =~ /^$/
|
|
721
|
+
line = " "
|
|
722
|
+
end
|
|
723
|
+
outputfile.print normalize(line)+"\n"
|
|
724
|
+
end
|
|
725
|
+
|
|
726
|
+
# 底本の処理
|
|
727
|
+
outputfile.write(postamble())
|
|
728
|
+
outputfile.print normalize(line)+"\n"
|
|
729
|
+
while line = inputfile.gets
|
|
730
|
+
line.chomp!
|
|
731
|
+
line = NKF::nkf('-wS', line)
|
|
732
|
+
outputfile.print normalize(line)+"\n"
|
|
733
|
+
end
|
|
734
|
+
outputfile.print "\n\\end{minipage}\n\\end{teihon}\n\\end{document}\n"
|
|
735
|
+
if @log_text.size > 0
|
|
736
|
+
until @log_text.empty?
|
|
737
|
+
outputfile.print @log_text.shift
|
|
738
|
+
end
|
|
739
|
+
end
|
|
740
|
+
end
|
|
741
|
+
end
|