view Paper/o2tex @ 22:1b513be6fbab

fix
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 26 Nov 2012 19:45:58 +0900
parents a323397febf4
children
line wrap: on
line source

#!/usr/bin/perl
use strict;
use warnings;


unlink "title.tex";
unlink "abstract.tex";
unlink "abstract-e.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");

my $alt0 = "fig000";

my $paper = $ARGV[0];

my $fh;

&Pick('>', "title.tex") ;
print $fh <<RogueRogue;
RogueRogue

&Pick('>', "00.tex") ;
print $fh <<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

&Pick('>', "jsss00.tex") ;
print $fh <<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{}
% 英文のみのタイトルならば,\\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


&Pick('>', "ohp00.tex") ;
print $fh <<RogueRogue;
\\documentstyle[blackandwhite,landscape,oval,pagenumbers]{NRslides}
% run this through SLiTeX
\\input tgrindfi.tex
\\raggedright
\\begin{document}

RogueRogue

&Pick('>', "trcover.tex") ;
print $fh <<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


$\ = "\n";

my $depth = 0;
my $section = 1;
my $file = '00.tex';
my $zero = '00.tex';
my $ohp = 'ohp00.tex';
my $cover = 'trcover.tex';
my $note = 1;
my $abstract = 0;
my $cite = "%";
my $m = "";  # msdos make

my @depend = ($paper);
my @ohpdepend = ('ohp.tex');

my $verbatim = 1;

my $pre;
my $day;
my $title;
my $number;
my $author;
my $backup;
my %opened;

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: (.*)/) {
	open(my $fdbase,"nkf -w $1 |");
	push(@depend,$1);
#	print STDOUT "$1 ";
	&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 (/^--*date:/) {
        my $tmp;
	for ($tmp = 1; substr($_, $tmp, 1) eq '-'; $tmp++) {
	    ;
	}
	$tmp += 5;
	$day = substr($_, $tmp, length($_) - $tmp + 1);
	next line;
    }
    if (/^--*number:/) {
        my $tmp;
	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:/) {
        my $tmp;
	$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 = 'title-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 == 2) {
	    $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 == 3) {
	    $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 == 4) {
	    $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) {
	my $fig = $1; my $alt = $2;
        my $caption;
	if ($fig) {
	    $fig =~ s/\.gif|\.jpg/.eps/;
	}
        if (! $alt) {
            $alt = $alt0++;
            $caption = "";
        } else {
            $caption = "\\caption{$alt}\n";
        }
	&Pick('>>', $file);
	# center environment disturbes caption counter and label reference
	my $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) {
	my $fig = $1; my $alt = $2;
        my $caption;
	if ($fig) {
	    $fig =~ s/\.gif|\.jpg/.eps/;
	}
        if (! $alt) {
            $alt = $alt0++;
            $caption = "";
        } else {
            $caption = "\\caption{$alt}\n";
        }
	&Pick('>>', $file);
	my $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=([^{},]+)/ || 
	     /\\includegraphics\{([^{},]+)\}/ || 	     
            /\\input (.*)/ || /\\include (.*)/) { 
        my $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) {
            print $fh "{\\small\n\\begin{verbatim}";
            $pre = 1;
        }
        print $fh $_;
    } elsif (!/^-/) {
	&Pick('>>', $file) &&
	    (print $fh $_);
    }
    if (/\\cite\{/) { $cite = ""; } 
  }
}

foreach my $arg (@ARGV) {
  open(my $fdbase,"nkf -w $arg |") || die("$arg cannot open");
  &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) = @_;
    $pipe = "" if (! defined $pipe) ;
    if (! defined $opened{$name}) {
	open(my $mfh,$mode, $name.$pipe);
        $fh = $mfh;
        $opened{$name} = $fh;
    } else {
        $fh = $opened{$name};
    }
    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
SLITEX = jslitex
BIBTEX = jbibtex
AWK = awk
SED = sed
DVI2PS = dvi2ps 
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
.ps.gs:
	gs \$*.ps

all: 	
	-rm -f \$(MAIN).dvi
	make \$(MAIN).dvi

print: \$(MAIN).print
lw: \$(MAIN).lw
next: \$(MAIN).next
gs: \$(MAIN).gs
\$(MAIN).gs : \$(MAIN).ps
\$(MAIN).ps : \$(MAIN).dvi
\$(OHP).gs : \$(OHP).ps
\$(OHP).ps : \$(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