comparison 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
comparison
equal deleted inserted replaced
9:504aea3b42be 10:99f297cb7d34
1 #!/usr/bin/perl
2
3 use strict;
4
5 my $FS;
6 my $abstract;
7 my $alt;
8 my $alt0;
9 my $arg;
10 my $author;
11 my $backup;
12 my $caption;
13 my $cite;
14 my $cover;
15 my $current;
16 my $day;
17 my $depth;
18 my $fdbase;
19 my $fh;
20 my $fig;
21 my $file;
22 my $m;
23 my $mode;
24 my $name;
25 my $nextfh;
26 my $note;
27 my $number;
28 my $ohp;
29 my $paper;
30 my $pipe;
31 my $pre;
32 my $section;
33 my $title;
34 my $tmp;
35 my $verbatim;
36 my $zero;
37 my %opened;
38 my @depend;
39 my @ohpdepend;
40 my $fh;
41 my $line;
42
43 unlink "title.tex";
44 unlink "abstract.tex";
45 unlink "cover.tex";
46 # for msdos
47 system("rm -f 0*.tex 1*.tex 2.tex 3.tex 4.tex 5.tex 6.tex 7.tex 8.tex 9.tex");
48
49 $alt0 = "fig000";
50
51 $paper = $ARGV[0];
52
53 open(fh,">title.tex"); select(fh);
54 print <<RogueRogue;
55 RogueRogue
56
57 close fh;
58 open(fh,">abstract.tex"); select(fh);
59 print <<RogueRogue;
60 RogueRogue
61
62 close fh;
63 open(fh,">abstract-e.tex"); select(fh);
64 print <<RogueRogue;
65 RogueRogue
66
67 close fh;
68 open(fh,">00.tex"); select(fh);
69 print <<RogueRogue;
70 \\documentclass[12pt]{article} %%%%% preamble %%%%%
71 \\usepackage[dvipdfm]{graphicx}
72
73 %\\textwidth 16.3cm % the text frame size
74 %\\textheight 23cm
75 %\\oddsidemargin 5mm % for centering
76 %\\evensidemargin 13mm % for centering
77 %\\topmargin 1mm
78 %\\pagestyle{empty}
79 \\pagestyle{plain}
80 \\begin{document} %%%%% the main routine begins here %%%%%
81 %\\baselinestretch 2
82 %\\flushbottom
83 %\\large % character size
84 %\\setlength{\\baselineskip}{1cm} % line spacing
85 RogueRogue
86
87 close fh;
88 open(fh,">jsss00.tex"); select(fh);
89 print <<RogueRogue;
90
91 \\documentclass[twocolumn]{jarticle}
92 \\usepackage[dvipdfm]{graphicx}
93
94 %\hoffset -1in \\addtolength{\hoffset}{20mm}
95 %\voffset -1in \\addtolength{\voffset}{20mm}
96 %\oddsidemargin 0mm
97 \\topmargin -4mm
98 %\\headheight 13pt
99 %\\headsep 15mm
100 %\\textheight 43\\baselineskip \\addtolength{\\textheight}{\\topskip}
101 %\\textwidth 160mm
102 %\\marginparsep 3mm
103 %\\marginparwidth 15mm
104 %\\footskip \headsep
105
106 \\begin{document}
107 % \input tgrindfig.tex
108 \\bibliographystyle{jplain} % for bibliography
109 %
110 \\include{title}
111 %\\title{}
112
113 \\date{}
114
115
116 \\author{{河野真治} \\\\
117 琉球大学理工学研究科情報工学専攻\\\\
118 琉球大学工学部情報工学科\\\\
119 }
120 \\twocolumn[
121 \\maketitle{}
122
123 % {\\em 概要 \vspace{0.5cm}}\\
124 \\include{abstract.tex}
125 \\begin{center}
126 {\\Large
127 \\include{title-e.tex}\\
128 \\include{author-e.tex}} \\\\ \\hspace{0.7cm}
129 \\end{center}
130
131 % {\tt \\Large Abstract}\\
132 \\include{abstract-e.tex}
133 \\\\
134 \\hspace{0.5cm}
135 ]
136
137 %
138 \\input 0.tex
139 %
140 \\input reference.tex
141
142 \\end{document}
143
144 RogueRogue
145
146 close fh;
147
148 open(fh,">ohp00.tex"); select(fh);
149 print <<RogueRogue;
150 \\documentstyle[blackandwhite,landscape,oval,pagenumbers]{NRslides}
151 % run this through SLiTeX
152 \\input tgrindfi.tex
153 \\raggedright
154 \\begin{document}
155
156 RogueRogue
157
158 close fh;
159 open(fh,">trcover.tex"); select(fh);
160 print <<RogueRogue;
161 \\documentstyle[a4,11pt]{article} %%%%% preamble %%%%%
162 %\\textwidth 16.3cm % the text frame size
163 %\\textheight 23cm
164 %\\oddsidemargin 5mm % for centering
165 %\\evensidemargin 13mm % for centering
166 %\\topmargin 1mm
167 \\begin{document}
168
169 \\begin{titlepage}
170 \\begin{center}\\vspace*{34mm}
171 \\parbox[c]{12cm}{\\begin{center}
172 RogueRogue
173
174 close fh;
175
176
177 $[ = 1; # set array base to 1
178 $FS = ' '; # set field separator
179 $, = ' '; # set output field separator
180 $\ = "\n"; # set output record separator
181
182 $FS = "\n";
183 $depth = 0;
184 $section = 1;
185 $file = '00.tex';
186 $zero = '00.tex';
187 $ohp = 'ohp00.tex';
188 $cover = 'trcover.tex';
189 $note = 1;
190 $abstract = 0;
191 $cite = "%";
192 $m = ""; # msdos make
193 $fdbase = "in00";
194
195 @depend = ($paper);
196 @ohpdepend = ('ohp.tex');
197
198 $verbatim = 1;
199
200 sub o2tex {
201 my ($current) = @_;
202
203 line: while (<$current>) {
204 chop; # strip record separator
205 if( $verbatim && (!/^\s/) && (!/^$/) && $pre) {
206 print $fh "\\end{verbatim}\n}\n";
207 $pre = 0;
208 }
209 if (/^-*input: (.*)/) {
210 # $fdbase = $current; $fdbase ++;
211 my $fd;
212 open($fd,"nkf -w $1 |");
213 $fdbase = $fd;
214 push(@depend,$1);
215 # print STDOUT "$1 ";
216 do o2tex($fdbase);
217 next line;
218 }
219 if (/^-title:/) {
220 $file = 'title.tex';
221 $title = substr($_, 8, length($_) - 7);
222 &Pick('>>', $file) &&
223 (printf $fh "\\title{{\\bf %s}}\n", $title);
224 &Pick('>>', $ohp) &&
225 (printf $fh "\\title{{\\bf %s}}\n", $title);
226 next line;
227 }
228 if (/^-title-e:/) {
229 $file = 'title-e.tex';
230 $title = substr($_, 10, length($_) - 9);
231 &Pick('>>', $file) &&
232 (printf $fh "\\title{{\\bf %s}}\n", $title);
233 &Pick('>>', $ohp) &&
234 (printf $fh "\\title{{\\bf %s}}\n", $title);
235 next line;
236 }
237 if (/^--*date:/) {
238 for ($tmp = 1; substr($_, $tmp, 1) eq '-'; $tmp++) {
239 ;
240 }
241 $tmp += 5;
242 $day = substr($_, $tmp, length($_) - $tmp + 1);
243 next line;
244 }
245 if (/^--*number:/) {
246 for ($tmp = 1; substr($_, $tmp, 1) eq '-'; $tmp++) {
247 ;
248 }
249 $tmp += 7;
250 $number = substr($_, $tmp, length($_) - $tmp + 1);
251 next line;
252 }
253 if (/^--*note:/) {
254 &trcover();
255 $note = 2;
256 $file = 'trcover.tex';
257 &Pick('>>', $file) &&
258 (printf $fh "\\clearpage\n");
259 (printf $fh "\\vspace*{\\fill}\n");
260 (printf $fh "\\begin{quote}\n");
261 next line;
262 }
263 if (/^--*author:/) {
264 $file = 'title.tex';
265 for ($tmp = 1; substr($_, $tmp, 1) eq '-'; $tmp++) {
266 ;
267 }
268 $tmp += 7;
269 $author = substr($_, $tmp, length($_) - $tmp + 1);
270 &Pick('>>', $file) &&
271 (printf $fh "%%\\pagenumbering{roman}\n");
272 (printf $fh "\\author{%s \\\\[5mm]\n", $author);
273 (printf $fh "e-mail:kono\@ie.u-ryukyu.ac.jp\\\\\n");
274 (printf $fh "Information Engineering, University of the Ryukyus\\\\\n");
275 (printf $fh "Nishihara-cyo 1, Okinawa, 903-01, Japan}\n");
276 if ($day) {
277 (printf $fh "\\date{%s}\n", $day);
278 }
279 else {
280 (printf $fh "%% \\date{}\n");
281 }
282 $file = sprintf('%d', $section) . '.tex';
283
284 &Pick('>>', $ohp) &&
285 (printf $fh "\\author{%s \\\\[5mm]\n", $author);
286 (printf $fh ".Information Engineering, University of the Ryukyus\n");
287 (print $fh "%% \\today");
288 (print $fh "\\maketitlepage");
289 next line;
290 }
291 if (/^--*author-e:/) {
292 $file = 'author-e.tex';
293 next line;
294 }
295 if (/^--*abstract-e:/) {
296 $file = 'abstract-e.tex';
297 $abstract = 1;
298 &Pick('>>', $file); # && (printf $fh "\\begin{quotation}\n");
299 next line;
300 }
301 if (/^--*abstract:/) {
302 $file = 'abstract.tex';
303 $abstract = 1;
304 &Pick('>>', $file); # && (printf $fh "\\begin{quotation}\n");
305 (print $fh "\\mbox{}");
306 next line;
307 }
308 if (/^--*begin-comment:/) {
309 $backup = $file;
310 $file = '/dev/null';
311 next line;
312 }
313 if (/^--*end-comment:/) {
314 $file = $backup;
315 next line;
316 }
317 if (/^-/) {
318 if ($abstract == 1) {
319 &Pick('>>', $file); # && (printf $fh "\\end{quotation}\n");
320
321 $abstract = 0;
322 }
323 if ($note) {
324 if ($note == 2) {
325 &Pick('>>', $cover) &&
326 (printf $fh "\\end{quote}\n");
327 }
328 else {
329 &trcover();
330 }
331 $note = 0;
332 }
333 for ($depth = 1; substr($_, $depth, 1) eq '-'; $depth++) {
334 ;
335 }
336 if ($depth == 3) {
337 $file = sprintf('%d', $section) . '.tex';
338 &Pick('>>', $file) &&
339 (print $fh "\\section{", substr($_, $depth,
340 length($_) - $depth + 1) . '}');
341 &Pick('>>', $ohp) &&
342 (print $fh "\\begin{bwslide}");
343 (print $fh "\\ctitle{", substr($_, $depth,
344 length($_) - $depth + 1) . '}');
345 (print $fh "\\end{bwslide}\n\n");
346 &Pick('>>', '0.tex') &&
347 (printf $fh "\\input{%d}\t%% %s\n", $section, substr($_,
348 $depth, length($_) - $depth + 1));
349 $section++;
350 # print STDOUT "$section ";
351 }
352 elsif ($depth == 4) {
353 $file = sprintf('%d', $section - 1) . '.tex';
354 &Pick('>>', $file) &&
355 (print $fh "\\subsection{", substr($_, $depth,
356 length($_) - $depth + 1) . '}');
357 &Pick('>>', $ohp) &&
358 (print $fh "\\begin{bwslide}");
359 (print $fh "\\ctitle{", substr($_, $depth,
360 length($_) - $depth + 1) . '}');
361 (print $fh "\\end{bwslide}\n\n");
362 }
363 elsif ($depth == 5) {
364 $file = sprintf('%d', $section - 1) . '.tex';
365 &Pick('>>', $file) &&
366 (print $fh "\\subsubsection{", substr($_, $depth,
367 length($_) - $depth + 1) . '}');
368 &Pick('>>', $ohp) &&
369 (print $fh "\\begin{bwslide}");
370 (print $fh "\\ctitle{", substr($_, $depth,
371 length($_) - $depth + 1) . '}');
372 (print $fh "\\end{bwslide}\n\n");
373 }
374 else {
375 $file = sprintf('%d', $section - 1) . '.tex';
376 &Pick('>>', $file) &&
377 (printf $fh "%s\\\\\n", substr($_, $depth,
378 length($_) - $depth + 1));
379 }
380 next line;
381 } elsif (m!^<center>\s*<img.*src="([^>"]*)"[^>]*alt="([^>"]*)"[^>]*>\s*</center>!i) {
382 $fig = $1; $alt = $2;
383 if ($fig) {
384 # leave .pdf untouch
385 $fig =~ s/\.gif|\.jpg/.eps/;
386 }
387 if ($fig =~ /\.pdf/ && -f $fig) {
388 # generate .bb file
389 system "ebb $fig";
390 }
391 if (! $alt) {
392 $alt = $alt0++;
393 $caption = "";
394 } else {
395 $caption = "\\caption{$alt}\n";
396 }
397 &Pick('>>', $file);
398 # center environment disturbes caption counter and label reference
399 $line = <<"EOF";
400 \\begin{figure}[htb]
401 \\begin{center}
402 \\includegraphics[width=6cm]{${fig}}
403 ${caption}\\end{center}
404 \\label{${alt}}
405 \\end{figure}
406 EOF
407 # print $fh "(fig.\\ref{$alt})\n";
408 print $fh $line;
409 &Pick('>>', $ohp) &&
410 (print $fh "\\centerline{$line}\n");
411 if(! /^\s*%/) {
412 $fig =~ s/[{}]//g;
413 push(@depend,$fig);
414 push(@ohpdepend,$fig);
415 }
416 next line;
417 } elsif (m!^<center>\s*<img.*src="([^>"]*)"[^>]*>\s*</center>!i) {
418 $fig = $1; $alt = $2;
419 if ($fig) {
420 $fig =~ s/\.gif|\.jpg/.eps/;
421 }
422 if (! $alt) {
423 $alt = $alt0++;
424 $caption = "";
425 } else {
426 $caption = "\\caption{$alt}\n";
427 }
428 &Pick('>>', $file);
429 $line = <<"EOF";
430 \\begin{figure}[htb]
431 \\begin{center}
432 \\includegraphics[width=6cm]{${fig}}
433 ${caption}\\end{center}
434 \\label{${alt}}
435 \\end{figure}
436 EOF
437 # print $fh "(fig.\\ref{$alt})\n";
438 print $fh $line;
439 &Pick('>>', $ohp) &&
440 (print $fh "\\centerline{$line}\n");
441 if(! /^\s*%/) {
442 $fig =~ s/[{}]//g;
443 push(@depend,$fig);
444 push(@ohpdepend,$fig);
445 }
446 next line;
447 } elsif (/\\epsfile\{.*file=([^{},]+)/ ||
448 /\\input(.*)/ || /\\include(.*)/) {
449 $fig = $1;
450 &Pick('>>', $file) &&
451 (print $fh $_);
452 &Pick('>>', $ohp) &&
453 (print $fh "\\centerline{$_}\n");
454 if(! /^\s*%/) {
455 $fig =~ s/[{}]//g;
456 push(@depend,$fig);
457 push(@ohpdepend,$fig);
458 }
459 next line;
460 } elsif ($verbatim && /^\s/) {
461 if(! $pre) {
462 &Pick('>>', $file) &&
463 print $fh "{\\small\n\\begin{verbatim}";
464 $pre = 1;
465 }
466 print $fh $_;
467 } elsif (!/^-/) {
468 &Pick('>>', $file) &&
469 (print $fh $_);
470 }
471 if (/\\cite\{/) { $cite = ""; } # }
472 }
473 }
474
475 foreach $arg (@ARGV) {
476 if ($arg eq '-n') {
477 $verbatim = 0 ; next;
478 }
479 my $fd;
480 open($fd,"nkf -w $arg |") || die("$arg cannot open");
481 $fdbase = $fd;
482 do o2tex($fdbase);
483 }
484
485 &Pick('>>', $zero);
486 select($fh);
487 printf $fh "%s\\bibliographystyle{jplain} %% for bibliography\n", $cite;
488 print <<RogueRogue ;
489 \\input{title} % title, abstract
490 \\maketitle
491 \\begin{quote}
492 \\input{abstract}
493 \\end{quote}
494 %%%%\\tableofcontents %% contents, lists
495 %%%%\\listoffigures
496 %%%%\\listoftables
497 %\\pagenumbering{arabic}
498
499 \\input{0} % sections
500 RogueRogue
501
502 printf $fh "%s\\bibliography{ref}\n", $cite;
503 if($cite eq "%") { $cite = "#" ; }
504 &Pick('>>', $zero) &&
505 (printf $fh "\\end{document}\n");
506 close($fh);
507 &Pick('>>', $ohp) &&
508 (printf $fh "\n\\end{document}\n");
509 close($fh);
510
511 sub trcover {
512 if ($title) {
513 &Pick('>>', $cover) &&
514 (printf $fh "{\\LARGE\\bf %s}\\\\[+5mm]\n", $title);
515 }
516 if ($author) {
517 &Pick('>>', $cover) &&
518 (printf $fh "{\\large %s}\\\\[+5mm]\n", $author);
519 }
520 if ($number) {
521 &Pick('>>', $cover) &&
522 (printf $fh "{\\large %s}\\\\[+4mm]\n", $number);
523 }
524 if ($day) {
525 &Pick('>>', $cover) &&
526 (printf $fh "{\\large %s}\n", $day);
527 }
528 &Pick('>>', $cover) &&
529 (print $fh "\\end{center}}\\\\");
530 (print $fh "\\vfill");
531 (printf $fh "{\\Large Information Engineering, University of the Ryukyus\\\\\n");
532 (print $fh "Nishihara-cho 1, Okinawa, 903-01 JAPAN}\\\\[+2cm]");
533 (print $fh "{\\small Copyright \\copyright\\ \\number\\year\\");
534 (print $fh 'University of the Ryukyus');
535 (print $fh "}\\\\[+1cm]");
536 (print $fh "\\end{center}");
537 (print $fh "\\end{titlepage}\n\n");
538 return;
539 }
540
541 sub Pick {
542 my ($mode,$name,$pipe) = @_;
543 $fh = $opened{$name};
544 if (!$fh) {
545 my $fd;
546 # $fh = $opened{$name} = 'fh_' . ($nextfh++ + 0);
547 open($fd,$mode.$name.$pipe);
548 $fh = $opened{$name} = $fd;
549 }
550 1;
551 }
552
553 &Pick('>>', $cover) &&
554 print $fh "\\end{document}\n";
555 close $fh;
556
557 if (! -f Makefile) {
558 open(fh,">Makefile"); select(fh);
559 print "PAPER = ". $paper . "\n";
560 print <<RogueRogue;
561
562 PRINTER = ab
563 OHP = ohp
564 MAIN = main
565 COVER = trcover
566 LATEX = platex-utf8
567 SLITEX = jslitex
568 BIBTEX = jbibtex -kanji=utf8
569 AWK = awk
570 SED = sed
571 DVI2PS = dvi2ps
572 DVI2PS = dvipdfmx
573 R =
574 PRINTER =
575
576 $m.SUFFIXES: .c .d .tokio .x .xfig .fig .tex .dvi .print .lw .next .ps .gs .xdvi
577
578 .d.tex:
579 tgrind -F -ldb \$< >\$@
580 .c.tex:
581 tgrind -F -lC \$< >\$@
582 .tokio.tex:
583 tgrind -F -ltokio \$< >\$@
584 .fig.tex:
585 f2tpic \$< >\$@
586 .xfig.tex:
587 f2tpic \$< >\$@
588 .fig.ps:
589 f2ps1 \$< >\$@
590 .x.tex:
591 x2tpic \$<
592 -rm -f \$*.pic
593 .tex.dvi:
594 jlatex \$<
595 .dvi.print:
596 \$(DVI2PS) \$(R) \$< | lpr -P\$(PRINTER)
597 # lpr \$(PRINTER) -d \$<
598 .dvi.lw:
599 \$(DVI2PS) \$(R) \$< | lpr -P\$(PRINTER)
600 .dvi.next:
601 dviNeXT \$<
602 .dvi.xdvi:
603 (exec xdvi \$< & )
604 .dvi.ps:
605 -\$(DVI2PS) \$(R) \$< > \$*.ps
606 .dvi.pdf:
607 -\$(DVI2PDF) \$<
608 .ps.gs:
609 gs \$*.ps
610
611 all:
612 -rm -f \$(MAIN).dvi \$(MAIN).pdf
613 make \$(MAIN).pdf
614
615 print: \$(MAIN).print
616 lw: \$(MAIN).lw
617 next: \$(MAIN).next
618 gs: \$(MAIN).gs
619 \$(MAIN).gs : \$(MAIN).ps
620 \$(MAIN).ps : \$(MAIN).dvi
621 \$(MAIN).pdf : \$(MAIN).dvi
622 \$(OHP).gs : \$(OHP).ps
623 \$(OHP).ps : \$(OHP).dvi
624 \$(OHP).pdf : \$(OHP).dvi
625 xdvi: \$(MAIN).xdvi
626 dvips: \$(MAIN).dvi
627 dvips \$(MAIN).dvi -o \$(MAIN).ps
628
629 \$(MAIN).dvi: 1.tex
630 \$(LATEX) \$(MAIN)
631
632 jsss.dvi: jsss.tex 1.tex
633 \$(LATEX) jsss.tex
634
635 wc:
636 \$(SED) -e '/\\\\special{/d' \$(PAPER) | delatex | wc
637 uu:
638 tar cBf - \$(MAIN).[tab]* [0-9]*.tex \$(DEPENDENCY) \\
639 title.tex abstract.tex ohp.tex \\
640 Makefile | gzip | uuencode \$(PAPER).tar.gz > uu
641
642
643 bbl: \$(MAIN).bbl
644
645 \$(MAIN).bbl: ref.bib 1.tex # \$(MAIN).aux
646 -\$(BIBTEX) \$(MAIN)
647
648 \$(MAIN).aux: \$(MAIN).tex 1.tex
649 \$(LATEX) \$(MAIN)
650
651 1.tex: \$(PAPER) \$(DEPENDENCY)
652 -o2tex \$(PAPER)
653
654 # OHP with slitex
655 \$(OHP): \$(OHP).dvi
656 \$(OHP).dvi : \$(OHP).tex \$(DEPENDOHP)
657 \$(SLITEX) \$(OHP)
658
659 ohpprint: \$(OHP).dvi
660 lpr -c \$(OHP).dvi
661 ohplw: \$(OHP).dvi
662 \$(DVI2PS) \$(R) -o landscape \$(OHP).dvi | lpr -P\$(PRINTER)
663 ohpnext: \$(OHP).dvi
664 \$(DVI2PS) -h -i /usr/lib/tex/ps/tex-j.next -o landscape \$(OHP).dvi |\\
665 lpr -Pcb
666 ohpgs: \$(OHP).gs
667
668 cover: \$(COVER).dvi
669 \$(COVER): \$(COVER).dvi
670 \$(COVER).dvi : \$(PAPER)
671 coverprint: \$(COVER).print
672 coverlw: \$(COVER).lw
673 covernext: \$(COVER).next
674 covergs: \$(COVER).gs
675
676 clean:
677 -rm -f \$(MAIN).ps *.dvi *.log *.blg \\
678 *~ \\#* ?.tex *.toc *.lof *.lot xfig/*.tex
679
680 tgrindfig.tex:
681 ln -s "\$\$HOME"/paper/tgrindfig.tex .
682 # for MSDOS
683 tgrindfi.tex:
684 ln -s "\$\$HOME"/paper/tgrindfig.tex tgrindfi.tex
685 ref.bib:
686 ln -s "\$\$HOME"/paper/ref.bib .
687
688 RogueRogue
689 close fh;
690 }
691 if ( ! -f "main.tex") {
692 rename('00.tex','main.tex');
693 }
694 if ( ! -f "jsss.tex") {
695 rename('jsss00.tex','jsss.tex');
696 }
697 if ( ! -f "ohp.tex") {
698 rename('ohp00.tex','ohp.tex');
699 }
700 # make depend > /dev/null
701
702 rename("Makefile","Makefile.old");
703 open(MAKE, "<Makefile.old");
704 open(fh,">Makefile");
705 select(fh);
706 print "DEPENDENCY = @depend\n";
707 print "DEPENDOHP = @ohpdepend\n";
708 while(<MAKE>) {
709 next if(/^DEPEND/);
710 chop; print;
711 }
712 close(fh);
713
714 # end