hiki2latex 0.9.12 → 0.9.12.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.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -3
  3. data/{README.en.md → README.md} +6 -4
  4. data/Rakefile +56 -28
  5. data/exe/#hiki2latex# +5 -0
  6. data/hiki2latex.gemspec +3 -0
  7. data/hiki2latex.wiki/AbstSample.pdf +0 -0
  8. data/hiki2latex.wiki/Math.png +0 -0
  9. data/hiki2latex.wiki/Report_head.png +0 -0
  10. data/hiki2latex.wiki/handout_sample.md +73 -0
  11. data/{docs/README.ja.md → hiki2latex.wiki/hiki2latex.md} +14 -16
  12. data/hiki2latex.wiki/hiki2latex_gemizing.md +221 -0
  13. data/hiki2latex.wiki/hiki2latex_init.md +97 -0
  14. data/hiki2latex.wiki/hiki2latex_listings.md +113 -0
  15. data/hiki2latex.wiki/hiki2latex_manual.md +31 -0
  16. data/hiki2latex.wiki/hiki2latex_math.md +147 -0
  17. data/hiki2latex.wiki/hiki2latex_table.md +103 -0
  18. data/hiki2latex.wiki/lpso_abst.pdf +0 -0
  19. data/hiki2latex.wiki/readme_en.md +60 -0
  20. data/{README.ja.md → hiki2latex.wiki/readme_ja.md} +46 -26
  21. data/hiki2latex.wiki/table.png +0 -0
  22. data/hikis/AbstSample.pdf +0 -0
  23. data/hikis/Math.png +0 -0
  24. data/hikis/Report_head.png +0 -0
  25. data/{docs/readme.ja.hiki → hikis/hiki2latex.hiki} +4 -6
  26. data/hikis/hiki2latex_gemizing.hiki +222 -0
  27. data/hikis/hiki2latex_init.hiki +95 -0
  28. data/hikis/hiki2latex_listings.hiki +113 -0
  29. data/hikis/hiki2latex_manual.hiki +32 -0
  30. data/hikis/hiki2latex_math.hiki +145 -0
  31. data/hikis/hiki2latex_table.hiki +102 -0
  32. data/hikis/lpso_abst.pdf +0 -0
  33. data/{docs/readme.hiki → hikis/readme_en.hiki} +2 -0
  34. data/hikis/readme_ja.hiki +133 -0
  35. data/hikis/table.png +0 -0
  36. data/latexes/AbstSample.pdf +0 -0
  37. data/latexes/Math.png +0 -0
  38. data/latexes/Report_head.png +0 -0
  39. data/latexes/head.tex +4 -0
  40. data/latexes/hiki2latex.aux +60 -0
  41. data/latexes/hiki2latex.log +307 -0
  42. data/latexes/hiki2latex.pdf +0 -0
  43. data/latexes/hiki2latex.synctex.gz +0 -0
  44. data/latexes/hiki2latex.tex +213 -0
  45. data/latexes/hiki2latex.toc +47 -0
  46. data/latexes/hiki2latex_gemizing.tex +212 -0
  47. data/latexes/hiki2latex_init.tex +103 -0
  48. data/latexes/hiki2latex_listings.tex +106 -0
  49. data/latexes/hiki2latex_manual.tex +38 -0
  50. data/latexes/hiki2latex_math.tex +151 -0
  51. data/latexes/hiki2latex_table.tex +108 -0
  52. data/latexes/lpso_abst.pdf +0 -0
  53. data/latexes/post.tex +17 -0
  54. data/latexes/table.png +0 -0
  55. data/lib/#hiki2latex.rb# +145 -0
  56. data/lib/hiki2latex/hiki2latex.rb +2 -1
  57. data/lib/hiki2latex/version.rb +1 -1
  58. data/lib/hiki2latex.rb +2 -2
  59. metadata +84 -13
  60. data/#Rakefile# +0 -42
  61. data/#hiki2latex.gemspec# +0 -42
  62. data/{docs/README.en.md → hiki2latex.wiki/readme.md} +4 -4
@@ -0,0 +1,222 @@
1
+ {{toc}}
2
+
3
+ !【概要】
4
+ hikiフォーマットの記述をlatexフォーマットに変換する
5
+ !【使用法】
6
+ gem化して配布可能とした.したがって,installがちゃんとできていれば,
7
+ :command lineから:
8
+ <<< tcsh
9
+ bob% hiki2latex Shunkuntype_manual > tmp.tex
10
+ >>>
11
+ :libraryとして:
12
+ <<< ruby
13
+ require 'hiki2latex'
14
+
15
+ puts HikiDoc.to_latex(File.read(ARGV[0]))
16
+ >>>
17
+ <<< tcsh
18
+ bob% ruby trans.rb ./Shunkuntype_manual > tmp.tex
19
+ >>>
20
+ などとして利用できる.
21
+
22
+ !【help】
23
+
24
+ <<< tcsh
25
+ bob% hiki2latex
26
+ Usage: hiki2latex [options]
27
+ -v, --version show program Version.
28
+ -l, --level VALUE set Level for output section.
29
+ -p, --plain FILE make Plain document.
30
+ -b, --bare FILE make Bare document.
31
+ --head FILE put headers of maketitle file.
32
+ --pre FILE put preamble file.
33
+ --post FILE put post file.
34
+ >>>
35
+
36
+ !【詳細使用例(-p)】
37
+ 以下のようなSampleDoc
38
+ <<< hiki
39
+ bob% cat SampleDoc
40
+ !title
41
+ contents
42
+ *list1
43
+ *list2
44
+ !!title2
45
+ >>>
46
+
47
+ <<< tex
48
+ bob% hiki2latex -p SampleDoc
49
+ \documentclass[12pt,a4paper]{jsarticle}
50
+ \usepackage[dvipdfmx]{graphicx}
51
+ \begin{document}
52
+ \section{title}
53
+ contents
54
+ \begin{itemize}
55
+ \item list1
56
+ \item list2
57
+ \end{itemize}
58
+ \subsection{title2}
59
+ \end{document}
60
+ >>>
61
+ となる.
62
+
63
+ !【詳細使用例(-b)】
64
+ 上記
65
+ <<< tex
66
+ \begin{document}
67
+ ...
68
+ \end{document}
69
+ >>>
70
+ の中身だけを生成.いくつものtex filesをincludeしている場合の個別ファイル作成に便利.
71
+
72
+ この際,'-l 2'として付録のsectionとかを調整する.
73
+
74
+ !【詳細使用例( --head, --pre, --post】
75
+ formatを標準と違うものにするために,pre,head,postがある.詳しくはsampleを見よ.
76
+ していしていく順番はないはずだけど,-p SampleDocだけは順番があるのかな.
77
+ あと,erbみたいにして使ったほうがいいかも.
78
+ <<< tcsh
79
+ bob% hiki2latex --pre preamble.tex --head head.tex --post post.tex -p SampleDoc
80
+ >>>
81
+ <<< tex
82
+ %preamble.tex
83
+ \documentclass[12pt,a4paper]{jsarticle}
84
+ \usepackage[dvipdfmx]{graphicx}
85
+ \pagestyle{empty}
86
+ >>>
87
+ <<< tex
88
+ \begin{document}
89
+ >>>
90
+ <<< tex
91
+ %head.tex
92
+ \author{関西学院大学・理工学部・西谷滋人}
93
+ \title{touch typing習得環境shunkuntype}
94
+ \date{\today}
95
+ \maketitle
96
+ >>>
97
+ <<< tex
98
+ \section{title}
99
+ contents
100
+ \begin{itemize}
101
+ \item list1
102
+ \item list2
103
+ \end{itemize}
104
+ \subsection{title2}
105
+ >>>
106
+ <<< tex
107
+ %post.tex
108
+ \pagebreak
109
+ \appendix
110
+ \section{マニュアル}
111
+ \input{shunkuntype_manual}
112
+ \pagebreak
113
+ \section{gem化メモ}
114
+ \input{shunkuntype_gemizing}
115
+ \pagebreak
116
+ \section{初期版のコード解説}
117
+ \input{shunkuntype_coding}
118
+ >>>
119
+ <<< tex
120
+ \end{document}
121
+ >>>
122
+ !【lib/hiki2latex.rb】
123
+ <<< ruby
124
+ require 'optparse'
125
+ require "hiki2latex/version"
126
+ #require "hiki2latex/hikidoc"
127
+ require "hiki2latex/hiki2latex"
128
+
129
+ module Hiki2latex
130
+ class Command
131
+
132
+ def self.run(argv=[])
133
+ new(argv).execute
134
+ end
135
+
136
+ def initialize(argv=[])
137
+ @argv = argv
138
+ @pre=@head=@post=nil
139
+ end
140
+
141
+ def execute
142
+ @argv << '--help' if @argv.size==0
143
+ command_parser = OptionParser.new do |opt|
144
+ opt.on('-v', '--version','show program Version.') { |v|
145
+ opt.version = Hiki2latex::VERSION
146
+ puts opt.ver
147
+ }
148
+ opt.on('-l VALUE','--level','set Level for output section.'){|level| @level=level.to_i}
149
+ opt.on('-p FILE', '--plain','make Plain document.') { |file| plain_doc(file) }
150
+ opt.on('-b FILE', '--bare','make Bare document.') { |file| bare_doc(file) }
151
+ opt.on('--head FILE', 'put headers of maketitle file.') { |file| @head=file }
152
+ opt.on('--pre FILE', 'put preamble file.') { |file| @pre=file }
153
+ opt.on('--post FILE', 'put post file.') { |file| @post=file }
154
+ opt.on('--listings', 'use listings.sty for preformat with style.') {@listings=true }
155
+ end
156
+ command_parser.banner = "Usage: hiki2latex [options] FILE"
157
+ command_parser.parse!(@argv)
158
+ plain_doc(@argv[0]) if @argv[0]!=nil
159
+ exit
160
+ end
161
+
162
+ # pre, post, listingsなどの拡張を処理
163
+ def plain_doc(file)
164
+ if @listings==true then
165
+ puts listings_preamble
166
+ elsif @pre==nil then
167
+ puts "\\documentclass[12pt,a4paper]{jsarticle}"
168
+ puts "\\usepackage[dvipdfmx]{graphicx}"
169
+ else
170
+ puts File.read(@pre)
171
+ end
172
+ puts "\\begin{document}"
173
+ puts File.read(@head) if @head!=nil
174
+ plain_tex = HikiDoc.to_latex(File.read(file),{:listings=>@listings})
175
+ puts mod_abstract(plain_tex)
176
+ puts File.read(@post) if @post!=nil
177
+ puts "\\end{document}"
178
+ end
179
+
180
+ def bare_doc(file)
181
+ bare_doc = HikiDoc.to_latex(File.read(file),{:level=>@level,:listings=>@listings})
182
+ puts kill_head_tableofcontents(bare_doc)
183
+ end
184
+ >>>
185
+
186
+ !!kill_head_line
187
+ kill_head_lineで付録(bare_text)にtocが含まれている場合は削除.
188
+ <<< ruby
189
+ def kill_head_tableofcontents(text)
190
+ text.gsub!(/^\\tableofcontents/,'')
191
+ end
192
+ >>>
193
+
194
+ !!mod_abstract
195
+ mod_abstractで\verb|\section{abstract}|で書かれた内容をabstract環境へ移行する.一行づつの処理は有限状態マシン的に処理するのがいいらしい(Ruby Best Practice, p.112).一旦contentとabstractを分けて,その後,tableofcontentの前にabstractを挿入している.delete_at(0)は一行目に\verb|\section{【abstract】}|が存在するため.
196
+ <<< ruby
197
+ # convert section to abstract
198
+ def mod_abstract(text)
199
+ abstract,section = [],[]
200
+ content = ""
201
+ text.split("\n").each do |line|
202
+ case line
203
+ when /^\\section(.+)/
204
+ section.push $1
205
+ end
206
+
207
+ case section[-1]
208
+ when /.+abstract.+/
209
+ abstract << line+"\n"
210
+ when /.+概要.+/
211
+ abstract << line+"\n"
212
+ else
213
+ content << line+"\n"
214
+ end
215
+ end
216
+ abstract.delete_at(0)
217
+ content.gsub!(/\\tableofcontents/){|text|
218
+ tt="\n\\abstract\{\n#{abstract.join}\}\n\\tableofcontents"
219
+ }
220
+ return content
221
+ end
222
+ >>>
@@ -0,0 +1,95 @@
1
+ {{toc}}
2
+ !【変更作業の手順】
3
+ * hikiをhtmlに変換するhikidoc.rbに加えていく形で変更
4
+ * hikidocについて調べよ(澄田の宿題)
5
+
6
+ <<< ruby
7
+ bob% diff hikidoc.rb master-hikidoc/lib/hikidoc.rb
8
+ 39d38
9
+ < require './hiki2latex.rb'
10
+ 58,61d56
11
+ < def HikiDoc.to_latex(src, options = {})
12
+ < new(LatexOutput.new(""), options).compile(src)
13
+ < end
14
+ <
15
+ 916,917c911
16
+ < # puts HikiDoc.to_html(ARGF.read(nil))
17
+ < puts HikiDoc.to_latex(ARGF.read(nil))
18
+ ---
19
+ > puts HikiDoc.to_html(ARGF.read(nil))
20
+ >>>
21
+
22
+ * hiki2latex.rbに変更を加えていく.
23
+ !【設計】
24
+ !!【maketitleの挿入】
25
+ latex formatに仕込む際にテキストの順序が前後するコマンドが幾つかある.
26
+ \\maketitleの前に置かれた,
27
+ * title
28
+ * author
29
+ である.これらはheadersとしてtext部と別に返すことも可能である.
30
+ 具体的には,
31
+ || to_html || *fを返す
32
+ || to_latex || *fと*headを返す.
33
+ なおto_htmlとの互換性を維持するため*headを後に返すようにしている.
34
+
35
+ しかし,この部分は,to_htmlとの整合性を考えるとto_latexで処理してしまった方がよい.
36
+ そこで,
37
+
38
+ <<< ruby
39
+ def finish
40
+ @f.string
41
+ end
42
+ >>>
43
+ となっているのを,
44
+
45
+ <<< ruby
46
+ def finish
47
+ if @head != "" then
48
+ @head << "\\maketitle\n"
49
+ return @head+@f
50
+ else
51
+ return @f
52
+ end
53
+ end
54
+ >>>
55
+ とした.
56
+
57
+ !【sample】
58
+ *[[Jihou15]]
59
+
60
+ !【pdfの貼り込み】
61
+ pdfpagesを使おうとすると
62
+
63
+ <<<
64
+ /usr/local/texlive/2015/texmf-dist/tex/latex/pdfpages/pdfpages.sty:70: LaTeX Er
65
+ ror: Missing \begin{document}.
66
+
67
+ See the LaTeX manual or LaTeX Companion for explanation.
68
+ Type H <return> for immediate help.
69
+ ...
70
+
71
+ l.70 \input{pp\AM@driver.def}
72
+ >>>
73
+ というエラーが出る.この解決法がわからず,incudegraphicsで対応.
74
+
75
+ <<<
76
+ ¥documentclass{jsarticle}
77
+ ¥usepackage[dvipdfmx,hiresbb]{graphicx}
78
+ ¥begin{document}
79
+ ¥includegraphics[width=5cm]{sample.pdf}
80
+ ¥end{document}
81
+
82
+ の4行目を
83
+ ¥includegraphics[page=3,width=5cm]{sample.pdf}
84
+ とすれば、
85
+
86
+ 普通に3ページ目の画像を使うことができました。
87
+
88
+ 美文書5版のCD-ROMから普通にインストールした TeXShopの環境です。
89
+
90
+ つまり、何も(といっても、同書 P114 にあるように、
91
+ --shell--escape--commands=extractbb
92
+ をTeXShop環境設定の「内部設定」タブ pdfTex のLatexのオプションとして付け加えています。)特別なことをせずに、ページ指定をするだけで、できてしまいました。
93
+
94
+ 次の、美文書の版には、ページ設定についても解説していただくといいかも知れません。>奥村先生お願いします。
95
+ >>>
@@ -0,0 +1,113 @@
1
+ !【概要】
2
+ latexのlistingsスタイルを使って,source codeの色付き表示が可能に.
3
+
4
+ !【hiki2latexの変更】
5
+ hikidoc2texで使われているのを参照して,
6
+
7
+ <<< ruby
8
+ def block_preformatted(str, info)
9
+ if (@listings==true and info!=nil) then
10
+ style='customRuby' if info=='ruby'
11
+ style='customCsh' if (info=='tcsh' or info=='csh')
12
+ style='customTeX' if info=='tex'
13
+ style='customJava' if info=='java'
14
+ preformatted_with_style(str,style)
15
+ else
16
+ preformatted(text(str))
17
+ end
18
+ end
19
+
20
+ def preformatted(str)
21
+ @f.slice!(-1)
22
+ @f << "\\begin{quote}\\begin{verbatim}\n"
23
+ @f << str+"\n"
24
+ @f << "\\end{verbatim}\\end{quote}\n"
25
+ end
26
+
27
+ def preformatted_with_style(str,style)
28
+ @f.slice!(-1)
29
+ @f << "\\begin{lstlisting}[style=#{style}]\n"
30
+ @f << str+"\n"
31
+ @f << "\\end{lstlisting}\n"
32
+ end
33
+ >>>
34
+
35
+ opt周りは,
36
+
37
+ <<< ruby
38
+ opt.on('--listings', 'use listings.sty for preformat with style.') {@listings=true }
39
+ >>>
40
+ としている.これをHikiDocへ渡す時は,
41
+
42
+ <<< ruby
43
+ def plain_doc(file)
44
+ if @listings==true then
45
+ puts listings_preamble
46
+ elsif @pre==nil then
47
+ puts "\\documentclass[12pt,a4paper]{jsarticle}"
48
+ puts "\\usepackage[dvipdfmx]{graphicx}"
49
+ else
50
+ puts File.read(@pre)
51
+ end
52
+ puts "\\begin{document}"
53
+ puts File.read(@head) if @head!=nil
54
+ puts HikiDoc.to_latex(File.read(file),{:listings=>@listings})
55
+ puts File.read(@post) if @post!=nil
56
+ puts "\\end{document}"
57
+ end
58
+ >>>
59
+ 後ろのoptions={}の中にhashで登録している.texのstyleはlisting_preambleで打ち出すようにしている.
60
+
61
+ listingsの設定は以下の通り.
62
+
63
+ <<< tex
64
+ \documentclass[10pt,a4paper]{jsarticle}
65
+ \usepackage[dvipdfmx]{graphicx}
66
+ \usepackage[dvipdfmx]{color}
67
+ \usepackage{listings}
68
+ % to use japanese correctly, install jlistings.
69
+ \lstset{
70
+ basicstyle={\small\ttfamily},
71
+ identifierstyle={\small},
72
+ commentstyle={\small\itshape\color{red}},
73
+ keywordstyle={\small\bfseries\color{cyan}},
74
+ ndkeywordstyle={\small},
75
+ stringstyle={\small\color{blue}},
76
+ frame={tb},
77
+ breaklines=true,
78
+ numbers=left,
79
+ numberstyle={\scriptsize},
80
+ stepnumber=1,
81
+ numbersep=1zw,
82
+ xrightmargin=0zw,
83
+ xleftmargin=3zw,
84
+ lineskip=-0.5ex
85
+ }
86
+ \lstdefinestyle{customCsh}{
87
+ language={csh},
88
+ numbers=none,
89
+ }
90
+ \lstdefinestyle{customRuby}{
91
+ language={ruby},
92
+ numbers=left,
93
+ }
94
+ \lstdefinestyle{customTex}{
95
+ language={tex},
96
+ numbers=none,
97
+ }
98
+ \lstdefinestyle{customJava}{
99
+ language={java},
100
+ numbers=left,
101
+ }
102
+ >>>
103
+
104
+ <<<
105
+ \begin{lstlisting}[style=customRuby]
106
+ def block_preformatted(str, info)
107
+ if (@listings==true and info!=nil) then
108
+ style='customRuby' if info=='ruby'
109
+ style='customCsh' if (info=='tcsh' or info=='csh')
110
+ style='customTeX' if info=='tex'
111
+ ...
112
+ \end{lstlisting}
113
+ >>>
@@ -0,0 +1,32 @@
1
+ {{toc}}
2
+ !【概要】
3
+ hikiで書いたのを中間発表の予稿集用に変換するマニュアル.
4
+ !【下準備】
5
+ #yahataProjectをinstall
6
+ #rake initを実行.passwordを聞かれたときはdonkeyかnishitaniに知らせる
7
+ #setenvでpathを設定
8
+ !【手順】
9
+ #hikiにGraduate_handout原稿を作成
10
+ # 作業用のdirectoryを作成
11
+ #そこで,hiki2abst.rb ~/Sites/hiki-1.0/data/text/Graduate_handout > Graduate_handout.tex
12
+ # open Graduate_handout.tex
13
+ # command-Tでpdfへ変換.
14
+
15
+ !【graph作成手順】
16
+ !!hiki
17
+ # 適当なサイズに調整したファイルを添付ファイルとしてUpLoad
18
+ * ImageMagickがinstallされているとして,convert A.png -scale 50% B.png
19
+ !!latex directory
20
+ # hikiでファイルを選択してDownLoad
21
+ # 作業用のlatex directoryへ移す.
22
+ # ebb B.pngでB.bbを作成.
23
+ # TeXShopでcompileすればいけるはず.
24
+
25
+ ! 【TeXShopの設定】
26
+ !!ファイルが文字化け
27
+ * 「設定」->書類->エンコーディング Unicode(UTF-8)
28
+ * 同じタグの「設定プロファイル」-> pTeX(ptex2pdf)を選択
29
+ * TeXShopを再起動
30
+ * compileすればいけるはず.
31
+ !!compileうまくいかないとき.
32
+ * *.auxファイルを消去して,再compile.
@@ -0,0 +1,145 @@
1
+ {{toc}}
2
+ !【概要】
3
+ dmath,math環境をequationに変換
4
+ !【入力:hiki】
5
+
6
+ <<<
7
+ mathがうまくいくかどうかの検討用サンプルです.
8
+ {{dmath 'f_x'}}
9
+ さらにinlineで{{math 'x_i'}}なんかもできるといいのですが.
10
+ >>>
11
+
12
+ mathがうまくいくかどうかの検討用サンプルです.
13
+ {{dmath 'f_x'}}
14
+ さらにinlineで{{math 'x_i'}}なんかもできるといいのですが.
15
+
16
+ !【出力:latex】
17
+
18
+ <<<
19
+ \begin{document}
20
+ mathがうまくいくかどうかの検討用サンプルです.
21
+ \begin{equation}
22
+ f_x
23
+ \end{equation}
24
+ さらにinlineで$x_i$なんかもできるといいのですが.
25
+ >>>
26
+ :注2016/02/20:このあたりでhiki, rubyを指定するとlistingsがうまく処理できない.preformatted\_without\_styleで対応.
27
+ {{attach_view(Math.png)}}
28
+ !【コード解説】
29
+ !!evaluate_plugin_block
30
+ すこしトリッキーだったので,メモです.
31
+ <<< ruby
32
+ def evaluate_plugin_block(str, buf = nil)
33
+ buf ||= @output.container
34
+ str.split(/(\0\d+\0)/).each do |s|
35
+ if s[0, 1] == "\0" and s[-1, 1] == "\0"
36
+ buf << @output.inline_plugin(plugin_block(s[1..-2].to_i))
37
+ else
38
+ buf << @output.text(s)
39
+ end
40
+ end
41
+ buf
42
+ end
43
+ >>>
44
+ としてinline_pluginはblock_pluginと違った扱いになっています.bufに一度溜め込んでそれを@fに吐いているようです.
45
+ そこで,@output.inline_pluginで行き着く先が,LatexOutputの
46
+ <<< ruby
47
+ def inline_plugin(src)
48
+ tmp=[]
49
+ if ( /(\w+)\((.+)\)/ =~ src ) or ( /(\w+).\'(.+)\'/ =~src ) or (/(\w+)/ =~ src)
50
+ tmp = [$1,$2]
51
+ end
52
+
53
+ case tmp[0]
54
+ when 'dmath'
55
+ "\\begin{equation}\n#{tmp[1]}\n\\end{equation}"
56
+ when 'math'
57
+ "\$#{tmp[1]}\$"
58
+ else
59
+ %Q(<span class="plugin">{{#{src}}}</span>)
60
+ end
61
+ end
62
+ >>>
63
+ としてmath,dmathを処理しています.必要ならそれ以外のinlineもここに付け足すことで対応できます.
64
+
65
+ !!snake_nameがlatexで引っかかる
66
+ math環境の移し替えはうまくいったが,underscore_namesがすべて引っかかるequationとして引っかかる.
67
+ \usepackage{underscore}
68
+ だけでもできるようだが,できればto_latexで対応したい.ということで,paragraphにescape_snake_namesを入れた.
69
+
70
+ paragraphはpreformattedからは呼ばれない.しかし,\verb|$$|や\verb|\begin{equation}...\end{equation}|が含まれる.そこで
71
+ 一旦全置換してそこだけ戻すようにした.gsubのなかでなんどもできるか自信がなくて.二重のgsubにしているが...
72
+ <<< ruby
73
+ def escape_snake_names(str)
74
+ str.gsub!(/_/,"\\_")
75
+ str.gsub!(/\$.+?\$/){ |text| text.gsub!(/\\_/,"_") }
76
+ str.gsub!(/equation.+?equation/m){ |text| text.gsub!(/\\_/,"_") }
77
+ end
78
+
79
+ def paragraph(lines)
80
+ lines.each{|line| line = escape_snake_names(line) }
81
+ @f << "#{lines.join("\n")}\n\n"
82
+ end
83
+ >>>
84
+ gsub!で置換できなかったときには,nilが返るので対応.なんかえらく冗長.
85
+ <<< ruby
86
+ def escape_snake_names(str)
87
+ str.gsub!(/_/,"\\_")
88
+ str.gsub!(/\$.+?\$/){ |text|
89
+ if text =~ /\\_/ then
90
+ text.gsub!(/\\_/,"_")
91
+ else
92
+ text
93
+ end
94
+ }
95
+ str.gsub!(/equation.+?equation/m){ |text|
96
+ if text =~ /\\_/ then
97
+ text.gsub!(/\\_/,"_")
98
+ else
99
+ text
100
+ end
101
+ }
102
+ str
103
+ end
104
+ >>>
105
+
106
+ !!escape_snake_namesを改良(2016/02/14)
107
+ gemへの公開にあたって冗長部を簡略化.verbだけはここを切り出した検証とは違う.testにuriを埋め込んでverb変換とsnakeを検証.
108
+ <<< ruby
109
+ def escape_snake_names(str)
110
+ str.gsub!(/_/,"\\_")
111
+ patterns = [/\$(.+?)\$/ , /\\verb\|(.+?)\|/, /equation(.+?)equation/m ]
112
+ patterns.each{|pattern|
113
+ str.gsub!(/\\_/,"_") if str.match(pattern)
114
+ }
115
+ str
116
+ end
117
+ >>>
118
+ !!escape_snake_namesを再改良(2016/02/16)
119
+ underscoreではincludeなどでsnake_named_fileも変換してしまい,だめ.hiki2latexで対応.
120
+
121
+ 上のやり方では,うまくいかない場合が存在.元へ戻す.
122
+ <<< ruby
123
+ def escape_snake_names(str)
124
+ str.gsub!(/_/,"\\_")
125
+ patterns = [/\$(.+?)\$/ , /\\verb\|(.+?)\|/, /equation(.+?)equation/m ]
126
+ patterns.each{|pattern|
127
+ # str.gsub!(/\\_/,"_") if str.match(pattern)
128
+ str.gsub!(pattern){|text|
129
+ if text =~ /\\_/ then
130
+ text.gsub!(/\\_/,'_')
131
+ else
132
+ text
133
+ end
134
+ }
135
+ }
136
+ str
137
+ end
138
+ >>>
139
+ さらに
140
+ tableでescape_snake_namesを通ってなかった.
141
+ # buf << "#{ele} &"
142
+ buf << escape_snake_names(ele)+" &"
143
+
144
+ !【copyright】
145
+ cc by Shigeto R. Nishitani, 2015
@@ -0,0 +1,102 @@
1
+ {{toc}}
2
+ !【概要】
3
+ hiki2latexのtable処理部
4
+
5
+ !【仕様】
6
+ * hiki記法の表をtabularへ変換
7
+ * 連結作用素に対応
8
+ * 行連結では中心に表示を移動
9
+ * 縦罫は基本使わない
10
+ * 横罫はheader内枠と上下外枠のみ
11
+
12
+ !【hiki】
13
+
14
+ <<<
15
+ ||>A11||>A12||
16
+ ||^^A21||A22||>A23||
17
+ ||A11||^A22||A12||
18
+ ||A21||A23||
19
+ >>>
20
+
21
+ ||>A11||>A12||
22
+ ||^^A21||A22||>A23||
23
+ ||A11||^A22||A12||
24
+ ||A21||A23||
25
+
26
+
27
+ !【latex】
28
+
29
+ <<< latex
30
+ ¥begin{center}¥begin{table}[htbp]¥begin{tabular}{ccccc}
31
+ ¥hline
32
+ ¥multicolumn{2}{c}{A11 } &¥multicolumn{2}{c}{A12 } & ¥¥ ¥hline
33
+ &A22 &¥multicolumn{2}{c}{A23 } & ¥¥
34
+ A21 &A11 &A22 &A12 & ¥¥
35
+ &A21 & &A23 & ¥¥
36
+ ¥hline
37
+ ¥end{tabular}¥end{table}¥end{center}
38
+ %横罫を入れる場合は, ¥hline, ¥cline{2-3}などで.
39
+ >>>
40
+
41
+ {{attach_view(table.png)}}
42
+
43
+ !【コード解説】
44
+ 元のHTMLOutputではそれぞれの要素で対応していたが,LatexOutputではtable_closeにて
45
+ <<< ruby
46
+ def table_close
47
+ @f << make_table
48
+ end
49
+ >>>
50
+ としている.make_tableは下請けにmake_matrixを読んでおり,ここでほぼ全ての作業をしている.作業内容は
51
+ * matrixを作る
52
+ * 縦連結を処理
53
+ ** 縦連結の数(rs)だけ下行に追加
54
+ ** 連結の中心(c_rs)に内容を表記
55
+ * 横連結をmulticolumnで処理
56
+ ** ついでに最大列数(max_col)を記録
57
+
58
+ <<< ruby
59
+ bob% cat table.rb
60
+ cont = File.readlines("table")
61
+
62
+ cont.each{|line|
63
+ p tmp=line.split('||')
64
+ }
65
+
66
+ t_matrix=[]
67
+ cont.each{|line|
68
+ tmp=line.split('||')
69
+ tmp.slice!(0)
70
+ tmp.slice!(-1) if tmp.slice(-1)=="\n"
71
+ tmp.each_with_index{|ele,i| tmp[i] = ele.match(/\s*(.+)/)[1]}
72
+ t_matrix << tmp
73
+ }
74
+
75
+ t_matrix.each_with_index{|line,i|
76
+ line.each_with_index{|ele,j|
77
+ if ele=~/\^+/ then
78
+ t_matrix[i][j]=""
79
+ rs=$&.size
80
+ c_rs=rs/2
81
+ rs.times{|k| t_matrix[i+k+1].insert(j,"")}
82
+ t_matrix[i+c_rs][j]=$'
83
+ end
84
+ }
85
+ }
86
+ p t_matrix
87
+
88
+ max_col=0
89
+ t_matrix.each_with_index{|line,i|
90
+ n_col=line.size
91
+ line.each_with_index{|ele,j|
92
+ if ele=~/>+/ then
93
+ cs=$&.size
94
+ t_matrix[i][j]= "\\multicolumn{#{cs+1}}{c}{#{$'}} "
95
+ n_col+=cs
96
+ end
97
+ }
98
+ max_col = n_col if n_col>max_col
99
+ }
100
+ p t_matrix
101
+ p max_col
102
+ >>>
Binary file