#!/usr/bin/ruby
require 'kconv'
print "Input target file name (defaul:Hiki2Latex)\n"
#print "Input target file name (defaul:KyoguchiPaper)\n"
if ($target=gets.chomp)=="" then
$target = "Hiki2LatexPaper"
# $target = "KyoguchiPaper"
end
$path0="/Users/bob/Sites/hiki-data/data/text/"
def file_cp(file)
i_count=1
file_name = $path0+file
cont0=File.read(file_name)
cont1=""
cont0.each_line do |line|
line.gsub!(/\{\{math'(.+?)'\}\}/){|matched|
"$#{matched[7..-4]}$"
}
line.scan(/^\|\|\{\{attach_view\((.+)\)\}\}/)
if $1!=nil then
cont1 << "
\\begin{figure}\\begin{center}
\\includegraphics[width=80mm]{./figures/#{$1}}
\\caption{}
\\label{}
\\end{center}\\end{figure}
"
# print $1+"\n"
# print $2+"\n"
else
cont1 << NKF.nkf("-s",line)
end
end
file=open(file,"w")
file.print(cont1)
file.close
end
def select_cont(element,c_sel)
if element=='' then return "" end
element.scan(/\[\[(.+)\]\]/)
term = $1
if term !=nil then
cont=""
element2=term.split("|")
case element2.length
when 0 then
cont << c_sel+"{"+element2[0]+"}\n"
when 1 then
cont << "\\input{"+element2[0]+"}\n"
file_cp(element2[0])
else
cont << c_sel+"{"+element2[0]+"}\n"
cont << "\\input{"+element2[1]+"}\n"
file_cp(element2[1])
end
return cont
else
if element.length<16 then
return c_sel+"{"+element+"}\n"
else
return element+"\n"
end
end
end
file=open($path0+$target,"r")
content="\\documentclass[12pt,a4j]{jreport}
\\usepackage[dvipdfm]{graphicx}
\\usepackage{amsmath,amsthm,amssymb}
\\usepackage{verbatim}
\\usepackage{here}
"
dummy=[]
while line=file.gets do
elements=line.chomp.split('||')
if elements[1]==nil then next end
if elements[1].downcase=='title' then
content << "\\title{"+ elements[2].chomp+"}\n"
elsif elements[1].downcase=='author' then
content << "\\author{"+ elements[2].chomp+"}\n"
elsif elements[1].downcase=='abstract' then
abstract = select_cont(elements[2],"")
elsif elements[1].downcase=='thebibliography' then
thebibliography = select_cont(elements[2],"")
else
dummy << elements
end
end
file.close
content <<"
\\begin{document}
\\maketitle
\\begin{abstract}
"
content << abstract
content << "
\\end{abstract}
\\tableofcontents
\\pagebreak
"
is_chapter=0
is_section=0
c_sel=[" ","\\chapter","\\section","\\subsection"]
#c_sel=[" ","\\chapter","",""]
dummy.each do |elements|
if is_chapter>0 then
elements[0,0]=""
end
if is_section>0 then
elements[0,0]=""
end
elements.each_with_index do |elem,i|
if elem=~/^\^+/ then
i_n=elem.scan(/^\^+/)[0].length
if i==1 then
is_chapter=i_n+1
else
is_section=i_n+1
end
content << c_sel[i]+"{"+elem[i_n..-1]+"}\n"
else
content << select_cont(elem,c_sel[i])+"\n"
end
end
is_chapter-=1
is_section-=1
end
if thebibliography!=nil then content << thebibliography end
content << "\\end{document}\n"
#print NKF.nkf("-w",content)
file=File.open($target+".tex","w")
file.print NKF.nkf("-s",content)
file.close
Keyword(s):
References:[Hiki2LatexPaper]