/[suikacvs]/markup/2004/tex/pretex.pl
Suika

Contents of /markup/2004/tex/pretex.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Sat Jul 31 07:39:00 2004 UTC (20 years, 3 months ago) by wakaba
Branch: MAIN
Changes since 1.1: +4 -1 lines
File MIME type: text/plain
Preprocessor instruction implemented

1 #!/usr/bin/perl
2 use strict;
3 use Encode;
4 my $opt = {};
5 sub c{
6 $_ = shift;
7 s/\\preprocess{([^{}=\s]+)(?:\s*=\s*([^{}=\s]*))?}/$opt->{$1}=defined$2?$2:1;''/ge;
8 s/\x{3001}/, /g;
9 s/\x{3002}/. /g;
10 s/\$/\\\$/g if $opt->{'Perl-mode'};
11 s{\\sourcecode\s*(?:\[([^\[\]]*)\]\s*)?{([^{}]+)}}{
12 my %opt = map {$_->[1] = 1 unless defined $_->[1]; @$_}
13 map {[split /\s*=\s*/, $_, 2]} split /\s*,\s*/, $1;
14 my $filename = $2;
15 open my $file, '<', $filename or die "$0: $filename: $!";
16 my $source = '';
17 my $line = 1;
18 for (<$file>) {
19 s/\t/ /g and warn "$0: $filename\[$line]: TAB found";
20 $source .= sprintf '%3d %s', $line++, $_;
21 }
22 $opt{size} ||= 'tiny';
23 "% $&\n\\begin{$opt{size}}\\begin{verbatim}\n$source\n\\end{verbatim}\\end{$opt{size}}\n";
24 }ge;
25 $_;
26 }
27 while(<>){
28 print encode(q<iso-2022-jp>,c(decode(q<iso-2022-jp>,$_)))
29 }
30
31
32 =head1 NAME
33
34 pretex.pl - Preprocessor for Japanese LaTeX document
35
36 =head1 SYNOPSIS
37
38 $ perl pretex.pl a.pretex > a.tex
39
40 =head1 DESCRIPTION
41
42 This script preprocesses LaTeX document. This script is
43 written to satisfy author's need only.
44
45 =head1 FEATURES
46
47 =over 4
48
49 =item Replacement of COMMA and FULL STOP
50
51 In science community, use of COMMA and FULL STOP, rather than
52 IDEOGRAPHIC COMMA and IDEOGRAPHIC FULL STOP, is often encouraged.
53 This filter script substitutes IDEOGRAPHIC COMMA and IDEOGRAPHIC FULL STOP
54 to COMMA and FULL STOP, followed by a SPACE.
55
56 =item Command C<\sourcecode{filename}>
57
58 This filter script puts content of external plain text file
59 as C<verbatim> block, in place <\sourcecode> pseudo-command happens.
60
61 =back
62
63 Note that input document must be written in ISO-2022-JP.
64
65 =head1 AUTHOR
66
67 Wakaba <w@suika.fam.cx>
68
69 =head1 LICENSE
70
71 Copyright 2004 Wakaba <w@suika.fam.cx>
72
73 This program is free software; you can redistribute it and/or
74 modify it under the same terms as Perl itself.
75
76 =cut
77
78 # $Date: 2004/06/13 03:53:35 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24