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