diff paper/o2tex @ 10:99f297cb7d34

hi hi
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 11 Aug 2011 21:26:04 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paper/o2tex	Thu Aug 11 21:26:04 2011 +0900
@@ -0,0 +1,714 @@
+#!/usr/bin/perl
+
+use strict;
+
+my $FS;
+my $abstract;
+my $alt;
+my $alt0;
+my $arg;
+my $author;
+my $backup;
+my $caption;
+my $cite;
+my $cover;
+my $current;
+my $day;
+my $depth;
+my $fdbase;
+my $fh;
+my $fig;
+my $file;
+my $m;
+my $mode;
+my $name;
+my $nextfh;
+my $note;
+my $number;
+my $ohp;
+my $paper;
+my $pipe;
+my $pre;
+my $section;
+my $title;
+my $tmp;
+my $verbatim;
+my $zero;
+my %opened;
+my @depend;
+my @ohpdepend;
+my $fh;
+my $line;
+
+unlink "title.tex";
+unlink "abstract.tex";
+unlink "cover.tex";
+# for msdos
+system("rm -f 0*.tex 1*.tex 2.tex 3.tex 4.tex 5.tex 6.tex 7.tex 8.tex 9.tex");
+
+$alt0 = "fig000";
+
+$paper = $ARGV[0];
+
+open(fh,">title.tex"); select(fh);
+print <<RogueRogue;
+RogueRogue
+
+close fh;
+open(fh,">abstract.tex"); select(fh);
+print <<RogueRogue;
+RogueRogue
+
+close fh;
+open(fh,">abstract-e.tex"); select(fh);
+print <<RogueRogue;
+RogueRogue
+
+close fh;
+open(fh,">00.tex"); select(fh);
+print <<RogueRogue;
+\\documentclass[12pt]{article} %%%%% preamble            %%%%%
+\\usepackage[dvipdfm]{graphicx}
+
+%\\textwidth 16.3cm	% the text frame size
+%\\textheight 23cm
+%\\oddsidemargin 5mm	% for centering
+%\\evensidemargin 13mm	% for centering
+%\\topmargin 1mm
+%\\pagestyle{empty}
+\\pagestyle{plain}
+\\begin{document}		%%%%% the main routine begins here	%%%%%
+%\\baselinestretch 2
+%\\flushbottom
+%\\large				% character size
+%\\setlength{\\baselineskip}{1cm}	% line spacing
+RogueRogue
+
+close fh;
+open(fh,">jsss00.tex"); select(fh);
+print <<RogueRogue;
+
+\\documentclass[twocolumn]{jarticle}
+\\usepackage[dvipdfm]{graphicx}
+
+%\hoffset -1in \\addtolength{\hoffset}{20mm}
+%\voffset -1in \\addtolength{\voffset}{20mm}
+%\oddsidemargin 0mm
+\\topmargin -4mm
+%\\headheight 13pt
+%\\headsep 15mm
+%\\textheight 43\\baselineskip \\addtolength{\\textheight}{\\topskip}
+%\\textwidth 160mm
+%\\marginparsep 3mm
+%\\marginparwidth 15mm
+%\\footskip \headsep
+
+\\begin{document}
+% \input tgrindfig.tex
+\\bibliographystyle{jplain} % for bibliography
+%
+\\include{title}
+%\\title{}
+
+\\date{}
+
+
+\\author{{河野真治} \\\\
+琉球大学理工学研究科情報工学専攻\\\\
+琉球大学工学部情報工学科\\\\
+}
+\\twocolumn[   
+\\maketitle{}
+
+% {\\em 概要 \vspace{0.5cm}}\\
+\\include{abstract.tex}
+\\begin{center}
+{\\Large 
+\\include{title-e.tex}\\
+\\include{author-e.tex}} \\\\ \\hspace{0.7cm}
+\\end{center}
+
+% {\tt \\Large Abstract}\\
+\\include{abstract-e.tex}
+\\\\
+\\hspace{0.5cm}
+]
+
+%
+\\input 0.tex
+%
+\\input reference.tex
+
+\\end{document}
+
+RogueRogue
+
+close fh;
+
+open(fh,">ohp00.tex"); select(fh);
+print <<RogueRogue;
+\\documentstyle[blackandwhite,landscape,oval,pagenumbers]{NRslides}
+% run this through SLiTeX
+\\input tgrindfi.tex
+\\raggedright
+\\begin{document}
+
+RogueRogue
+
+close fh;
+open(fh,">trcover.tex"); select(fh);
+print <<RogueRogue;
+\\documentstyle[a4,11pt]{article} %%%%% preamble		%%%%%
+%\\textwidth 16.3cm	% the text frame size
+%\\textheight 23cm
+%\\oddsidemargin 5mm	% for centering
+%\\evensidemargin 13mm	% for centering
+%\\topmargin 1mm
+\\begin{document}
+
+\\begin{titlepage}
+\\begin{center}\\vspace*{34mm}
+\\parbox[c]{12cm}{\\begin{center}
+RogueRogue
+
+close fh;
+
+
+$[ = 1;			# set array base to 1
+$FS = ' ';		# set field separator
+$, = ' ';		# set output field separator
+$\ = "\n";		# set output record separator
+
+$FS = "\n";
+$depth = 0;
+$section = 1;
+$file = '00.tex';
+$zero = '00.tex';
+$ohp = 'ohp00.tex';
+$cover = 'trcover.tex';
+$note = 1;
+$abstract = 0;
+$cite = "%";
+$m = "";  # msdos make
+$fdbase = "in00";
+
+@depend = ($paper);
+@ohpdepend = ('ohp.tex');
+
+$verbatim = 1;
+
+sub o2tex {
+my ($current) = @_;
+
+line: while (<$current>) {
+    chop;	# strip record separator
+    if( $verbatim && (!/^\s/) && (!/^$/) && $pre) {
+        print $fh "\\end{verbatim}\n}\n";
+        $pre = 0;
+    }
+    if (/^-*input: (.*)/) {
+	# $fdbase = $current; $fdbase ++;
+	my $fd;
+	open($fd,"nkf -w $1 |");
+	$fdbase = $fd;
+	push(@depend,$1);
+#	print STDOUT "$1 ";
+	do o2tex($fdbase);
+	next line;
+    }
+    if (/^-title:/) {
+	$file = 'title.tex';
+	$title = substr($_, 8, length($_) - 7);
+	&Pick('>>', $file) &&
+	    (printf $fh "\\title{{\\bf %s}}\n", $title);
+	&Pick('>>', $ohp) &&
+	    (printf $fh "\\title{{\\bf %s}}\n", $title);
+	next line;
+    }
+    if (/^-title-e:/) {
+	$file = 'title-e.tex';
+	$title = substr($_, 10, length($_) - 9);
+	&Pick('>>', $file) &&
+	    (printf $fh "\\title{{\\bf %s}}\n", $title);
+	&Pick('>>', $ohp) &&
+	    (printf $fh "\\title{{\\bf %s}}\n", $title);
+	next line;
+    }
+    if (/^--*date:/) {
+	for ($tmp = 1; substr($_, $tmp, 1) eq '-'; $tmp++) {
+	    ;
+	}
+	$tmp += 5;
+	$day = substr($_, $tmp, length($_) - $tmp + 1);
+	next line;
+    }
+    if (/^--*number:/) {
+	for ($tmp = 1; substr($_, $tmp, 1) eq '-'; $tmp++) {
+	    ;
+	}
+	$tmp += 7;
+	$number = substr($_, $tmp, length($_) - $tmp + 1);
+	next line;
+    }
+    if (/^--*note:/) {
+	&trcover();
+	$note = 2;
+	$file = 'trcover.tex';
+	&Pick('>>', $file) &&
+	    (printf $fh "\\clearpage\n");
+	    (printf $fh "\\vspace*{\\fill}\n");
+	    (printf $fh "\\begin{quote}\n");
+	next line;
+    }
+    if (/^--*author:/) {
+	$file = 'title.tex';
+	for ($tmp = 1; substr($_, $tmp, 1) eq '-'; $tmp++) {
+	    ;
+	}
+	$tmp += 7;
+	$author = substr($_, $tmp, length($_) - $tmp + 1);
+	&Pick('>>', $file) &&
+	    (printf $fh "%%\\pagenumbering{roman}\n");
+	    (printf $fh "\\author{%s \\\\[5mm]\n", $author);
+	    (printf $fh "e-mail:kono\@ie.u-ryukyu.ac.jp\\\\\n");
+	    (printf $fh "Information Engineering, University of the Ryukyus\\\\\n");
+	    (printf $fh "Nishihara-cyo 1, Okinawa, 903-01, Japan}\n");
+	if ($day) {
+		(printf $fh "\\date{%s}\n", $day);
+	}
+	else {
+		(printf $fh "%% \\date{}\n");
+	}
+	$file = sprintf('%d', $section) . '.tex';
+
+	&Pick('>>', $ohp) &&
+	    (printf $fh "\\author{%s \\\\[5mm]\n", $author);
+	    (printf $fh ".Information Engineering, University of the Ryukyus\n");
+	    (print $fh "%% \\today");
+	    (print $fh "\\maketitlepage");
+	next line;
+    }
+    if (/^--*author-e:/) {
+	$file = 'author-e.tex';
+	next line;
+    }
+    if (/^--*abstract-e:/) {
+	$file = 'abstract-e.tex';
+	$abstract = 1;
+	&Pick('>>', $file); # && (printf $fh "\\begin{quotation}\n");
+	next line;
+    }
+    if (/^--*abstract:/) {
+	$file = 'abstract.tex';
+	$abstract = 1;
+	&Pick('>>', $file); # && (printf $fh "\\begin{quotation}\n");
+	(print $fh "\\mbox{}");
+	next line;
+    }
+    if (/^--*begin-comment:/) {
+        $backup = $file;
+	$file = '/dev/null';
+	next line;
+    }
+    if (/^--*end-comment:/) {
+        $file = $backup;
+	next line;
+    }
+    if (/^-/) {
+	if ($abstract == 1) {
+	    &Pick('>>', $file); #  && (printf $fh "\\end{quotation}\n");
+
+	    $abstract = 0;
+	}
+	if ($note) {
+	    if ($note == 2) {
+		&Pick('>>', $cover) &&
+		    (printf $fh "\\end{quote}\n");
+	    }
+	    else {
+		&trcover();
+	    }
+	    $note = 0;
+	}
+	for ($depth = 1; substr($_, $depth, 1) eq '-'; $depth++) {
+	    ;
+	}
+	if ($depth == 3) {
+	    $file = sprintf('%d', $section) . '.tex';
+	    &Pick('>>', $file) &&
+		(print $fh "\\section{", substr($_, $depth,
+		  length($_) - $depth + 1) . '}');
+	    &Pick('>>', $ohp) &&
+		(print $fh "\\begin{bwslide}");
+		(print $fh "\\ctitle{", substr($_, $depth,
+		  length($_) - $depth + 1) . '}');
+		(print $fh "\\end{bwslide}\n\n");
+	    &Pick('>>', '0.tex') &&
+		(printf $fh "\\input{%d}\t%% %s\n", $section, substr($_,
+		  $depth, length($_) - $depth + 1));
+	    $section++;
+#	    print STDOUT "$section ";
+	}
+	elsif ($depth == 4) {
+	    $file = sprintf('%d', $section - 1) . '.tex';
+	    &Pick('>>', $file) &&
+		(print $fh "\\subsection{", substr($_, $depth,
+		  length($_) - $depth + 1) . '}');
+	    &Pick('>>', $ohp) &&
+		(print $fh "\\begin{bwslide}");
+		(print $fh "\\ctitle{", substr($_, $depth,
+		  length($_) - $depth + 1) . '}');
+		(print $fh "\\end{bwslide}\n\n");
+	}
+	elsif ($depth == 5) {
+	    $file = sprintf('%d', $section - 1) . '.tex';
+	    &Pick('>>', $file) &&
+		(print $fh "\\subsubsection{", substr($_, $depth,
+		  length($_) - $depth + 1) . '}');
+	    &Pick('>>', $ohp) &&
+		(print $fh "\\begin{bwslide}");
+		(print $fh "\\ctitle{", substr($_, $depth,
+		  length($_) - $depth + 1) . '}');
+		(print $fh "\\end{bwslide}\n\n");
+	}
+	else {
+	    $file = sprintf('%d', $section - 1) . '.tex';
+	    &Pick('>>', $file) &&
+		(printf $fh "%s\\\\\n", substr($_, $depth,
+		  length($_) - $depth + 1));
+	}
+	next line;
+    } elsif (m!^<center>\s*<img.*src="([^>"]*)"[^>]*alt="([^>"]*)"[^>]*>\s*</center>!i) {
+	$fig = $1; $alt = $2;
+	if ($fig) {
+            # leave .pdf untouch
+	    $fig =~ s/\.gif|\.jpg/.eps/;
+	}
+	if ($fig =~ /\.pdf/ && -f $fig) {
+            # generate .bb file
+	    system "ebb $fig";
+	}
+        if (! $alt) {
+            $alt = $alt0++;
+            $caption = "";
+        } else {
+            $caption = "\\caption{$alt}\n";
+        }
+	&Pick('>>', $file);
+	# center environment disturbes caption counter and label reference
+	$line =  <<"EOF";
+\\begin{figure}[htb]
+\\begin{center}
+\\includegraphics[width=6cm]{${fig}}
+${caption}\\end{center}
+\\label{${alt}}
+\\end{figure}
+EOF
+	# print $fh "(fig.\\ref{$alt})\n";
+	print $fh $line;
+	&Pick('>>', $ohp) &&
+	    (print $fh "\\centerline{$line}\n");
+	if(! /^\s*%/) {
+            $fig =~ s/[{}]//g;
+	    push(@depend,$fig);
+	    push(@ohpdepend,$fig);
+	}
+	next line;
+    } elsif (m!^<center>\s*<img.*src="([^>"]*)"[^>]*>\s*</center>!i) {
+	$fig = $1; $alt = $2;
+	if ($fig) {
+	    $fig =~ s/\.gif|\.jpg/.eps/;
+	}
+        if (! $alt) {
+            $alt = $alt0++;
+            $caption = "";
+        } else {
+            $caption = "\\caption{$alt}\n";
+        }
+	&Pick('>>', $file);
+	$line =  <<"EOF";
+\\begin{figure}[htb]
+\\begin{center}
+\\includegraphics[width=6cm]{${fig}}
+${caption}\\end{center}
+\\label{${alt}}
+\\end{figure}
+EOF
+	# print $fh "(fig.\\ref{$alt})\n";
+	print $fh $line;
+	&Pick('>>', $ohp) &&
+	    (print $fh "\\centerline{$line}\n");
+	if(! /^\s*%/) {
+            $fig =~ s/[{}]//g;
+	    push(@depend,$fig);
+	    push(@ohpdepend,$fig);
+	}
+	next line;
+    } elsif (/\\epsfile\{.*file=([^{},]+)/ || 
+            /\\input(.*)/ || /\\include(.*)/) { 
+        $fig = $1;
+	&Pick('>>', $file) &&
+	    (print $fh $_);
+	&Pick('>>', $ohp) &&
+	    (print $fh "\\centerline{$_}\n");
+	if(! /^\s*%/) {
+            $fig =~ s/[{}]//g;
+	    push(@depend,$fig);
+	    push(@ohpdepend,$fig);
+	}
+	next line;
+    } elsif ($verbatim && /^\s/) {
+        if(! $pre) {
+	    &Pick('>>', $file) &&
+            print $fh "{\\small\n\\begin{verbatim}";
+            $pre = 1;
+        }
+        print $fh $_;
+    } elsif (!/^-/) {
+	&Pick('>>', $file) &&
+	    (print $fh $_);
+    }
+    if (/\\cite\{/) { $cite = ""; } # }
+  }
+}
+
+foreach $arg (@ARGV) {
+    if ($arg eq '-n') {
+	$verbatim = 0 ; next;
+    }
+  my $fd;
+  open($fd,"nkf -w $arg |") || die("$arg cannot open");
+  $fdbase = $fd;
+  do o2tex($fdbase);
+}
+
+&Pick('>>', $zero);
+    select($fh);
+       printf $fh "%s\\bibliographystyle{jplain} %% for bibliography\n", $cite;
+    print <<RogueRogue ;
+\\input{title}	% title, abstract 
+\\maketitle
+\\begin{quote}
+\\input{abstract}
+\\end{quote}
+%%%%\\tableofcontents		%% contents, lists
+%%%%\\listoffigures
+%%%%\\listoftables
+%\\pagenumbering{arabic}
+
+\\input{0}	% sections
+RogueRogue
+
+    printf $fh "%s\\bibliography{ref}\n", $cite;
+    if($cite eq "%") { $cite = "#" ; }
+&Pick('>>', $zero) &&
+    (printf $fh "\\end{document}\n");
+    close($fh);
+&Pick('>>', $ohp) &&
+    (printf $fh "\n\\end{document}\n");
+    close($fh);
+
+sub trcover {
+    if ($title) {
+	&Pick('>>', $cover) &&
+	    (printf $fh "{\\LARGE\\bf %s}\\\\[+5mm]\n", $title);
+    }
+    if ($author) {
+	&Pick('>>', $cover) &&
+	    (printf $fh "{\\large %s}\\\\[+5mm]\n", $author);
+    }
+    if ($number) {
+	&Pick('>>', $cover) &&
+	    (printf $fh "{\\large %s}\\\\[+4mm]\n", $number);
+    }
+    if ($day) {
+	&Pick('>>', $cover) &&
+	    (printf $fh "{\\large %s}\n", $day);
+    }
+    &Pick('>>', $cover) &&
+	(print $fh "\\end{center}}\\\\");
+	(print $fh "\\vfill");
+	(printf $fh "{\\Large Information Engineering, University of the Ryukyus\\\\\n");
+	(print $fh "Nishihara-cho 1, Okinawa, 903-01 JAPAN}\\\\[+2cm]");
+	(print $fh "{\\small Copyright \\copyright\\ \\number\\year\\");
+	(print $fh 'University of the Ryukyus');
+	(print $fh "}\\\\[+1cm]");
+	(print $fh "\\end{center}");
+	(print $fh "\\end{titlepage}\n\n");
+    return;
+}
+
+sub Pick {
+    my ($mode,$name,$pipe) = @_;
+    $fh = $opened{$name};
+    if (!$fh) {
+	my $fd;
+	# $fh = $opened{$name} = 'fh_' . ($nextfh++ + 0);
+	open($fd,$mode.$name.$pipe);
+	$fh = $opened{$name} = $fd;
+    }
+    1;
+}
+
+&Pick('>>', $cover) &&
+print $fh "\\end{document}\n";
+close $fh;
+
+if (! -f Makefile) {
+open(fh,">Makefile"); select(fh);
+print "PAPER = ". $paper . "\n";
+print <<RogueRogue;
+
+PRINTER = ab
+OHP = ohp
+MAIN = main
+COVER = trcover
+LATEX = platex-utf8
+SLITEX = jslitex
+BIBTEX = jbibtex -kanji=utf8
+AWK = awk
+SED = sed
+DVI2PS = dvi2ps 
+DVI2PS = dvipdfmx 
+R = 
+PRINTER = 
+
+$m.SUFFIXES: .c .d .tokio .x .xfig .fig .tex .dvi .print .lw .next .ps .gs .xdvi
+
+.d.tex:
+	tgrind -F -ldb \$< >\$@ 
+.c.tex:
+	tgrind -F -lC \$< >\$@ 
+.tokio.tex:
+	tgrind -F -ltokio \$< >\$@ 
+.fig.tex:
+	f2tpic \$< >\$@
+.xfig.tex:
+	f2tpic \$< >\$@
+.fig.ps:
+	f2ps1 \$< >\$@
+.x.tex:
+	x2tpic \$< 
+	-rm -f \$*.pic
+.tex.dvi:
+	jlatex \$<
+.dvi.print:
+	\$(DVI2PS) \$(R) \$< | lpr -P\$(PRINTER)
+#	lpr \$(PRINTER) -d \$<
+.dvi.lw:
+	\$(DVI2PS) \$(R) \$< | lpr -P\$(PRINTER)
+.dvi.next:
+	dviNeXT \$<
+.dvi.xdvi:
+	(exec xdvi \$< & )
+.dvi.ps:
+	-\$(DVI2PS) \$(R) \$< > \$*.ps
+.dvi.pdf:
+	-\$(DVI2PDF)  \$< 
+.ps.gs:
+	gs \$*.ps
+
+all: 	
+	-rm -f \$(MAIN).dvi \$(MAIN).pdf
+	make \$(MAIN).pdf
+
+print: \$(MAIN).print
+lw: \$(MAIN).lw
+next: \$(MAIN).next
+gs: \$(MAIN).gs
+\$(MAIN).gs : \$(MAIN).ps
+\$(MAIN).ps : \$(MAIN).dvi
+\$(MAIN).pdf : \$(MAIN).dvi
+\$(OHP).gs : \$(OHP).ps
+\$(OHP).ps : \$(OHP).dvi
+\$(OHP).pdf : \$(OHP).dvi
+xdvi: \$(MAIN).xdvi
+dvips: \$(MAIN).dvi
+	dvips \$(MAIN).dvi -o \$(MAIN).ps
+
+\$(MAIN).dvi:  1.tex 
+	\$(LATEX) \$(MAIN)
+
+jsss.dvi:  jsss.tex 1.tex 
+	\$(LATEX) jsss.tex
+
+wc:
+	\$(SED) -e '/\\\\special{/d' \$(PAPER) | delatex | wc
+uu:
+	tar cBf - \$(MAIN).[tab]* [0-9]*.tex \$(DEPENDENCY)   \\
+	title.tex abstract.tex ohp.tex \\
+	Makefile | gzip | uuencode \$(PAPER).tar.gz > uu
+
+
+bbl: \$(MAIN).bbl
+
+\$(MAIN).bbl:  ref.bib 1.tex # \$(MAIN).aux
+	-\$(BIBTEX) \$(MAIN)
+
+\$(MAIN).aux: \$(MAIN).tex 1.tex
+	\$(LATEX) \$(MAIN)
+
+1.tex: \$(PAPER) \$(DEPENDENCY)
+	-o2tex \$(PAPER)
+
+# OHP with slitex
+\$(OHP): \$(OHP).dvi
+\$(OHP).dvi : \$(OHP).tex \$(DEPENDOHP)
+	\$(SLITEX) \$(OHP)
+
+ohpprint: \$(OHP).dvi
+	lpr  -c \$(OHP).dvi
+ohplw: \$(OHP).dvi
+	\$(DVI2PS) \$(R) -o landscape \$(OHP).dvi | lpr  -P\$(PRINTER)
+ohpnext: \$(OHP).dvi
+	\$(DVI2PS) -h -i /usr/lib/tex/ps/tex-j.next -o landscape \$(OHP).dvi |\\
+	lpr  -Pcb
+ohpgs:  \$(OHP).gs
+
+cover: \$(COVER).dvi
+\$(COVER): \$(COVER).dvi
+\$(COVER).dvi : \$(PAPER)
+coverprint: \$(COVER).print
+coverlw: \$(COVER).lw
+covernext: \$(COVER).next
+covergs:  \$(COVER).gs
+
+clean:
+	-rm -f \$(MAIN).ps *.dvi *.log *.blg \\
+		*~ \\#* ?.tex *.toc *.lof *.lot xfig/*.tex
+
+tgrindfig.tex:
+	ln -s "\$\$HOME"/paper/tgrindfig.tex .
+# for MSDOS
+tgrindfi.tex:
+	ln -s "\$\$HOME"/paper/tgrindfig.tex tgrindfi.tex
+ref.bib:
+	ln -s "\$\$HOME"/paper/ref.bib .
+
+RogueRogue
+close fh;
+}
+if ( ! -f "main.tex") {
+	rename('00.tex','main.tex');
+}
+if ( ! -f "jsss.tex") {
+	rename('jsss00.tex','jsss.tex');
+}
+if ( ! -f "ohp.tex") {
+	rename('ohp00.tex','ohp.tex');
+}
+# make depend > /dev/null
+
+rename("Makefile","Makefile.old");
+open(MAKE, "<Makefile.old");
+open(fh,">Makefile");
+select(fh);
+print "DEPENDENCY = @depend\n";
+print "DEPENDOHP = @ohpdepend\n";
+while(<MAKE>) {
+   next if(/^DEPEND/);
+   chop; print;
+}
+close(fh);
+
+# end