1 |
wakaba |
1.1 |
#!/usr/bin/perl |
2 |
|
|
use strict; |
3 |
|
|
use Encode; |
4 |
wakaba |
1.2 |
my $opt = {}; |
5 |
wakaba |
1.1 |
sub c{ |
6 |
|
|
$_ = shift; |
7 |
wakaba |
1.2 |
s/\\preprocess{([^{}=\s]+)(?:\s*=\s*([^{}=\s]*))?}/$opt->{$1}=defined$2?$2:1;''/ge; |
8 |
wakaba |
1.1 |
s/\x{3001}/, /g; |
9 |
|
|
s/\x{3002}/. /g; |
10 |
wakaba |
1.2 |
s/\$/\\\$/g if $opt->{'Perl-mode'}; |
11 |
wakaba |
1.1 |
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 |
wakaba |
1.2 |
# $Date: 2004/06/13 03:53:35 $ |