1 |
# |
2 |
# -*- Perl -*- |
3 |
# $Id: tex.pl,v 1.7 2000/03/15 06:53:50 satoru Exp $ |
4 |
# Copyright (C) 1999 Satoru Takabayashi , |
5 |
# This is free software with ABSOLUTELY NO WARRANTY. |
6 |
# |
7 |
# This program is free software; you can redistribute it and/or modify |
8 |
# it under the terms of the GNU General Public License as published by |
9 |
# the Free Software Foundation; either versions 2, or (at your option) |
10 |
# any later version. |
11 |
# |
12 |
# This program is distributed in the hope that it will be useful |
13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
# GNU General Public License for more details. |
16 |
# |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with this program; if not, write to the Free Software |
19 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
20 |
# 02111-1307, USA |
21 |
# |
22 |
# This file must be encoded in EUC-JP encoding |
23 |
# |
24 |
|
25 |
package tex; |
26 |
use strict; |
27 |
require 'util.pl'; |
28 |
require 'gfilter.pl'; |
29 |
|
30 |
my $texconvpath = undef; |
31 |
|
32 |
sub mediatype() { |
33 |
return ('application/x-tex'); |
34 |
} |
35 |
|
36 |
sub status() { |
37 |
$texconvpath = util::checkcmd('detex'); |
38 |
return 'yes' if (defined $texconvpath); |
39 |
return 'no'; |
40 |
} |
41 |
|
42 |
sub recursive() { |
43 |
return 0; |
44 |
} |
45 |
|
46 |
sub pre_codeconv() { |
47 |
return 1; |
48 |
} |
49 |
|
50 |
sub post_codeconv () { |
51 |
return 0; |
52 |
} |
53 |
|
54 |
sub add_magic ($) { |
55 |
my ($magic) = @_; |
56 |
|
57 |
$magic->addSpecials("application/x-tex", |
58 |
"^\\\\document(style|class)", |
59 |
"^\\\\begin\\{document\\}", |
60 |
"^\\\\section\\{[^}]+\\}"); |
61 |
$magic->addFileExts('\\.tex$', 'application/x-tex'); |
62 |
return; |
63 |
} |
64 |
|
65 |
sub filter ($$$$$) { |
66 |
my ($orig_cfile, $cont, $weighted_str, $headings, $fields) |
67 |
= @_; |
68 |
my $cfile = defined $orig_cfile ? $$orig_cfile : ''; |
69 |
|
70 |
if ($$cont =~ m/\\title\{(.*?)\}/s) { |
71 |
$fields->{'title'} = $1; |
72 |
$fields->{'title'} =~ s/\\\\/ /g; |
73 |
} |
74 |
if ($$cont =~ m/\\author\{(.*?)\}/s) { |
75 |
$fields->{'author'} = $1; |
76 |
$fields->{'author'} =~ s/\\\\/ /g; |
77 |
} |
78 |
if ($$cont =~ m/\\begin\{abstract\}(.*?)\\end\{abstract\}/s) { |
79 |
$fields->{'summary'} = $1; |
80 |
$fields->{'summary'} =~ s/\\\\/ /g; |
81 |
} |
82 |
|
83 |
my $tmpfile = util::tmpnam('NMZ.tex'); |
84 |
util::vprint("Processing tex file ... (using '$texconvpath')\n"); |
85 |
|
86 |
{ |
87 |
my $fh = util::efopen("| $texconvpath > $tmpfile"); |
88 |
print $fh $$cont; |
89 |
} |
90 |
|
91 |
{ |
92 |
my $fh = util::efopen("< $tmpfile"); |
93 |
$$cont = util::readfile($fh); |
94 |
} |
95 |
|
96 |
gfilter::line_adjust_filter($cont); |
97 |
gfilter::line_adjust_filter($weighted_str); |
98 |
gfilter::white_space_adjust_filter($cont); |
99 |
$fields->{'title'} = gfilter::filename_to_title($cfile, $weighted_str) |
100 |
unless $fields->{'title'}; |
101 |
gfilter::show_filter_debug_info($cont, $weighted_str, |
102 |
$fields, $headings); |
103 |
return undef; |
104 |
} |
105 |
|
106 |
1; |