latex2hiki 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/.yardopts +2 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/Rakefile +42 -0
- data/Rakefile.orig +16 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/exe/#latex2hiki# +5 -0
- data/exe/latex2hiki +5 -0
- data/exe/mk_maple_hiki +5 -0
- data/hikis/README_en.hiki +41 -0
- data/hikis/README_ja.hiki +91 -0
- data/latex2hiki.gemspec +36 -0
- data/latex2hiki.wiki/README.md +63 -0
- data/latex2hiki.wiki/README_en.md +47 -0
- data/latex2hiki.wiki/README_ja.md +102 -0
- data/lib/latex2hiki.rb +35 -0
- data/lib/latex2hiki/latex2hiki.rb +221 -0
- data/lib/latex2hiki/latex2hiki_new.rb +38 -0
- data/lib/latex2hiki/latex2hiki_old.rb +208 -0
- data/lib/latex2hiki/version.rb +3 -0
- data/lib/maple/latex2hiki.rb +222 -0
- data/lib/maple/new_rakefile +50 -0
- data/lib/mk_maple_hiki.rb +178 -0
- metadata +159 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
# Latex2hiki
|
2
|
+
|
3
|
+
CUI application to convert latex document to hiki structure.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'latex2hiki'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```
|
22
|
+
$ gem install latex2hiki
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
|/usr/local/bin|source|description|
|
28
|
+
|:----|:----|:----|
|
29
|
+
|latex2hiki|lib/maple/latex2hiki.rb|basic conversion from latex to hiki format|
|
30
|
+
|mk_maple_hiki|lib/mk_maple_hiki.rb|automatic conversion from latex directory to hiki|
|
31
|
+
|rake maple|Rakefile|Sample codes for specific conversions|
|
32
|
+
|
33
|
+
|
34
|
+
## Development
|
35
|
+
|
36
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec latex2hiki` to use the gem in this directory, ignoring other installed copies of this gem.
|
37
|
+
|
38
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/latex2hiki. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
43
|
+
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# Latex2hiki
|
2
|
+
|
3
|
+
latex文書をhiki構造に変換するCUI.
|
4
|
+
|
5
|
+
単独のファイルを変換するlatex2hikiと,latex文書構成にしたがってhiki構造を作成するmk_maple_hikiとを提供している.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'latex2hiki'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```
|
18
|
+
$ bundle
|
19
|
+
```
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
```
|
24
|
+
$ gem install latex2hiki
|
25
|
+
```
|
26
|
+
|
27
|
+
## latex2hiki usage
|
28
|
+
|
29
|
+
```
|
30
|
+
latex2hiki sample.tex > sample.hiki
|
31
|
+
|
32
|
+
```
|
33
|
+
## mk_maple_hiki usage
|
34
|
+
mk_maple_hikiは,目次にしたがって構造化されたhikiサイトを自動構築することを目指している.
|
35
|
+
|
36
|
+
|
37
|
+
|options|操作|DIR_NAME/.latex2hiki_rcの初期値|
|
38
|
+
|:----|:----|:----|
|
39
|
+
|--init [DIR_NAME]| ベースとなるlatexサイトを構築する,Rakefile, figures, .latex2hiki_rcを作成|
|
40
|
+
|--figures [DIR_NAME]| 下部のdirectoriesから画像ファイルを集め,pngに変換してhiki/cache/attachへ入れる. |:fig_extension: ".eps"|
|
41
|
+
|--scale [VAL]% |figuresをhikiに変換するときのscale|デフォルトは80%|
|
42
|
+
|--level [VAL] |head(!や!!)をどのlevelから始めるか.| :level: 0|
|
43
|
+
|--hiki| text, figuresをサイトに構築する | :local_site: "/hoge/hoge"|
|
44
|
+
|
45
|
+
|
46
|
+
- initで配置されるRakefileに一括変換のサンプルがある
|
47
|
+
- 変換errorや,Latex標準でないcommandはrake preで予め変換.
|
48
|
+
- それぞれの変換の内容はRakefileを参照せよ.
|
49
|
+
|
50
|
+
以下のように切り分けているが,もっと徹底すべき.
|
51
|
+
|
52
|
+
|binのコマンド|source|内容|
|
53
|
+
|:----|:----|:----|
|
54
|
+
|latex2hiki|lib/maple/latex2hiki.rb|latexからの基本変換|
|
55
|
+
|mk_maple_hiki|lib/mk_maple_hiki.rb|directoryからhikiへの自動変換|
|
56
|
+
|rake maple|Rakefile|固有変換を自動化するサンプル|
|
57
|
+
|
58
|
+
|
59
|
+
## 具体的な使用例
|
60
|
+
### 一括して作る場合
|
61
|
+
```tcsh
|
62
|
+
bob% cd MapleText/
|
63
|
+
bob% mk_maple_hiki --init
|
64
|
+
bob% mk_maple_hiki --figures NumMaple
|
65
|
+
```
|
66
|
+
```tcsh
|
67
|
+
[bob:~/Ruby/latex2hiki/MapleText] bob% mk_maple_hiki --hiki NumMaple/
|
68
|
+
[["begin", "document"], ["title", "Mapleで理解する数値計算の基礎"], ["author", "西谷@関西学院大・理工"], ["date", "\\today"], ["chapter", "代数方程式(fsolve)"], ["section", "概要"], ["input", "FSolve/abs.tex"], ["section", "Mapleでの解"], ["input", "FSolve/s
|
69
|
+
...
|
70
|
+
["!!", "高速フーリエ変換アルゴリズムによる高速化"]
|
71
|
+
"FFT/TukeyAlgorithm.tex"
|
72
|
+
["!!", "FFT関数を用いた結果"]
|
73
|
+
"FFT/FFTFunction.tex"
|
74
|
+
chmod 666 /Users/bob/Sites/new_ist_data/maple_hiki_data/text/NumMaple
|
75
|
+
```
|
76
|
+
|
77
|
+
### sectionを分割して作る場合
|
78
|
+
```tch
|
79
|
+
bob% ls
|
80
|
+
Error/ LAEigenvectors/ NonLinearFit/ NumMapleCont.tex figures/
|
81
|
+
FFT/ LAFundamentals/ NumMaple.out NumMaple_140130.pdf
|
82
|
+
FSolve/ LAMatrixInverse/ NumMaple.tex NumMaple_160802.pdf
|
83
|
+
InterpolationIntegral/ LeastSquareFit/ NumMaple.toc Rakefile
|
84
|
+
bob% rake maple
|
85
|
+
"./Error"
|
86
|
+
[["begin", "document"], ["chapter", "誤差(Error)"], ["section", "打ち切り誤差と丸め誤差(Truncation and round off errors)"], ["input", "TruncationRoundoff.tex"], ["s
|
87
|
+
```
|
88
|
+
|
89
|
+
## Development
|
90
|
+
|
91
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec latex2hiki` to use the gem in this directory, ignoring other installed copies of this gem.
|
92
|
+
|
93
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
94
|
+
|
95
|
+
## Contributing
|
96
|
+
|
97
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/latex2hiki. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
98
|
+
|
99
|
+
|
100
|
+
## License
|
101
|
+
|
102
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/latex2hiki.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'optparse'
|
3
|
+
require "latex2hiki/version"
|
4
|
+
require "latex2hiki/latex2hiki"
|
5
|
+
#require "latex2hiki/latex2hiki_new"
|
6
|
+
|
7
|
+
module Latex2hiki
|
8
|
+
# Your code goes here...
|
9
|
+
class Command
|
10
|
+
def self.run(argv=[])
|
11
|
+
new(argv).execute
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(argv=[])
|
15
|
+
@argv = argv
|
16
|
+
@pre=@head=@post=nil
|
17
|
+
@listings=false
|
18
|
+
end
|
19
|
+
|
20
|
+
def execute
|
21
|
+
@argv << '--help' if @argv.size==0
|
22
|
+
command_parser = OptionParser.new do |opt|
|
23
|
+
opt.on('-v', '--version','show program Version.') { |v|
|
24
|
+
opt.version = Latex2hiki::VERSION
|
25
|
+
puts opt.ver
|
26
|
+
exit
|
27
|
+
}
|
28
|
+
end
|
29
|
+
command_parser.parse!(@argv)
|
30
|
+
puts NKF.nkf("-w",Latex.new(File.read(ARGV[0])).to_hiki)
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,221 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
require "stringio"
|
4
|
+
require 'kconv'
|
5
|
+
require "strscan"
|
6
|
+
require "uri"
|
7
|
+
|
8
|
+
class Latex < String
|
9
|
+
|
10
|
+
def initialize(output)
|
11
|
+
@text = NKF.nkf("-w",output)
|
12
|
+
@text.gsub!(/\r\n?/,'\n')
|
13
|
+
@text.gsub!(/\\%/,'%')
|
14
|
+
@text.gsub!("。",".")
|
15
|
+
@text.gsub!("、",",")
|
16
|
+
end
|
17
|
+
|
18
|
+
def strip_hiki
|
19
|
+
ifHIKI = true
|
20
|
+
output = ''
|
21
|
+
@text.each_line {|line1|
|
22
|
+
case line1
|
23
|
+
when /\\ifHIKI/
|
24
|
+
ifHIKI = true
|
25
|
+
when /\\else/
|
26
|
+
ifHIKI = false
|
27
|
+
when /\\fi/
|
28
|
+
ifHIKI = true
|
29
|
+
else
|
30
|
+
if ifHIKI==true then
|
31
|
+
output << line1
|
32
|
+
end
|
33
|
+
end
|
34
|
+
}
|
35
|
+
@text = output
|
36
|
+
end
|
37
|
+
|
38
|
+
def strip_document
|
39
|
+
is_document = false
|
40
|
+
is_include_document = false
|
41
|
+
output = ''
|
42
|
+
@text.each_line{|line|
|
43
|
+
case line
|
44
|
+
when /\\begin\{document\}/
|
45
|
+
is_document = true
|
46
|
+
is_include_document = true
|
47
|
+
when /\\end\{document\}/
|
48
|
+
is_document = false
|
49
|
+
else
|
50
|
+
if is_document==true then
|
51
|
+
output << line
|
52
|
+
end
|
53
|
+
end
|
54
|
+
}
|
55
|
+
if is_include_document==true then
|
56
|
+
@text = output
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def to_hiki
|
61
|
+
roman_num=["","i)","ii)","iii)","iv)","v)","vi)","vii)","viii)","ix)","x)"]
|
62
|
+
alpha_num=["","a)","b)","c)","d)","e)","f)","g)","h)","i)","j)"]
|
63
|
+
strip_document()
|
64
|
+
strip_hiki()
|
65
|
+
output=''
|
66
|
+
item_number=Array.new(3,1)
|
67
|
+
is_enumerate=0
|
68
|
+
is_quote_eq, is_quote, is_itemize, is_table = false, false, false, false
|
69
|
+
@text.each_line {|nline|
|
70
|
+
line=nline.gsub(/\\verb\|(.+?)\|/){|matched|
|
71
|
+
$&[6..-2]
|
72
|
+
}
|
73
|
+
|
74
|
+
line.gsub!(/\\fbox\{(.+?)\}/,"[ XXX ]")
|
75
|
+
line.gsub!(/\\displaystyle/,'')
|
76
|
+
|
77
|
+
case line
|
78
|
+
when /\\label\{(.*)\}/
|
79
|
+
|
80
|
+
when /\\section\{(.*)\}/
|
81
|
+
output << "\n!#{$1} \n"
|
82
|
+
when /\\section\*\{(.*)\}/
|
83
|
+
output << "\n!#{$1} \n"
|
84
|
+
when /\\subsection\{(.*)\}/
|
85
|
+
output << "\n!!#{$1} \n"
|
86
|
+
when /\\subsubsection\{(.*)\}/
|
87
|
+
output << "\n!!!#{$1} \n"
|
88
|
+
when /\\paragraph\{(.*)\}/
|
89
|
+
output << "\n!!!!#{$1} \n"
|
90
|
+
when /\\item\[(.*)\](.*)/
|
91
|
+
output << ":"+$1+":"+$2.chomp+"\n"
|
92
|
+
when /\\item(.*)/
|
93
|
+
if is_enumerate==1 then
|
94
|
+
output << "# "+$1.chomp+"\n"
|
95
|
+
elsif is_enumerate==2 then
|
96
|
+
output << "# "+$1.chomp+"\n"
|
97
|
+
elsif is_enumerate==3 then
|
98
|
+
output << "# "+$1.chomp+"\n"
|
99
|
+
elsif is_itemize then
|
100
|
+
output << "* "+$1+"\n"
|
101
|
+
end
|
102
|
+
|
103
|
+
when /\\begin\{MapleInput\}/
|
104
|
+
output << "<<<maple\n"
|
105
|
+
when /\\end\{MapleInput\}/
|
106
|
+
output << ">>>\n"
|
107
|
+
when /\\begin\{MapleError\}/
|
108
|
+
output << "<<<maple\n"
|
109
|
+
when /\\end\{MapleError\}/
|
110
|
+
output << ">>>\n"
|
111
|
+
|
112
|
+
|
113
|
+
when /\\begin\{quote\}/
|
114
|
+
is_quote = true
|
115
|
+
when /\\end\{quote\}/
|
116
|
+
is_quote = false
|
117
|
+
|
118
|
+
when /\\begin\{description\}/
|
119
|
+
when /\\end\{description\}/
|
120
|
+
when /\\begin\{verbatim\}/
|
121
|
+
output << "<<<\n"
|
122
|
+
when /\\end\{verbatim\}/
|
123
|
+
output << ">>>\n"
|
124
|
+
when /\\begin\{enumerate\}/
|
125
|
+
is_enumerate += 1
|
126
|
+
when /\\begin\{itemize\}/
|
127
|
+
is_itemize = true
|
128
|
+
when /\\end\{enumerate\}/
|
129
|
+
item_number[is_enumerate]=1
|
130
|
+
is_enumerate -= 1
|
131
|
+
when /\\end\{itemize\}/
|
132
|
+
is_itemize = false
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
when /\\begin\{MapleOutput\}/,/\\begin\{MapleOutputGather\}/,/\\begin\{gather\}/ then
|
137
|
+
output << "\$\$\n"
|
138
|
+
is_quote_eq = true
|
139
|
+
when /\\end\{MapleOutput\}/,/\\end\{MapleOutputGather\}/,/\\end\{gather\}/ then
|
140
|
+
output << "\$\$\n"
|
141
|
+
is_quote_eq = false
|
142
|
+
when /\\notag/ then
|
143
|
+
output << $`+"\n"
|
144
|
+
|
145
|
+
when /\\MaplePlot\{(.*)\}\{(.*)\}/
|
146
|
+
target=File::basename($2,".eps")+".png"
|
147
|
+
output << "||{{attach_view(#{target},#{$target_dir})}}||\n"
|
148
|
+
|
149
|
+
when /\\begin\{tabular\}/
|
150
|
+
is_table = true
|
151
|
+
when /\\end\{tabular\}/
|
152
|
+
is_table = false
|
153
|
+
when /\\begin\{table\}/
|
154
|
+
when /\\end\{table\}/
|
155
|
+
when /\\begin\{center\}/
|
156
|
+
when /\\end\{center\}/
|
157
|
+
when /\\caption\{(.*)\}/
|
158
|
+
# output << "'''"+$1+"'''\n"
|
159
|
+
output << "!!!caption:"+$1+"\n"
|
160
|
+
|
161
|
+
when /\\begin\{equation\*\}/
|
162
|
+
is_quote_eq = true
|
163
|
+
if is_quote then
|
164
|
+
output << "\"\"\$\$\n"
|
165
|
+
else
|
166
|
+
output << "\$\$\n"
|
167
|
+
end
|
168
|
+
when /\\end\{equation\*\}/
|
169
|
+
is_quote_eq = false
|
170
|
+
output << "\$\$\n"
|
171
|
+
when /\\begin\{equation\}/
|
172
|
+
is_quote_eq = true
|
173
|
+
if is_quote then
|
174
|
+
output << "\"\"\$\$\n"
|
175
|
+
else
|
176
|
+
output << "\$\$\n"
|
177
|
+
end
|
178
|
+
when /\\end\{equation\}/
|
179
|
+
is_quote_eq = false
|
180
|
+
output << "\$\$\n"
|
181
|
+
when /\\pagebreak/
|
182
|
+
when /\\begin\{(.+)\}/
|
183
|
+
if is_quote_eq then
|
184
|
+
output << line.lstrip
|
185
|
+
end
|
186
|
+
when /\\end\{(.+)\}/
|
187
|
+
if is_quote_eq then
|
188
|
+
output << line.lstrip
|
189
|
+
end
|
190
|
+
else
|
191
|
+
if is_table then
|
192
|
+
next if ((line==nil) or (line=~/^\\hline/))
|
193
|
+
line.gsub!(/\&/,"||")
|
194
|
+
line.gsub!(/\\\\/,"")
|
195
|
+
line.gsub!(/\\hline/,"")
|
196
|
+
output << "||"+line
|
197
|
+
|
198
|
+
elsif is_quote then
|
199
|
+
if is_quote_eq then
|
200
|
+
output << line.lstrip
|
201
|
+
else
|
202
|
+
output << "\"\""+line
|
203
|
+
end
|
204
|
+
else
|
205
|
+
if is_quote_eq then
|
206
|
+
output << line.lstrip
|
207
|
+
else
|
208
|
+
output << line
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
}
|
213
|
+
return output
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
if __FILE__ == $0
|
218
|
+
$target_dir=File::dirname(ARGV[0])
|
219
|
+
# puts NKF.nkf("-e",Latex.new(File.read(ARGV[0])).to_hiki)
|
220
|
+
puts NKF.nkf("-w",Latex.new(File.read(ARGV[0])).to_hiki)
|
221
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'kconv'
|
3
|
+
|
4
|
+
class Latex < String
|
5
|
+
|
6
|
+
def initialize(input)
|
7
|
+
@input = input
|
8
|
+
@f = ""
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_hiki
|
12
|
+
section = []
|
13
|
+
@input.split("\n").each do |line|
|
14
|
+
case line
|
15
|
+
when /^\\(\w+)/
|
16
|
+
section.push $1
|
17
|
+
next
|
18
|
+
when /^End(\w+)/
|
19
|
+
section.pop
|
20
|
+
next
|
21
|
+
end
|
22
|
+
p section[-1]
|
23
|
+
|
24
|
+
case section[-1]
|
25
|
+
when ["author"]
|
26
|
+
@f << line
|
27
|
+
cont = line.match(/\\(\w+)\{(\w+)\}/)
|
28
|
+
p cont
|
29
|
+
@f << cont
|
30
|
+
@f << cont[2]
|
31
|
+
exit
|
32
|
+
else
|
33
|
+
# @f << section[-1]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
return @f
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,208 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
require "stringio"
|
4
|
+
require 'kconv'
|
5
|
+
require "strscan"
|
6
|
+
require "uri"
|
7
|
+
|
8
|
+
class Latex < String
|
9
|
+
|
10
|
+
def initialize(output)
|
11
|
+
@text = NKF.nkf("-w",output)
|
12
|
+
@text.gsub!(/\r\n?/,'\n')
|
13
|
+
@text.gsub!(/\\%/,'%')
|
14
|
+
@text.gsub!("。",".")
|
15
|
+
@text.gsub!("、",",")
|
16
|
+
end
|
17
|
+
|
18
|
+
def strip_hiki
|
19
|
+
ifHIKI = true
|
20
|
+
output = ''
|
21
|
+
@text.each_line {|line1|
|
22
|
+
case line1
|
23
|
+
when /\\ifHIKI/
|
24
|
+
ifHIKI = true
|
25
|
+
when /\\else/
|
26
|
+
ifHIKI = false
|
27
|
+
when /\\fi/
|
28
|
+
ifHIKI = true
|
29
|
+
else
|
30
|
+
if ifHIKI==true then
|
31
|
+
output << line1
|
32
|
+
end
|
33
|
+
end
|
34
|
+
}
|
35
|
+
@text = output
|
36
|
+
end
|
37
|
+
|
38
|
+
def strip_document
|
39
|
+
is_document = false
|
40
|
+
is_include_document = false
|
41
|
+
output = ''
|
42
|
+
@text.each_line{|line|
|
43
|
+
case line
|
44
|
+
when /\\begin\{document\}/
|
45
|
+
is_document = true
|
46
|
+
is_include_document = true
|
47
|
+
when /\\end\{document\}/
|
48
|
+
is_document = false
|
49
|
+
else
|
50
|
+
if is_document==true then
|
51
|
+
output << line
|
52
|
+
end
|
53
|
+
end
|
54
|
+
}
|
55
|
+
if is_include_document==true then
|
56
|
+
@text = output
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def to_hiki
|
61
|
+
roman_num=["","i)","ii)","iii)","iv)","v)","vi)","vii)","viii)","ix)","x)"]
|
62
|
+
alpha_num=["","a)","b)","c)","d)","e)","f)","g)","h)","i)","j)"]
|
63
|
+
strip_document()
|
64
|
+
strip_hiki()
|
65
|
+
output=''
|
66
|
+
item_number=Array.new(3,1)
|
67
|
+
is_enumerate=0
|
68
|
+
is_quote_eq, is_quote, is_itemize, is_table = false, false, false, false
|
69
|
+
@text.each_line {|nline|
|
70
|
+
line=nline.gsub(/\\verb\|(.+?)\|/){|matched|
|
71
|
+
$&[6..-2]
|
72
|
+
}
|
73
|
+
|
74
|
+
line.gsub!(/\\fbox\{(.+?)\}/,"[ XXX ]")
|
75
|
+
line.gsub!(/\\displaystyle/,'')
|
76
|
+
|
77
|
+
case line
|
78
|
+
when /\\label\{(.*)\}/
|
79
|
+
|
80
|
+
when /\\section\{(.*)\}/
|
81
|
+
output << "\n!#{$1} \n"
|
82
|
+
when /\\section\*\{(.*)\}/
|
83
|
+
output << "\n!#{$1} \n"
|
84
|
+
when /\\subsection\{(.*)\}/
|
85
|
+
output << "\n!!#{$1} \n"
|
86
|
+
when /\\subsubsection\{(.*)\}/
|
87
|
+
output << "\n!!!#{$1} \n"
|
88
|
+
when /\\paragraph\{(.*)\}/
|
89
|
+
output << "\n!!!!#{$1} \n"
|
90
|
+
when /\\item\[(.*)\](.*)/
|
91
|
+
output << ":"+$1+":"+$2.chomp+"\n"
|
92
|
+
when /\\item(.*)/
|
93
|
+
if is_enumerate==1 then
|
94
|
+
output << "# "+$1.chomp+"\n"
|
95
|
+
elsif is_enumerate==2 then
|
96
|
+
output << "# "+$1.chomp+"\n"
|
97
|
+
elsif is_enumerate==3 then
|
98
|
+
output << "# "+$1.chomp+"\n"
|
99
|
+
elsif is_itemize then
|
100
|
+
output << "* "+$1+"\n"
|
101
|
+
end
|
102
|
+
when /\\begin\{quote\}/
|
103
|
+
is_quote = true
|
104
|
+
when /\\end\{quote\}/
|
105
|
+
is_quote = false
|
106
|
+
|
107
|
+
when /\\begin\{description\}/
|
108
|
+
when /\\end\{description\}/
|
109
|
+
when /\\begin\{verbatim\}/
|
110
|
+
output << "<<<\n"
|
111
|
+
when /\\end\{verbatim\}/
|
112
|
+
output << ">>>\n"
|
113
|
+
when /\\begin\{enumerate\}/
|
114
|
+
is_enumerate += 1
|
115
|
+
when /\\begin\{itemize\}/
|
116
|
+
is_itemize = true
|
117
|
+
when /\\end\{enumerate\}/
|
118
|
+
item_number[is_enumerate]=1
|
119
|
+
is_enumerate -= 1
|
120
|
+
when /\\end\{itemize\}/
|
121
|
+
is_itemize = false
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
when /\\begin\{tabular\}/
|
126
|
+
is_table = true
|
127
|
+
when /\\end\{tabular\}/
|
128
|
+
is_table = false
|
129
|
+
when /\\begin\{table\}/
|
130
|
+
when /\\end\{table\}/
|
131
|
+
when /\\begin\{center\}/
|
132
|
+
when /\\end\{center\}/
|
133
|
+
when /\\caption\{(.*)\}/
|
134
|
+
output << "!!!caption:"+$1+"\n"
|
135
|
+
|
136
|
+
when /\\begin\{gather\}/ then
|
137
|
+
output << "\$\$\n"
|
138
|
+
is_quote_eq = true
|
139
|
+
when /\\end\{gather\}/ then
|
140
|
+
output << "\$\$\n"
|
141
|
+
is_quote_eq = false
|
142
|
+
when /\\notag/ then
|
143
|
+
output << $`+"\n"
|
144
|
+
|
145
|
+
when /\\MaplePlot\{(.*)\}\{(.*)\}/
|
146
|
+
target=File::basename($2,".eps")+".png"
|
147
|
+
output << "||{{attach_view(#{target},#{$target_dir})}}||\n"
|
148
|
+
|
149
|
+
when /\\begin\{equation\*\}/
|
150
|
+
is_quote_eq = true
|
151
|
+
if is_quote then
|
152
|
+
output << "\"\"\$\$\n"
|
153
|
+
else
|
154
|
+
output << "\$\$\n"
|
155
|
+
end
|
156
|
+
when /\\end\{equation\*\}/
|
157
|
+
is_quote_eq = false
|
158
|
+
output << "\$\$\n"
|
159
|
+
when /\\begin\{equation\}/
|
160
|
+
is_quote_eq = true
|
161
|
+
if is_quote then
|
162
|
+
output << "\"\"\$\$\n"
|
163
|
+
else
|
164
|
+
output << "\$\$\n"
|
165
|
+
end
|
166
|
+
when /\\end\{equation\}/
|
167
|
+
is_quote_eq = false
|
168
|
+
output << "\$\$\n"
|
169
|
+
when /\\pagebreak/
|
170
|
+
when /\\begin\{(.+)\}/
|
171
|
+
if is_quote_eq then
|
172
|
+
output << line.lstrip
|
173
|
+
end
|
174
|
+
when /\\end\{(.+)\}/
|
175
|
+
if is_quote_eq then
|
176
|
+
output << line.lstrip
|
177
|
+
end
|
178
|
+
else
|
179
|
+
if is_table then
|
180
|
+
next if ((line==nil) or (line=~/^\\hline/))
|
181
|
+
line.gsub!(/\&/,"||")
|
182
|
+
line.gsub!(/\\\\/,"")
|
183
|
+
line.gsub!(/\\hline/,"")
|
184
|
+
output << "||"+line
|
185
|
+
|
186
|
+
elsif is_quote then
|
187
|
+
if is_quote_eq then
|
188
|
+
output << line.lstrip
|
189
|
+
else
|
190
|
+
output << "\"\""+line
|
191
|
+
end
|
192
|
+
else
|
193
|
+
if is_quote_eq then
|
194
|
+
output << line.lstrip
|
195
|
+
else
|
196
|
+
output << line
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
}
|
201
|
+
return output
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
if __FILE__ == $0
|
206
|
+
$target_dir=File::dirname(ARGV[0])
|
207
|
+
puts NKF.nkf("-w",Latex.new(File.read(ARGV[0])).to_hiki)
|
208
|
+
end
|