blib/lib/LaTeX/Authors.pm

filter: Statementstmt 5.7% 15 / 259 Branchbran 0.0% 0 / 118 Conditioncond 0.0% 0 / 45 MC/DCmcdc 0.0% 0 / 26 Subroutinesub 27.7% 5 / 18 Podpod n/a totaltotal 4.2% 20 / 466 CC 100 SCAR 68.6
CC
100
Cov
4%
router
2162.0
un_archive
362.9
find_tex_file
272.0
CRAP 956.8
↑ Summary
1 ######################################################################
2 #
3 # LaTeX::Authors
4 #
5 ######################################################################
6 #
7 # LaTeX::Authors 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 version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # LaTeX::Authors 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 ParaTools; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #
21 #######################################################################
22 #
23 # LaTeX::Authors try to find the authors and laboratories in a LaTeX file
24 # and return the information with xml tags.
25 #
26 # Author: Christian Rossi
27 # CCSD/CNRS (rossi@in2p3.fr) and LORIA/INRIA Lorraine (rossi@loria.fr)
28 #
29 # Based on latex.pm by José João Almeida (jj@di.uminho.py)
30 # http://natura.di.uminho.pt/~jj/perl/
31 #
32 # 2003/03/10 : version 0.8
33 # 2005/03/29 : version 0.81 (correct documentation Latex to LaTeX)
34 #
35 ########################################################################
36  
37  
38 package LaTeX::Authors;
39  
40 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
43 1 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 our @ISA = qw(Exporter);
46  
47 our @EXPORT = qw(&un_archive &find_tex_file &load_file_string &router
48 &string_byauthors_xml &string_byauthors_html &author_to_lab
49 &string_bylabs_html &string_bylabs_xml &string_onlyauthors_xml &string_onlylabs_xml);
50  
51 1 ▶use Text::Balanced qw (extract_bracketed);
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 our $VERSION = '0.81';
54  
55 =pod
56  
57 =head1 NAME
58  
59 LaTeX::Authors - Perl extension to extract authors and laboratories in a LaTeX file
60  
61 =head1 SYNOPSIS
62
63  
64 Extraction from a string with latex commands:
65
66 use LaTeX::Authors;
67 use strict;
68 my $tex_string = "\documentclass...";
69 my @article = router($tex_string);
70 my $string_xml = string_byauthors_xml(@article);
71 print $string_xml;
72
73
74 Extraction from a latex file:
75  
76 use LaTeX::Authors;
77 use strict;
78 my $file = shift;
79 my $tex_string = load_file_string($file);
80 my @article = router($tex_string);
81 my $string_xml = string_byauthors_xml(@article);
82 print $string_xml;
83
84
85 Extraction from a directory with latex files:
86
87 use LaTeX::Authors;
88 use strict;
89 my $directory = shift;
90 #my $error= un_archive($directory);
91 my $file = find_tex_file($directory);
92 my $tex_string = load_file_string($file);
93 my @article = router($tex_string);
94 my $string_xml = string_byauthors_xml(@article);
95 print $string_xml;
96  
97
98 =head1 DESCRIPTION
99
100 LaTeX::Authors try to find the authors and laboratories in a LaTex file.
101 The output is an xml or html string. This is an example of the xml output:
102
103 <article>
104 <item>
105 <author>author1</author>
106 <labo>lab1</labo>
107 <labo>lab2</labo>
108 </item>
109 <item>
110 ...
111 </item>
112 </article>
113  
114 The module try to found something like the \author and \affiliation latex command on the file.
115 With articles about physics try to found a collaboration name to work with more exotic way to show authors list.
116 It is especially design for article about physics where there is hundreds of authors.
117  
118 It can work on input with:
119 - an archiv file (tar, zip...), it's useful for arXiv file (function un_archiv)
120 - a directory with latex file (function find_tex_file)
121 - a latex file (function load_file_string)
122 - a string (function router)
123  
124 For the output it can produce:
125 - an xml string
126 - by author: author1 lab1 lab2 (string _byauthors_xml)
127 - by laboratory: lab1 author1 author2 (string_bylabs_xml)
128 - an html string
129 - by author (string_byauthors_html)
130 - by lab (string_bylabs_html)
131
132
133 =cut
134  
135 ###################################################
136  
137 =head1 FUNCTION
138  
139 =head2 C<un_archive> - uncompress, untar or unzip file in a directory
140  
141 Take the archive file and uncompress (useful for arXiv files)
142
143 my $error = un_archive($directory);
144
145 =cut
146  
147
148 sub un_archive
149 0 ▶{
Subroutine un_archive: not called CC=20 SCAR=58.9
150 0 my ($directory) = @_;
151 0 my $filename;
152 my @listfile;
153 0 my $error ="";
154
155 0 ▶ if (!(chdir($directory))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (chdir $directory) 0 0 0
156 0 $error = "dir";
157 0 return $error;
158 }
159  
160 0 ▶ @listfile = <*.uu>;
Subroutine BEGIN: called CC=1 SCAR=0.2
161 0 foreach $filename (@listfile) {
162 0 my $code = system("/bin/csh $filename >/dev/null 2>&1");
163 0 ▶ $error = "uu " if ($code);
Branch: 1 branch
BranchTrueFalseTotal
if $code 0 0 0
164 }
165 0 foreach $filename (@listfile) {
166 0 unlink($filename);
167 }
168  
169 0 @listfile = <*.tar.gz>;
170 0 foreach $filename (@listfile) {
171 0 my $code = system("gzip -cd $filename | tar x >/dev/null 2>&1");
172 0 ▶ $error .= "tar.gz " if ($code);
Branch: 1 branch
BranchTrueFalseTotal
if $code 0 0 0
173 }
174 0 foreach $filename (@listfile) {
175 0 unlink($filename);
176 }
177  
178 0 @listfile = <*.tgz>;
179 0 foreach $filename (@listfile) {
180 0 my $code = system("gzip -cd $filename | tar x >/dev/null 2>&1");
181 0 ▶ $error .= "tgz " if ($code);
Branch: 1 branch
BranchTrueFalseTotal
if $code 0 0 0
182 }
183 0 foreach $filename (@listfile) {
184 0 unlink($filename);
185 }
186  
187 0 @listfile = <*.tar>;
188 0 foreach $filename (@listfile) {
189 0 my $code = system("tar xf $filename >/dev/null 2>&1");
190 0 ▶ $error .= "tar " if ($code);
Branch: 1 branch
BranchTrueFalseTotal
if $code 0 0 0
191 }
192 0 foreach $filename (@listfile) {
193 0 unlink($filename) ;
194 }
195  
196 0 @listfile = <*.gz>;
197 0 foreach $filename (@listfile) {
198 0 my $code = system("gzip -d $filename");
199 0 ▶ $error .= "gz " if ($code);
Branch: 1 branch
BranchTrueFalseTotal
if $code 0 0 0
200 }
201 0 foreach $filename (@listfile) {
202 0 unlink($filename) ;
203 }
204  
205 0 @listfile = <*.zip>;
206 0 foreach $filename (@listfile) {
207 0 my $code = system("unzip $filename");
208 0 ▶ $error .= "zip " if ($code);
Branch: 1 branch
BranchTrueFalseTotal
if $code 0 0 0
209 }
210 0 foreach $filename (@listfile) {
211 0 unlink($filename);
212 }
213  
214 0 return $error;
215 }
216  
217  
218 ###################################################
219  
220  
221 =head2 C<find_tex_file> - Try to find the main tex file on a directory with multiple files
222  
223 my $texfile = find_tex_file($directory);
224  
225 =cut
226
227 sub find_tex_file
228 0 ▶{
Subroutine find_tex_file: not called CC=16 SCAR=56.1
229 0 my $directory = $_[0];
230  
231 0 ▶ if ($directory eq "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($directory eq "") 0 0 0
232 # Error: No working directory.
233 0 return "";
234 }
235 0 ▶ if (!(-d $directory)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $directory) 0 0 0
236 # Error: Working directory doesn't exist.
237 0 return "";
238 }
239  
240 0 ▶ if (!(chdir($directory))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (chdir $directory) 0 0 0
241 # Error: Can't cd to source directory.
242 0 return "";
243 }
244  
245 0 my @list_file_dir = <*.tex>;
246 0 my @list_file_sdir = <*/*.tex>;
247 0 my @list_file = (@list_file_dir,@list_file_sdir);
248 0 my $nbr_file = @list_file;
249
250 0 my $tex_file;
251
252 0 ▶ if ($nbr_file == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($nbr_file == 1) { } 0 0 0
elsif ($nbr_file > 1) { } 0 0 0
253 0 $tex_file = $list_file[0];
254 } elsif ($nbr_file > 1) {
255 0 foreach (@list_file) {
256 0 open(FILEGREP,"$_");
257 0 my $tempo_file = $_;
258 0 ▶ while (<FILEGREP>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline FILEGREP)) 0 0 0
259 0 s/(^\s*|[^\\])%.*/$1/g;
260 0 s/^\s*\n$//g;
261 0 ▶ if ((/\\begin\{document\}/) || (/\\bye/) || (/\\documentstyle/) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\\begin\{document\}/ or /\\bye/ or /\\documentstyle/) 0 0 0
Condition0%0/6
/\\begin\{document\}/ or /\\bye/ or /\\documentstyle/
l!l&&r!l&&!r
000
/\\begin\{document\}/ or /\\bye/
l!l&&r!l&&!r
000
MC/DC0%0/3
/\\begin\{document\}/ or /\\bye/ or /\\documentstyle/
/\\begin\{document\}/ /\\bye/ /\\documentstyle/
Truth table0%0/4
A or B or C
A= /\\begin\{document\}/B= /\\bye/C= /\\documentstyle/
ABCresult
1XX1
01X1
0011
0000
262 0 $tex_file = $tempo_file;
263 0 last;
264 }
265 }
266  
267 }
268 } else {
269
270 0 my @list_file_dir = <*>;
271 0 my @list_file_sdir = <*/*>;
272 0 my @list_file = (@list_file_dir,@list_file_sdir);
273
274 0 foreach (@list_file) {
275 0 open(FILEGREP,"$_");
276 0 my $tempo_file = $_;
277
278 0 ▶ while (<FILEGREP>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline FILEGREP)) 0 0 0
279 0 s/(^\s*|[^\\])%.*/$1/g;
280 0 s/^\s*\n$//g;
281
282 0 ▶ if ((/\\begin\{document\}/) || (/\\bye/) || (/\\documentstyle/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\\begin\{document\}/ or /\\bye/ or /\\documentstyle/) 0 0 0
Condition0%0/6
/\\begin\{document\}/ or /\\bye/ or /\\documentstyle/
l!l&&r!l&&!r
000
/\\begin\{document\}/ or /\\bye/
l!l&&r!l&&!r
000
MC/DC0%0/3
/\\begin\{document\}/ or /\\bye/ or /\\documentstyle/
/\\begin\{document\}/ /\\bye/ /\\documentstyle/
Truth table0%0/4
A or B or C
A= /\\begin\{document\}/B= /\\bye/C= /\\documentstyle/
ABCresult
1XX1
01X1
0011
0000
283 0 $tex_file = $tempo_file;
284 0 last;
285 }
286 }
287 }
288 }
289  
290 0 return $tex_file;
291  
292 }
293  
294  
295 ###################################################
296  
297  
298 =head2 C<load_file_string> - Load a file and put the content to a string
299  
300 my $string = load_file_string($file);
301  
302 Also delete the latex comments (%...).
303  
304 =cut
305  
306 sub load_file_string
307 0 ▶{
Subroutine load_file_string: not called CC=3 SCAR=24.8
308 0 my $file = $_[0];
309 0 my $string;
310 0 ▶ open(TEXFILE,$file) or die "Error: can't open $file\n";
Branch: 1 branch
BranchTrueFalseTotal
open TEXFILE, $file or die "Error: can't open $file\n" 0 0 0
311 0 ▶ while (<TEXFILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline TEXFILE)) 0 0 0
312 0 s/(^\s*|[^\\])%.*/$1/g;
313 0 s/^\s*\n$//g;
314 0 $string .= $_;
315 }
316 0 return $string;
317 }
318  
319  
320 ###################################################
321  
322  
323 =head2 C<router> - Try to qelect the good function to extract the authors and laboratories and return an array
324 with the authors and the laboratories in the latex file.
325  
326 @article = router($string);
327  
328 =cut
329  
330 sub router
331 0 ▶ {
Subroutine router: not called CC=46 SCAR=76.8
332 0 my $string= $_[0];
333 0 my ($aut,$aff,$add,$addeq,$ins,$and,$math_in_add,$math_in_aut,$altaff,$input_file,$report_fermilab);
334 0 my ($string_aut,$string_lab);
335 0 $string_aut = ""; $string_lab= "";
336 0 my @tab_chaine = split(/\n/,$string);
337 0 my @input;my @include;
338 0 foreach (@tab_chaine) {
339 0 ▶ if (/\\author/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\\author/) 0 0 0
340 0 $aut = 1; $string_aut = "author";
341 }
342
343 0 ▶ if (/\\affiliation/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\\affiliation/) 0 0 0
344 0 $aff = 1; $string_lab = "affiliation";
345 }
346 # aastex
347 0 ▶ if (/\\affil\{/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\\affil\{/) 0 0 0
348 0 $aff = 1; $string_lab = "affil";
349 }
350 0 ▶ if (/\\address/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\\address/) 0 0 0
351 0 $add = 1 ; $string_lab = "address";
352 }
353  
354 0 ▶ if (/\\address\{(\s*(\\\w+ )+|\s*)\$\^/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\\address\{(\s*(\\\w+ )+|\s*)\$\^/) 0 0 0
355 0 $add= 1; $string_lab = "address"; $math_in_add = 1;
356 }
357 0 ▶ if (/address=/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/address=/) 0 0 0
358 0 $addeq = 1 ; $string_lab = "address";
359 }
360 0 ▶ if (/\\institute/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\\institute/) 0 0 0
361 0 $ins = 1; $string_lab = "institute";
362 }
363 0 ▶ if (/\\altaffilmark/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\\altaffilmark/) 0 0 0
364 0 $altaff = 1;
365 }
366 # na59
367 #if ((/\\input/) && ($chaine1 eq "") && ($chaine2 eq "")) {
368 0 ▶ if (/\\input/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\\input/) 0 0 0
369 0 my $sed_string = $string;
370 # delete space \input xyz -> \input{xyz}
371 0 ▶ $sed_string =~ s/\\input\s+([\.\/\w]+)/\\input\{$1\}/g if (@input == 0);
Branch: 1 branch
BranchTrueFalseTotal
if @input == 0 0 0 0
372 0 ▶ @input = greplatexcom("input",["t"],$sed_string) if (@input == 0);
Branch: 1 branch
BranchTrueFalseTotal
if @input == 0 0 0 0
373  
374 # my $input_file = $input[0]->{t}; bichop($input_file);
375 # L3 : \input toto.tex
376 # if ($input_file eq "") {
377 # space
378 # /\\input\s+(.*)/; $input_file = $1;
379 # }
380 # $input_file .= ".tex" if ((! -f $input_file) && ($input_file ne ""));
381  
382 #my $chaine_l = load_file_string($input_file);
383 #my @out = router($chaine_l);
384 #if (@out > 0) {return @out;}
385 }
386 0 ▶ if (/\\include/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\\include/) 0 0 0
387 0 ▶ @include = greplatexcom("include",["t"],$string) if (@include == 0);
Branch: 1 branch
BranchTrueFalseTotal
if @include == 0 0 0 0
388 }
389 0 ▶ if (/report.*Fermilab/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/report.*Fermilab/) 0 0 0
390 0 $report_fermilab = 1;
391 }
392 }
393  
394 0 my $coll_name = found_collaboration($string);
395  
396 0 $coll_name =~ tr/A-Z/a-z/;
397  
398 #print "aut=$aut aff=$aff add=$add addeq=$addeq ins=$ins coll = $coll_name ";
399  
400 #$coll_name ="H1";
401  
402 0 my @aut = greplatexcom("author",[["arg"],"t"],$string);
403  
404 0 ▶ if (bichop($aut[0]->{t}) =~ /\\and/) {
Branch: 1 branch
BranchTrueFalseTotal
if (bichop($aut[0]{"t"}) =~ /\\and/) 0 0 0
405 0 $and = 1;
406 }
407 0 ▶ if (bichop($aut[0]->{t}) =~ /\$\^/) {
Branch: 1 branch
BranchTrueFalseTotal
if (bichop($aut[0]{"t"}) =~ /\$\^/) 0 0 0
408 0 $math_in_aut = 1;
409 }
410  
411 #print bichop($aut[0]->{t});
412  
413 0 my @addr= greplatexcom("address",[["arg"],"t"],bichop($aut[0]->{t}));
414
415 # print "1= $addr[0]->{t} \n";
416 0 my $imbri;
417  
418 0 ▶ $imbri= 1 if ((defined $addr[0]->{t}) && ($addr[0]->{t} ne ""));
Branch: 1 branch
BranchTrueFalseTotal
if defined $addr[0]{"t"} and $addr[0]{"t"} ne "" 0 0 0
Condition0%0/3
defined $addr[0]{"t"} and $addr[0]{"t"} ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $addr[0]{"t"} and $addr[0]{"t"} ne ""
defined $addr[0]{"t"} $addr[0]{"t"} ne ""
Truth table0%0/3
A and B
A= defined $addr[0]{"t"}B= $addr[0]{"t"} ne ""
ABresult
0X0
100
111
419
420 #print "imbri = $imbri and= $and input = ". @input ." include = ". @include. "\n";
421 #print "math_in_aut = $math_in_aut math_in_add = $math_in_add <br>\n";
422  
423 0 my @doc;
424  
425 0 ▶ if (($string_aut ne "") && ($string_lab eq "") && ($coll_name ne "l3")) {
Branch: 5 branches
BranchTrueFalseTotal
if ($string_aut ne '' and $string_lab eq '' and $coll_name ne 'l3') { } 0 0 0
elsif ($string_aut ne '' and $string_lab ne '' and $coll_name ne 'zeus') { } 0 0 0
elsif ($coll_name ne '') { } 0 0 0
elsif ($report_fermilab == 1) { } 0 0 0
elsif (@input != 0 or @include != 0) { } 0 0 0
Condition0%0/6
$string_aut ne "" and $string_lab eq "" and $coll_name ne "l3"
!ll&&!rl&&r
000
$string_aut ne "" and $string_lab eq ""
!ll&&!rl&&r
000
MC/DC0%0/3
$string_aut ne "" and $string_lab eq "" and $coll_name ne "l3"
$string_aut ne "" $string_lab eq "" $coll_name ne "l3"
Truth table0%0/4
A and B and C
A= $string_aut ne ""B= $string_lab eq ""C= $coll_name ne "l3"
ABCresult
0XX0
10X0
1100
1111
426 0 ▶ if ($math_in_aut) {
Branch: 2 branches
BranchTrueFalseTotal
if ($math_in_aut) { } 0 0 0
elsif ($altaff) { } 0 0 0
427 0 @doc = grepaut_math("$string_aut",$string);
428 } elsif ($altaff) {
429 0 @doc = grep_aut_altaff($string);
430 } else {
431 0 @doc = grepaut("$string_aut",$string);
432 }
433
434 ▶ } elsif (($string_aut ne "") && ($string_lab ne "") && ($coll_name ne "zeus")) {
Condition0%0/6
$string_aut ne "" and $string_lab ne "" and $coll_name ne "zeus"
!ll&&!rl&&r
000
$string_aut ne "" and $string_lab ne ""
!ll&&!rl&&r
000
MC/DC0%0/3
$string_aut ne "" and $string_lab ne "" and $coll_name ne "zeus"
$string_aut ne "" $string_lab ne "" $coll_name ne "zeus"
Truth table0%0/4
A and B and C
A= $string_aut ne ""B= $string_lab ne ""C= $coll_name ne "zeus"
ABCresult
0XX0
10X0
1100
1111
435 0 ▶ if ($imbri == 1) {
Branch: 3 branches
BranchTrueFalseTotal
if ($imbri == 1) { } 0 0 0
elsif ($addeq == 1) { } 0 0 0
elsif ($math_in_aut == 1 and $math_in_add == 1) { } 0 0 0
436 0 @doc= grepautadd("$string_aut","$string_lab",$string);
437 } elsif ($addeq == 1) {
438 0 @doc= grepautadd_eq("$string_aut","$string_lab",$string);
439 ▶ } elsif (($math_in_aut == 1) && ($math_in_add == 1)) {
Condition0%0/3
$math_in_aut == 1 and $math_in_add == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$math_in_aut == 1 and $math_in_add == 1
$math_in_aut == 1 $math_in_add == 1
Truth table0%0/3
A and B
A= $math_in_aut == 1B= $math_in_add == 1
ABresult
0X0
100
111
440 0 @doc= grepautadd_math("$string_aut","$string_lab",$string);
441  
442 } else {
443 0 @doc= grepautaff("$string_aut","$string_lab",$string);
444 }
445 } elsif ($coll_name ne "") {
446 #my $function = "grep_article_" . $coll_name;
447 #print "$function\n";
448 0 ▶ if (@input != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@input != 0) 0 0 0
449 0 foreach my $input_t (@input) {
450 0 $input_file = $input_t->{t}; bichop($input_file);
451 # L3 : \input toto.tex
452 # if ($input_file eq "") {
453 # # space
454 # /\\input\s+(.*)/; $input_file = $1;
455 #
456 0 ▶ $input_file .= ".tex" if ((! -f $input_file) && ($input_file ne ""));
Branch: 1 branch
BranchTrueFalseTotal
if not -f $input_file and $input_file ne "" 0 0 0
Condition0%0/3
not -f $input_file and $input_file ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
not -f $input_file and $input_file ne ""
not -f $input_file $input_file ne ""
Truth table0%0/3
not(A) and B
A= not -f $input_fileB= $input_file ne ""
ABresult
0X0
100
111
457 0 my $string_input = load_file_string($input_file);
458 #print "<br>f1=$input_file ";
459 # @doc = router($string_l);
460 0 @doc = func_by_coll($string_input,$coll_name);
461 0 ▶ last if (@doc > 0);
Branch: 1 branch
BranchTrueFalseTotal
if @doc > 0 0 0 0
462 }
463
464 }
465 0 ▶ @doc = func_by_coll($string,$coll_name) if (@doc == 0);
Branch: 1 branch
BranchTrueFalseTotal
if @doc == 0 0 0 0
466 } elsif ($report_fermilab == 1) {
467 0 @doc = extract_report_fermilab($string);
468 ▶ } elsif ((@input != 0) || (@include != 0)){
Condition0%0/3
@input != 0 or @include != 0
l!l&&r!l&&!r
000
MC/DC0%0/2
@input != 0 or @include != 0
@input != 0 @include != 0
Truth table0%0/3
A or B
A= @input != 0B= @include != 0
ABresult
1X1
011
000
469 0 my @infile = (@input,@include);
470 0 foreach my $input_t (@infile) {
471 0 $input_file = $input_t->{t}; bichop($input_file);
472 # L3 : \input toto.tex
473 # if ($input_file eq "") {
474 # space
475 # /\\input\s+(.*)/; $input_file = $1;
476 # }
477 0 ▶ $input_file .= ".tex" if ((! -f $input_file) && ($input_file ne ""));
Branch: 1 branch
BranchTrueFalseTotal
if not -f $input_file and $input_file ne "" 0 0 0
Condition0%0/3
not -f $input_file and $input_file ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
not -f $input_file and $input_file ne ""
not -f $input_file $input_file ne ""
Truth table0%0/3
not(A) and B
A= not -f $input_fileB= $input_file ne ""
ABresult
0X0
100
111
478 #print "<br>f2=$input_file ";
479 0 my $string_l = load_file_string($input_file);
480 0 @doc = router($string_l);
481 0 ▶ last if (@doc > 0);
Branch: 1 branch
BranchTrueFalseTotal
if @doc > 0 0 0 0
482 }
483 }
484 0 return(@doc);
485 }
486  
487  
488 ##################################################
489 #
490 # Tools functions
491 #
492 # Useful if you want to complete the module
493 # with others author/lab pattern
494 #
495 #################################################
496  
497  
498 =head2 C<found_collaboration> - Try to found a collaboration name
499  
500 Useful for physics articles whrere there often a collaboration name. The authors list format can be found with the collaboration name. Used by the router function.
501  
502 =cut
503  
504 sub found_collaboration
505 0 ▶ {
Subroutine found_collaboration: not called CC=7 SCAR=40.3
506 0 my $string = $_[0];
507 0 my (@tex_line) = split(/\n/,$string);
508 0 foreach (@tex_line) {
509 0 ▶ last if ((/thebibliogeraphie/) || (/\\bibitem/));
Branch: 1 branch
BranchTrueFalseTotal
if /thebibliogeraphie/ or /\\bibitem/ 0 0 0
Condition0%0/3
/thebibliogeraphie/ or /\\bibitem/
l!l&&r!l&&!r
000
MC/DC0%0/2
/thebibliogeraphie/ or /\\bibitem/
/thebibliogeraphie/ /\\bibitem/
Truth table0%0/3
A or B
A= /thebibliogeraphie/B= /\\bibitem/
ABresult
1X1
011
000
510 0 /(?:\s+|{\s*)([^\s]+)\s+collaboration/i;
511 0 my $collaboration = "";
512 0 ▶ $collaboration = $1 if ((defined $1) && ($1 ne ""));
Branch: 1 branch
BranchTrueFalseTotal
if defined $1 and $1 ne "" 0 0 0
Condition0%0/3
defined $1 and $1 ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $1 and $1 ne ""
defined $1 $1 ne ""
Truth table0%0/3
A and B
A= defined $1B= $1 ne ""
ABresult
0X0
100
111
513 0 ▶ if ($collaboration ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($collaboration ne "") 0 0 0
514 # for: (name collaboration) -> return name and not (name
515 0 $collaboration =~ s/^\(//;
516 # \name\ -> name
517 0 $collaboration =~ s/\\//g;
518 0 return $collaboration;
519 }
520 }
521 }
522
523  
524 ##################################################
525  
526  
527 =head2 C<delete_comment> - Delete tex comment (%) on a string
528  
529 my $string_out = delete_comment($string_in);
530  
531 =cut
532  
533 sub delete_comment
534 0 ▶{
Subroutine delete_comment: not called CC=1 SCAR=6.9
535 0 my $string = $_[0];
536 0 $string =~ s/(^\s*|[^\\])%.*/$1/g;
537 0 $string =~ s/^\s*\n$//g;
538 0 return $string;
539 }
540  
541  
542 ##################################################
543  
544  
545 =head2 C<bichop> - Double end chop
546  
547 With
548  
549 my $string_in = bichop("{aaa}")
550  
551 in $string_in there is:
552  
553 "aaa"
554  
555 =cut
556  
557 sub bichop
558 0 ▶ {
Subroutine bichop: not called CC=1 SCAR=6.9
559 0 chop $_[0];
560 0 substr($_[0],0,1)="";
561 0 $_[0];
562 }
563  
564  
565 ##################################################
566  
567  
568 =head2 C<greplatexcom> - To get all the ocurrences of a latex command
569  
570 @l_section = greplatexcom("section",["title"],$string);
571 for $s (@l_section) {print $s->{title} };
572  
573 Optional arguments can be described with "[name]". See this example:
574  
575 @class = greplatexcom("documentclass",[["args"],"class"],$string);
576 print $class[0]->{class} ;
577  
578 With \documentclass[xyz]{abc}
579  
580 $class[0]->{args} = xyz
581 $class[0]->{class} = abc
582  
583 =cut
584  
585 sub greplatexcom
586 0 ▶ {
Subroutine greplatexcom: not called CC=5 SCAR=34.0
587 0 my ($name,$listofargnames,$string) = @_ ;
588 0 my @rf=();
589 0 my ($begin, @list) = split(/\\$name\b/,$string);
590 0 foreach (@list) {
591 0 chomp;
592 0 my %r = ();
593
594 ###STRICT
595 0 my $n;
596 ###
597 0 for $n (@$listofargnames) {
598 0 ▶ if (ref($n) eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $n eq 'ARRAY') { } 0 0 0
599 0 ($r{$n->[0]},$_) = extract_bracketed($_,"[");
600 0 ▶ delete $r{$n->[0]} unless (defined $r{$n->[0]});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r{$n->[0]} 0 0 0
601 } else {
602 0 ($r{$n},$_) = extract_bracketed($_,"{");
603 }
604 }
605 0 push(@rf,\%r);
606 }
607 0 return @rf;
608 }
609  
610  
611 ###################################################
612  
613  
614 =head2 C<theenv> - To get a latex environment contents
615  
616 $abstract_string = theenv("abstract",$string);
617  
618 C<theenv> returns the contents of the environment "abstract".
619  
620 For example if:
621  
622 $string ="\begin{abstract}
623 xyz...
624 \end{abstract}";
625  
626 after theenv in $abstract_string there is the string:
627  
628 xyz...
629  
630 =cut
631  
632 sub theenv
633 0 ▶{
Subroutine theenv: not called CC=1 SCAR=6.9
634 0 my($a,$b) = @_;
635 0 my @r = greplatexenv($a,[],$b);
636 0 return $r[0]->{'env'};
637 }
638  
639  
640 ###################################################
641  
642  
643 =head2 C<theenvs> - To get all the latex environments contents
644  
645 @array = theenvs("sloppypar",$string);
646  
647 C<theenvs> returns the contents of all the environment "sloopypar".
648  
649 =cut
650  
651 sub theenvs
652 0 ▶{
Subroutine theenvs: not called CC=2 SCAR=17.9
653 0 my($a,$b)= @_;
654 0 my @string;
655 0 my @r=greplatexenv($a,[],$b);
656 0 foreach my $env (@r) {
657 # $r[0]->{'env'};
658 0 push(@string,$env->{'env'});
659 }
660 0 return(@string);
661 }
662  
663  
664 ###################################################
665  
666  
667 =head2 C<greplatexenv> - To get all ocurrences of a latex environment
668  
669 @a = greplatexenv("letter",["to"],$string) ;
670  
671 C<greplatexenv> returns a list of all the ocurrences of environment "letter",
672 reading its first argument to the "to" field and saving its content in the
673 "env" field;
674  
675 =cut
676  
677 sub greplatexenv
678 0 ▶{
Subroutine greplatexenv: not called CC=6 SCAR=37.4
679 0 my ($name,$listofargnames,$string) = @_ ;
680 0 my @rf=();
681 0 my ($begin, @list) = split(/\\begin{$name}/,$string);
682 0 foreach (@list) {
683 0 chomp;
684 0 ▶ if (/\\end{$name}/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\\end{$name}/) { } 0 0 0
685 0 $_=$`;
686 } else {
687 0 next;
688 }
689 0 my %r = ();
690 ###STRICT
691 0 my $n;
692 ###
693 0 for $n (@$listofargnames) {
694 0 ▶ if (ref($n) eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $n eq 'ARRAY') { } 0 0 0
695 0 ($r{$n->[0]},$_) = extract_bracketed($_,"[");
696 0 ▶ delete $r{$n->[0]} unless (defined $r{$n->[0]});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r{$n->[0]} 0 0 0
697 } else {
698 0 ($r{$n},$_) = extract_bracketed($_,"{");
699 }
700 }
701 0 $r{'env'} = $_;
702 0 push(@rf,\%r);
703 }
704 0 return @rf;
705 }
706  
707  
708 ###################################################
709  
710  
711 =head2 C<newcommand> - Return a hash with all the "newcommand" occurrences
712  
713 %listnewcom = newcommand($string);
714  
715 If you have
716  
717 $string="\newcommand[xyz]{abc}";
718  
719 so after newcommand:
720  
721 $listnewcom{xyz} = "abc";
722  
723 =cut
724
725 sub newcommand
726 0 ▶{
Subroutine newcommand: not called CC=2 SCAR=17.9
727 0 my $string = $_[0];
728 0 my %listnewcom;
729 0 my @newcom= greplatexcom("newcommand",["args","val"],$string);
730  
731 0 for my $s (@newcom) {
732 0 $s->{args} = bichop($s->{args});
733 0 $listnewcom{$s->{args}} = bichop($s->{val});
734 }
735 0 return %listnewcom;
736 }
737  
738  
739 ###################################################
740  
741  
742 =head2 C<list_index> - Return a hash with all the command occurences
743  
744 For example with:
745  
746 my $command_name = "command";
747 %list = list_index($command_name,$string);
748  
749 \command[index]{xyz...} -> $list{index} = "xyz...";
750  
751 Generalize the function newcommand with any command.
752  
753 =cut
754  
755 sub list_index
756 0 ▶ {
Subroutine list_index: not called CC=2 SCAR=17.9
757 0 my ($command,$string) = @_;
758 0 my %listnewcom;
759  
760 0 my @newcom = greplatexcom($command,[["args"],"val"],$string);
761  
762 0 for my $s (@newcom) {
763  
764 0 $s->{args} = bichop($s->{args});
765  
766 0 $s->{args} =~ s/^\s*//g;
767 0 $s->{args} =~ s/\s*$//g;
768
769 0 $s->{val} =~ s/^\s*//g;
770 0 $s->{val} =~ s/\s*$//g;
771
772 0 $listnewcom{$s->{args}} = bichop($s->{val});
773 }
774 0 return %listnewcom;
775 }
776
777  
778 ###################################################
779  
780  
781 =head2 C<accent> - Transform the latex caracters with accent to standard caracters
782  
783 my $string_out = accent($string_in);
784
785 =cut
786  
787 sub accent
788 {
789 ($_) = @_;
790  
791 s/{\\`a}/à/g;
792 s/{\\'a}/á/g;
793 s/{\\^a}/â/g ;
794 s/{\\"a}/ä/g;
795 s/{\\\*a}/å/g;
796 s/{\\ae}/æ/g;
797  
798 s/{\\`A}/À/g;
799 s/{\\'A}/Á/g;
800 s/{\\"A}/Ä/g;
801 s/{\\\*A}/Å/g;
802 s/{\\~A}/Ã/g;
803 s/{\\AE}/Æ/g;
804  
805 s/\\`{\\?a}/à/g ;
806 s/\\'{\\?a}/á/g ;
807 s/\\^{\\?a}/â/g ;
808 s/\\"{\\?a}/ä/g ;
809 s/\\\*{\\?a}/å/g ;
810 s/\\{ae}/æ/g ;
811  
812 s/\\`a/à/g ;
813 s/\\'a/á/g ;
814 s/\\^a/â/g ;
815 s/\\"a/ä/g ;
816 s/\\\*a/å/g ;
817 s/\\ae/æ/g ;
818 s/\\~a/ã/g ;
819  
820 s/\\`A/À/g ;
821 s/\\'A/Á/g ;
822 s/\\"A/Ä/g ;
823 s/\\\*A/Å/g ;
824 s/\\~A/Ã/g;
825 s/\\AE/Æ/g;
826  
827 s/\\c{c}/ç/g ;
828 s/\\c{C}/Ç/g ;
829  
830 # s/{\\,c}/ç/g ;
831 # s/{\\,C}/Ç/g ;
832 # s/\\,c/ç/g ;
833 # s/\\,C/Ç/g ;
834  
835 s/{\\'e}/é/g ;
836 s/{\\`e}/è/g ;
837 s/{\\^e}/ê/g ;
838 s/{\\"e}/ë/g ;
839  
840 s/\\'e/é/g ;
841 s/\\`e/è/g ;
842 s/\\^e/ê/g ;
843  
844 s/\\'{\\?e}/é/g ;
845 s/\\`{\\?e}/è/g ;
846 s/\\"{\\?e}/ë/g ;
847
848 s/{\\'E}/É/g ;
849 s/{\\"E}/Ë/g ;
850  
851 s/\\'E/É/g ;
852 s/\\"E/Ë/g ;
853  
854 s/{\\^i}/î/g ;
855 s/{\\'i}/í/g ;
856 s/{\\"I}/Ï/g ;
857 s/{\\'I}/Í/g ;
858  
859 s/\\'\\?i ?/í/g ;
860 s/{?\\'{\\?i}}?/í/g ;
861  
862 s/\\^i/î/g ;
863 s/\\"I/Ï/g ;
864 s/\\'I/Í/g ;
865  
866 s/{\\'O}/Ó/g;
867  
868 s/{\\"O}/Ö/g;
869 s/\\"{O}/Ö/g;
870
871 s/{\\'o}/ó/g;
872 s/{\\^o}/ô/g ;
873 s/{\\"o}/ö/g ;
874 s/{\\`o}/ò/g ;
875 s/{\\~o}/õ/g ;
876  
877 s/\\^o/ô/g ;
878 s/\\"o/ö/g ;
879 s/\\`o/ò/g ;
880 s/\\~o/õ/g ;
881  
882 s/\\'o/ó/g;
883 s/\\'O/Ó/g;
884 s/\\"O/Ö/g;
885
886 s/\\`{\\?o}/ò/g ;
887  
888 s/{\\~n}/ñ/g ;
889
890 s/\\~n/ñ/g ;
891  
892 s/{\\`u}/ù/g ;
893 s/{\\^u}/û/g ;
894 s/{\\^u}/û/g ;
895 s/{\\"u}/ü/g ;
896  
897 s/\\`u/ù/g ;
898 s/\\^u/û/g ;
899 s/\\^u/û/g ;
900 s/\\"u/ü/g ;
901
902 s/\\"{\\?u}/ü/g ;
903  
904 s/{\\'y}/ý/g ;
905 s/{\\'Y}/Ý/g ;
906
907 s/\\'y/ý/g ;
908 s/\\'Y/Ý/g;
909
910 s/\\.{I}/&#304;/g;
911 s/\\c{S}/&#350;/g;
912 s/\\c{s}/&#351;/g;
913 s/\\v{c}/&#269;/g;
914
915 s/\\'c/&#263;/g;
916 s/\\'C/&#262;/g;
917
918 s/\\v c/&#269;/g;
919
920 s/\\v{C}/&#268;/g;
921 s/\\v{S}/&#352;/g;
922 s/\\v{s}/&#353;/g;
923 s/\\v{Z}/&#381;/g;
924 s/\\v Z/&#381;/g;
925
926 s/\\v{z}/&#382;/g;
927 s/\\v z/&#382;/g;
928
929 s/\\.Z/&#x17b;/g;
930 s/\\.z/&#x17c;/g;
931
932 s/\\'{N}/&#x143;/g;
933
934 s/\\L /&#x141;/g;
935 s/\\l /&#x142;/g;
936 s/{\\l}/&#x142;/g;
937
938 s/\\'{N}/&#x143;/g;
939 s/\\'{n}/&#x144;/g;
940
941 s/\\'N/&#x144;/g;
942 s/\\'n/&#x144;/g;
943
944 s/{\\ss}/ß/g;
945  
946 # delete tex command
947 # \{\xyz text\} -> text
948 s/\{\\\w+ ([^\}]*)\}/$1/g;
949  
950 # \xyz{text} -> ""
951 s/\\\w+\{[^\}]+\}//g;
952
953 # \xyz text -> text
954 s/\\\w+ / /g;
955
956 # space and ,
957 s/[\n\t\s]+/ /g;
958 s/^\s*//g;
959 s/\s*$//g;
960  
961 s/~/ /g ;
962 s/\\\\/,/g ;
963  
964 s/\\ / /g ;
965  
966 s/on leave from//g;
967 s/Also with //g;
968 s/Also at //g;
969 # ,, -> ,
970 s/,+/,/g ;
971  
972 # , , -> ,
973 s/,\s*,/,/g ;
974
975 s/^, and / /g;
976 s/^,\s*//g;
977 s/^and\s//g;
978
979 # IN^2P^3 -> IN2P3
980 s/IN\$\^\{2\}\$P\$\^\{3\}\$/IN2P3/g;
981  
982 s/\\&/and/g;
983
984 # s/[\n\t\s]+/ /g;
985  
986 # , at the begin and at the end
987 s/^\s*,\s*//g;
988 s/\s*,\s*$//g;
989  
990 # space begin end
991 s/^\s*//g;
992 s/\s*$//g;
993  
994 return $_;
995  
996 }
997
998  
999 ######################################################################
1000 #
1001 # output function
1002 #
1003 #####################################################################
1004  
1005  
1006 =head2 C<string_byauthors_xml> - Retrun a string with xml tags all the authors and lab found in an article
1007
1008 my $string = string_byauthors_xml(@article);
1009  
1010 <article>
1011 <item>
1012 <author>author1</author>
1013 <labo>lab1</labo>
1014 <labo>lab2</labo>
1015 </item>
1016 <item>
1017 ...
1018 </item>
1019 </article>
1020  
1021 =cut
1022  
1023 ##
1024 #
1025 # @article in an array with ($ref_item1, $ref_item2,...)
1026 #
1027 # @$item is an array with (author, lab1, lab2,...)
1028 #
1029 ##
1030  
1031 sub string_byauthors_xml
1032 {
1033 my (@article) = @_;
1034 my $string;
1035 $string = "<article>\n" if (@article > 0);
1036 foreach my $item (@article) {
1037 $string .= " <item>\n";
1038 my ($author,@labo) = @$item;
1039 $string .= " <author>" . accent($author) . "</author>\n";
1040 foreach my $lab (@labo) {
1041 $string .= " <labo>" . accent($lab) . "</labo>\n";
1042 }
1043 $string .= " </item>\n";
1044 }
1045 $string .= "</article>\n" if (@article > 0);
1046 return $string;
1047 }
1048  
1049 #######################################################################
1050  
1051 =head2 C<string_onlyauthors_xml> - Retrun a string with xml tags all the authors found in an article
1052
1053 my $string = string_onlyauthors_xml(@article);
1054
1055 <article>
1056 <author>author1</author>
1057 <author>author2</author>
1058 ...
1059 </article>
1060  
1061 =cut
1062  
1063 sub string_onlyauthors_xml
1064 {
1065 my (@article) = @_;
1066 my $string;
1067 $string = "<article>\n" if (@article > 0);
1068 foreach my $item (@article) {
1069 my ($author,@labo) = @$item;
1070 $string .= " <author>" . accent($author) . "</author>\n";
1071 }
1072 $string .= "</article>\n" if (@article > 0);
1073 return $string;
1074 }
1075  
1076  
1077 #######################################################################
1078  
1079  
1080 =head2 C<author_to_lab> - Convert the author array to a lab array
1081  
1082 my @array_lab = author_to_lab(@array_author);
1083  
1084 (author1, lab1, lab2)(author2, lab1, lab3) -> (lab1,author1,author2)(lab2,author1)(lab3,author2)
1085
1086 =cut
1087  
1088 sub author_to_lab
1089 {
1090 my (@article) = @_;
1091 my %author;
1092 my @article_lab;
1093  
1094 foreach my $item (@article) {
1095 my ($author,@labo) = @$item;
1096 foreach my $lab (@labo) {
1097 my @lab_authors;
1098 # for the sort
1099 $lab = accent($lab);
1100 @lab_authors = @{$author{$lab}} if defined($author{$lab});
1101 push( @lab_authors,$author);
1102 $author{$lab} = \@lab_authors;
1103 }
1104 }
1105 foreach my $lab (sort keys %author) {
1106 unshift(@{$author{$lab}}, $lab);
1107 push( @article_lab, $author{$lab});
1108 }
1109 return @article_lab;
1110 }
1111  
1112  
1113 ############################################################
1114  
1115  
1116 =head2 C<string_bylabs_xml> - Return a string with xml tags all the lab and authors found in an article
1117
1118 my $xml_string = string_bylabs_xml(@article);
1119  
1120 <article>
1121 <item>
1122 <labo>lab1</labo>
1123 <author>authors1</author>
1124 <author>authors2</author>
1125 </item>
1126 <item>
1127 ...
1128 </item>
1129 </article>
1130  
1131 =cut
1132  
1133 ##
1134 #
1135 # @article in an array with ($ref_item1, $ref_item2,...)
1136 #
1137 # @$item is an array with (lab1, author1, author2,...)
1138 #
1139 ##
1140  
1141 sub string_bylabs_xml
1142 {
1143 my (@article) = @_;
1144 my $string;
1145 my @article_bylab = author_to_lab(@article);
1146 $string = "<article>\n" if (@article > 0);
1147 foreach my $item (@article_bylab) {
1148 $string .= " <item>\n";
1149 my ($lab,@authors) = @$item;
1150 $string .= " <labo>" . accent($lab) . "</labo>\n";
1151 foreach my $author (@authors) {
1152 $string .= " <author>" . accent($author) . "</author>\n";
1153 }
1154 $string .= " </item>\n";
1155 }
1156 $string .= "</article>\n" if (@article > 0);
1157 return $string;
1158 }
1159  
1160  
1161 ############################################################
1162  
1163  
1164 =head2 C<string_onlylabs_xml> - Return a string with xml tags all the lab found in an article
1165
1166 my $string = string_onlylabs_xml(@article);
1167  
1168 <article>
1169 <labo>lab1</labo>
1170 <labo>lab2</labo>
1171 ...
1172 </article>
1173  
1174 =cut
1175  
1176 sub string_onlylabs_xml
1177 {
1178 my (@article) = @_;
1179 my $string;
1180 my @article_bylab = author_to_lab(@article);
1181 $string = "<article>\n" if (@article > 0);
1182 foreach my $item (@article_bylab) {
1183
1184 my ($lab,@authors) = @$item;
1185 $string .= " <labo>" . accent($lab) . "</labo>\n";
1186 }
1187 $string .= "</article>\n" if (@article > 0);
1188 return $string;
1189 }
1190  
1191  
1192 ########################################################
1193  
1194  
1195 =head2 C<string_byauthors_html> - Return a string with all the authors and lab using html tags
1196  
1197 my $string_out = string_by_authors_html(@article);
1198
1199 <hr>
1200 author1
1201 <p>
1202 <ul>
1203 <li> lab1
1204 <li> lab2
1205 </ul>
1206 <p>
1207
1208 =cut
1209  
1210 sub string_byauthors_html
1211 {
1212 my (@article) = @_;
1213 my $string;
1214 my $number = @article;
1215 $string = "<p>Number of authors: $number<p>\n";
1216 my $i = 1;
1217 foreach my $item (@article) {
1218 $string .= "<hr>\n";
1219 my ($author,@labs) = @$item;
1220 $string .= "$i <p>";
1221 $string .= "<p>" . accent($author) . "\n<ul>";
1222 foreach my $lab (@labs) {
1223 $string .= "<li> " . accent($lab) . "</li>\n";
1224 }
1225 $string .= "</ul><p>\n";
1226 $i = $i + 1;
1227 }
1228 $string .= "</hr>\n";
1229 return $string;
1230 }
1231  
1232  
1233 #############################
1234  
1235  
1236 =head2 C<string_bylabs_html> - PrintReturn a string with all the laboratories with authors using html tags
1237
1238 <hr>
1239 lab1
1240 <p>
1241 <ul>
1242 <li> author1
1243 <li> author2
1244 </ul>
1245 <p>
1246
1247 =cut
1248  
1249 sub string_bylabs_html
1250 {
1251 my (@article) = @_;
1252 my $string;
1253 my @article_bylab = author_to_lab(@article);
1254 my $number = @article_bylab;
1255 $string = "<p>Number of labs: $number<p>\n";
1256 my $i = 1;
1257 foreach my $item (@article_bylab) {
1258 $string .= "<hr>\n";
1259 my ($lab,@authors) = @$item;
1260 $string .= "$i <p>";
1261 $string .= "<p>" . accent($lab) . "\n<ul>";
1262 foreach my $author (@authors) {
1263 $string .= "<li> " . accent($author) . "</li>\n";
1264 }
1265 $string .= "</ul><p>\n";
1266 $i = $i + 1;
1267 }
1268 $string .= "</hr>\n";
1269 return $string;
1270 }
1271  
1272  
1273 #######################################################################
1274 #
1275 # Generic functions to extract the authors and laboratories in a latex string
1276 #
1277 # In these function $name1 is the string command for author list (author)
1278 # and $name2 the string command for laboratory (institution).
1279 # Don't use \ in the command name.
1280 #
1281 # eg: grepautaff("author,"adr",$tex_string);
1282 #
1283 #######################################################################
1284  
1285 ########################################################################
1286 #
1287 # pattern 1:
1288 #
1289 # \auteur
1290 # \adr
1291 #
1292 # \author[ref_adr1]{name1}
1293 # \adr[ref_adr1]{name1}
1294 # \thanksref \thanks
1295 #
1296 #######################################################################
1297  
1298 sub grepautaff
1299 {
1300 my ($name1,$name2,$string_tex) = @_ ;
1301  
1302 my @article_t=();
1303
1304 # get lab name in \newcommand
1305
1306 my %list_index_author;
1307 my %list_index_labo;
1308
1309 #
1310  
1311 my $and;
1312  
1313 my %laliste;
1314
1315 # for $file (@mfile){
1316 # print "file: $file \n";
1317 %laliste = newcommand($string_tex);
1318
1319 my %thanks;
1320 my %thanks_index = list_index("thanks",$string_tex);
1321  
1322 my ($debut_string,@texte_tex) = split(/\\$name1/,$string_tex);
1323
1324 # open(A,$file) or die "cant open $file\n";
1325 # <A>;
1326 # while(<A>){
1327
1328 foreach (@texte_tex) {
1329 chomp;
1330  
1331 my @item = ();
1332 # print "$name2\n";;
1333 $_ =~ s/\\altaffiliation/\\affiliation/g if ($name2 eq "affiliation");
1334 #print "s1=$_ \n" ;
1335 #my $author;
1336 # traite crochet []
1337  
1338 my ($textecrochet,$texteapres) = extract_bracketed($_,"[");
1339 #print "1 = $textecrochet \n";
1340  
1341 my ($author,$suitetexte) = extract_bracketed($texteapres,"{");
1342  
1343 #print "s1=$_ \n" ;
1344  
1345 $author = bichop($author);
1346 # au1 \AND au2
1347  
1348 if ($author =~ /\\and/) {
1349 $and = 1;
1350 }
1351  
1352 #print "<br>1=$author";
1353 $_ =$author;
1354 my ($index_th) = /\\thanksref\{(\w+)\}$/;
1355 #my $index_th = $1;
1356 $author = accent($author);
1357 my $string_thanks = $thanks_index{$index_th};
1358  
1359 $string_thanks =~ s/Present address://;
1360 # $string_thanks =~ s/on leave from//;
1361 $thanks{$author} = $string_thanks if (($index_th ne "") &&($thanks_index{$index_th} =~ /address/));
1362 #print "<br>2=$author --- $string_thanks --- $index_th";
1363  
1364 $textecrochet = bichop($textecrochet);
1365 $list_index_author{$author} = $textecrochet if ($textecrochet ne "");
1366 #print "<br>a= $author \n";
1367 $author =~ s/, and/ and/;
1368
1369 push(@item,$author) if ($author ne "");
1370 #print "s2=$suitetexte \n" ;
1371  
1372 my ($vide,@next) = split(/\\$name2/,$suitetexte);
1373  
1374  
1375 foreach my $texte (@next) {
1376 #my $labo;
1377 #print "t= $texte \n";
1378 my ($textecrochet,$texteapres) = extract_bracketed($texte,"[");
1379 #print "2 = $textecrochet \n";
1380  
1381 my ($labo,$xyz) = extract_bracketed($texteapres,"{");
1382 #print "0 =$labo \n";
1383 $labo = bichop($labo);
1384 $labo =~ s/^ \s*//g;
1385 $labo =~ s/\s*$//g;
1386  
1387 $textecrochet = bichop($textecrochet) if ($textecrochet ne "");
1388 #print "<br>$textecrochet = $labo \n";
1389 $list_index_labo{$textecrochet} = $labo ;
1390  
1391 $labo = $laliste{$labo} if ($laliste{$labo} ne "");
1392 $labo = accent($labo);
1393 #print "2 = $labo \n";
1394 push(@item,$labo) if ($labo ne "");
1395 }
1396 push(@article_t,\@item);
1397  
1398 } # A
1399 # } #$file
1400  
1401  
1402 #return @article_t;
1403 my @article;
1404 if ($and == 0) {
1405 ####
1406 # traite \aut{A and B} \lab l -> A l , B l
1407 # et aussi \au A \au B \lab l -> A l , B l
1408 # \au[ind_lab]{aut} \lab[ind_lab]{lab} -> aut lab
1409 # \author[ind_lab1,ind_lab2]{name1}
1410  
1411 #my @article;
1412 my @listeattente;
1413 foreach my $s (@article_t) {
1414 my ($auto,@labo) = @$s;
1415  
1416 my $labo1 = $labo[0];
1417  
1418  
1419 if ($list_index_author{$auto} ne "") {
1420 my @item;
1421  
1422 my $index_labo = $list_index_author{$auto};
1423 #print "<br>a=$auto";
1424 push(@item,$auto);
1425  
1426  
1427 # \author[lab1,lab2]{name1}
1428  
1429 my @tab_index_lab = split(/,/,$index_labo);
1430  
1431 foreach (@tab_index_lab) {
1432
1433 #push(@item,$list_index_labo{$index_labo});
1434 #print "<br>$_ = $list_index_labo{$_}";
1435 push(@item,$list_index_labo{$_});
1436  
1437 }
1438 push(@item,$thanks{$auto}) if ($thanks{$auto} ne "");
1439 #push(@item,@labo);
1440 push (@article,\@item);
1441  
1442  
1443 } elsif ($labo1 ne "") {
1444 # autre
1445  
1446 foreach my $auteurwait (@listeattente) {
1447  
1448 my @item;
1449 push(@item,$auteurwait);
1450 push(@item,@labo);
1451 push (@article,\@item);
1452 }
1453  
1454 my @auteuritem=split(/,| and /,$auto);
1455 foreach my $unauteur (@auteuritem) {
1456  
1457 my @item;
1458 push(@item,$unauteur);
1459 push(@item,@labo);
1460 push (@article,\@item);
1461 }
1462  
1463 @listeattente = ();
1464  
1465 #@listeauteur = ();
1466 # last
1467  
1468  
1469 } else {
1470  
1471 push(@listeattente,$auto);
1472 }
1473  
1474 } # foreach authorrwait
1475  
1476 } else # $and = 1
1477 {
1478 #my @article;
1479  
1480 foreach my $s (@article_t) {
1481  
1482 my ($aute,$labo) = @$s;
1483  
1484 my @auteur = split(/\\and/,$aute);
1485 my @labo = split(/\\and/,$labo);
1486  
1487 my $nbre = @auteur;
1488  
1489 my $i = 0;
1490  
1491 foreach (@auteur) {
1492 my @doc2;
1493  
1494 push(@doc2,$_);
1495 push(@doc2,$labo[$i]);
1496  
1497 $i = $i +1;
1498 push(@article,\@doc2),
1499 } #for @auteur
1500  
1501 } # for s
1502
1503  
1504 } # and =1
1505  
1506 @article;
1507 } #sub
1508  
1509  
1510
1511 #########################################################################
1512 #
1513 # pattern 2:
1514 #
1515 # aastex
1516 #
1517 # \author{ author1\altaffilmark{1}, author2\altaffilmark{2} }
1518 # \altaffiltext{1}{lab1}
1519 # \altaffiltext{2}{lab2}
1520 #
1521 #########################################################################
1522  
1523 sub grep_aut_altaff
1524 {
1525 my ($string_tex) = @_ ;
1526 my @article;
1527 # for list_index: transform {1} -> [1]
1528 $string_tex =~ s/\\altaffiltext{([^}]+)}/\\altaffiltext[$1]/g;
1529 my %listlab = list_index("altaffiltext",$string_tex);
1530 my @author_string = greplatexcom("author",["t"],$string_tex);
1531 my $authors = bichop($author_string[0]->{t});
1532 my @authors_array = split(/,/,$authors);
1533 foreach (@authors_array)
1534 {
1535 /([^\\]+)\\altaffilmark{([^\\]+)}/;
1536 my @item;
1537 push(@item,$1);
1538 push(@item,$listlab{$2});
1539 push(@article,\@item);
1540 }
1541 return @article;
1542 }
1543  
1544 #########################################################################
1545 #
1546 # pattern 3:
1547 #
1548 # \author{ author \\ lab}
1549 #
1550 #########################################################################
1551  
1552 sub grepaut
1553 {
1554 my ($name1,$string_tex) = @_ ;
1555  
1556 my @article;
1557 #print "in grepaut\n";
1558 my ($debut_string,@texte_tex) = split(/\\$name1/,$string_tex);
1559  
1560 foreach (@texte_tex) {
1561 chomp;
1562  
1563 my @item = ();
1564
1565 my ($textecrochet,$textafter) = extract_bracketed($_,"[");
1566 #print "1 = $textecrochet \n";
1567 #print "2= $texteapres\n";
1568 my ($authorLab,$suitetexte) = extract_bracketed($textafter,"{");
1569  
1570 #print "s1=$_ \n" ;
1571  
1572 $authorLab = bichop($authorLab);
1573 # au1 \AND au2
1574 #print "a=$authorLab\n";
1575  
1576 my ($author,@lab)=split(/\\\\/,$authorLab);
1577 #print "a=$author\n";
1578  
1579 my @tab_author = split(/,| and /,$author);
1580 #print $tab_author[0];
1581  
1582 my $lab_string;
1583 foreach (@lab) {
1584 s/\\and/./g;
1585 s/,$/, /g;
1586 $lab_string .= $_ . ",";
1587 }
1588 $lab_string =~ s/^\s*//g;
1589  
1590 #print "l=$lab_string\n";
1591 foreach (@tab_author) {
1592 my @item;
1593 push(@item,$_);
1594 push(@item,$lab_string);
1595 push(@article,\@item);
1596 }
1597  
1598 return @article;
1599  
1600
1601 }
1602 }
1603  
1604 #########################################################################
1605 #
1606 # pattern 4:
1607 #
1608 # \author{ author1 \lab{address}}
1609 #
1610 #########################################################################
1611  
1612 sub grepautadd
1613 {
1614 my ($name1,$name2,$string_tex) = @_ ;
1615
1616 my @rf=();
1617  
1618 my ($debut_string,@texte_tex) = split(/\\$name1/,$string_tex);
1619  
1620 foreach (@texte_tex) {
1621 chomp;
1622  
1623 my $aut_lab;
1624  
1625 my %ref;
1626  
1627 ($aut_lab,$_) = extract_bracketed($_,"{");
1628  
1629 $aut_lab = bichop($aut_lab);
1630 $aut_lab =~ s/^\s//g;
1631 $aut_lab =~ s/\s$//g;
1632  
1633  
1634 my (@suite) = split(/\\$name2/,$aut_lab);
1635  
1636 my @r;
1637  
1638 my $begin = 1;
1639  
1640 my $rnom;
1641 foreach my $texte (@suite) {
1642 my $courant;
1643 if ($begin == 0) {
1644 # [lab_index] -> lab_name
1645 my $laref;
1646 my $leadr;
1647  
1648 ($laref,$courant) = extract_bracketed($texte,"[");
1649 ($leadr,$courant) = extract_bracketed($texte,"{");
1650  
1651 $laref = bichop($laref);
1652 $leadr = bichop($leadr);
1653  
1654 $ref{$laref} = $leadr if ($laref ne "");
1655  
1656 # push address
1657 if ($texte =~ /mark\[(.*)\]/) {
1658 my $relf = $1;
1659 my $leadr = $ref{$relf};
1660 $leadr = accent($leadr);
1661 push(@r,$leadr);
1662  
1663 } else {
1664 $leadr =~ s/\\.*{.*}//g;
1665 $leadr = accent($leadr);
1666 push(@r,$leadr);
1667 }
1668
1669 if ($rnom ne "") {
1670 my @tab = @r;
1671 push(@rf,\@tab);
1672 }
1673  
1674 } # begin == 0
1675  
1676 @r = ();
1677 $courant = $texte if ($begin == 1);
1678 $courant =~ s/\n/ /g;
1679 $courant =~ s/\\.*{.*}//g;
1680 $courant =~ s/^mark\[.*\]//g;
1681 $rnom = $courant if (!($texte =~ /mark\[(.*)\]/));
1682 my $chaine = accent($courant);
1683  
1684 # push author
1685  
1686 push(@r,$chaine) if ( (! ($texte =~ /mark\[(.*)\]$/)) && (($begin == 1 )|| ($courant =~ /,|and/) )) ;
1687 $begin = 0;
1688 }
1689  
1690 } # A
1691  
1692 #} # file
1693  
1694 return @rf;
1695 } #fonc
1696  
1697  
1698 #####################################################
1699 #
1700 # pattern 5:
1701 #
1702 # for aip articles
1703 #
1704 # \aut{nom}{address={adr1},altaddress={adr2}}
1705 #
1706 #####################################################
1707  
1708  
1709 sub grepautadd_eq
1710 {
1711 my ($name1,$name2,$string_tex) = @_ ;
1712 #print $string_tex;
1713 my @article=();
1714
1715 my ($debut_string,@texte_tex) = split(/\\$name1/,$string_tex);
1716  
1717 foreach (@texte_tex) {
1718 chomp;
1719 #print ;
1720 my $aut;
1721 my $lab;
1722  
1723 my @item;
1724  
1725 ($aut,$lab) = extract_bracketed($_,"{");
1726  
1727 $aut = bichop($aut);
1728 $lab = bichop($lab);
1729 $aut =~ s/^\s//g;
1730 $aut =~ s/\s$//g;
1731  
1732 push(@item,$aut);
1733  
1734 my ($begin,@suite) = split(/${name2}=/,$lab);
1735
1736 # my @r;
1737 # my $begin = 1;
1738  
1739 # my $rnom;
1740
1741 foreach my $texte (@suite) {
1742 #print "t=$texte \n";
1743 my ($leadr,$courant) = extract_bracketed($texte,"{");
1744 $leadr = bichop($leadr);
1745 #print "adr=$leadr \n";
1746 push(@item,$leadr);
1747 }
1748 push(@article,\@item);
1749 }
1750 return(@article);
1751 }
1752  
1753  
1754 #########################################################
1755 #
1756 # pattern 6:
1757 #
1758 # \author{name1$^1$, name2
1759 # \\
1760 # $^1§ labo\\
1761 # }
1762 #
1763 #########################################################
1764  
1765  
1766 sub grepaut_math
1767 {
1768 my ($name1,$string_tex) = @_ ;
1769  
1770 my @article=();
1771  
1772 my @grep_author_lab = greplatexcom("$name1",[["arg"],"t"],$string_tex);
1773 my $author_lab = bichop($grep_author_lab[0]->{t});
1774  
1775 my ($authors,@labs) = split(/\\\\/,$author_lab);
1776  
1777 my $lab_string;
1778  
1779 foreach (@labs) {
1780 $lab_string .= $_;
1781 }
1782  
1783 my @tab_authors = split(/\$/,$authors);
1784  
1785 my ($empty,@tab_address) = split(/\$/,$lab_string);
1786  
1787 my %labo;
1788  
1789 my $i = 0;
1790 my $indice;
1791  
1792 foreach (@tab_address) {
1793 if (!($i % 2)) {
1794 #print "<br>i=$_\n";
1795 /\^{?([\w\\]+)}?/;
1796 #print "i1= $1\n";
1797 #s/^\^//;
1798 $indice = $1;
1799 } else {
1800 s/Present address://; $labo{$indice} = $_; $indice = "";
1801 }
1802 # print "<br>la=$_\n";
1803 $i = $i +1;
1804 }
1805  
1806 my @list_author;
1807 my %name;
1808 my $author;
1809 $i = 0;
1810  
1811 foreach (@tab_authors) {
1812  
1813 if ($i % 2) {
1814 /\^{?([\w,()\\]+)}?/;
1815 # print "<br>$i l=$_\na=$1\n";
1816  
1817 $name{$author} = $1;
1818 push(@list_author,$author);
1819 $author = "";
1820 } else {
1821 #s/^\s*and //;
1822 #s/,$//;
1823 # print "<br>$i b=$_\n";
1824 $author = $_;
1825 $author =~ s/,\s*\\newauthor//g;
1826 # print "<br>$i au=$author\n";
1827 }
1828 $i =$i + 1;
1829 # print "<br>$_";
1830  
1831 }
1832  
1833 foreach (@list_author) {
1834 my @item;
1835 #print "$_<br>";
1836 push(@item,$_);
1837 #print "<br>$_ $name{$_}";
1838 my @tab_indice = split(/,/,$name{$_});
1839 foreach (@tab_indice) {
1840 push(@item,$labo{$_});
1841 }
1842 push(@article,\@item);
1843 }
1844 return @article;
1845  
1846 }
1847  
1848  
1849 ########################################################
1850 #
1851 # pattern 7:
1852 #
1853 # \aut {name1,$^1$ name2,$^2$ name3,$^{1,2}$}
1854 # \lab {$^1$lab1 $^2$lab2}
1855 #
1856 # \aut{name1 $^1$}
1857 # \aut[name2 $^2$}
1858 # \lab{$^1$ lab1}
1859 # \lab{$^2$ lab2}
1860 #
1861 ########################################################
1862  
1863  
1864 sub grepautadd_math
1865 {
1866 my ($name1,$name2,$string_tex) = @_ ;
1867  
1868 my @article=();
1869  
1870 my $authors;
1871 my $address;
1872  
1873 my @aut = greplatexcom("$name1",["t"],$string_tex);
1874 foreach (@aut) {
1875 $authors .= bichop($_->{t}). ", ";
1876 }
1877  
1878 #(bichop($aut[0]->{t})
1879 my @addr= greplatexcom("$name2",[["arg"],"t"],$string_tex);
1880 foreach (@addr) {
1881 $address .= bichop($_->{t}). ", ";
1882 }
1883
1884 my @tab_authors = split(/\$/,$authors);
1885 #print"<br>";
1886 my $i = 0;
1887 my %name;
1888 my %labo;
1889 my @list_author;
1890  
1891 my ($empty,@tab_address) = split(/\$/,$address);
1892  
1893 my $indice;
1894 my $author;
1895  
1896 foreach (@tab_address) {
1897 if (!($i % 2)) {
1898 #print "i=$_\n";
1899 /\^{?([\w,()]+)}?/;
1900 #print "i1= $1\n";
1901 #s/^\^//;
1902 $indice = $1;
1903 } else {
1904 $labo{$indice} = $_; $indice = "";
1905 }
1906 #print "la=$_\n";
1907 $i = $i +1;
1908 }
1909  
1910 $i = 0;
1911  
1912 foreach (@tab_authors) {
1913 if ($i % 2) {
1914 /\^{?([\w,()]+)}?/;
1915 #/\^{?\(?([\w,]+)\)?}?/;
1916 #print "l=$_\na=$1\n";
1917 $name{$author} = $1;
1918 push(@list_author,$author);
1919 $author = "";
1920 } else {
1921 s/^\s*and //;
1922 s/,$//;
1923 #print "b=$_\n";
1924 $author = $_;
1925  
1926 }
1927 $i =$i + 1;
1928  
1929 }
1930  
1931 foreach (@list_author) {
1932 my @item;
1933 #print "$_<br>";
1934 push(@item,$_);
1935  
1936 my @tab_indice = split(/,/,$name{$_});
1937 foreach (@tab_indice) {
1938 push(@item,$labo{$_});
1939 }
1940 push(@article,\@item);
1941 }
1942 return @article;
1943 }
1944  
1945  
1946 #################################################################
1947 #
1948 # Functions for collaboration (physics)
1949 #
1950 # Collaborations now available: h1, aleph, l3, na59, babar, zeus
1951 #
1952 # Each function try to extract authors and lab with the special
1953 # pattern used by a collaboration
1954 #
1955 ################################################################
1956  
1957 ################################################################
1958 #
1959 # Call the good function to extract authors and labs for
1960 # articles with a collaboration name
1961 #
1962 ################################################################
1963  
1964
1965 sub func_by_coll
1966 {
1967 my ($string,$collaboration) = @_;
1968 my @article;
1969 @article = extract_article_h1($string) if ($collaboration eq "h1");
1970 @article = extract_article_aleph($string) if ($collaboration eq "aleph");
1971 @article = extract_article_l3($string) if ($collaboration eq "l3");
1972 @article = extract_article_na59($string) if ($collaboration eq "na59");
1973 @article = extract_article_babar($string) if ($collaboration eq "babar");
1974 @article = extract_article_zeus($string) if ($collaboration eq "zeus");
1975 return(@article);
1976 }
1977  
1978  
1979 ###################################################################
1980 #
1981 # Collaboration 1: Na59
1982 #
1983 # Extract authors and lab for article of Na59 collaboration
1984 #
1985 # external file with \author and \affiliation
1986 #
1987 ###################################################################
1988  
1989  
1990 sub extract_article_na59
1991 {
1992 my ($string) = @_;
1993 my $chaine_file = $string ;
1994 return grepautaff("author","affiliation",$chaine_file);
1995 }
1996  
1997  
1998 ##################################################################
1999 #
2000 # Collaboration 2: H1
2001 #
2002 # Extract authors and lab for article of H1 collaboration
2003 #
2004 # external file
2005 # I.~Name$^{24}$
2006 # ...
2007 # $ ^{24}$ lab name \\
2008 #
2009 ###################################################################
2010  
2011  
2012 sub extract_article_h1
2013 {
2014 my ($string) = @_;
2015 my $chaine_file = $string ;
2016 #print $chaine_file;
2017  
2018 my $out_author = 0;
2019  
2020 my @tab_au;
2021 my @tab_lab;
2022 my %name_lab;
2023 my $i;
2024 my $ligne_lab;
2025 my $chaine;
2026 my $author;
2027 my $index;
2028  
2029 #while (<>)
2030  
2031 my @tab_chaine = split(/\n/,$chaine_file);
2032  
2033  
2034 foreach (@tab_chaine) {
2035 # author
2036 #print "l=$_\n";
2037  
2038 if ((/(^[^\s]+.*)\$\^{([\s\w,]+)}\$(,?)\s/) && ($out_author == 0)) {
2039 #print "$_\n";
2040 $out_author = 1 if ($3 eq "");
2041 #print "out = $out_author $3 \n";
2042
2043 my $auteur = $1;
2044 $auteur = accent($auteur);
2045 #print "x=$auteur $1 $2\n";
2046  
2047 my $index_lab = $2;
2048 $index_lab =~ s/^\s*//;
2049 $index_lab =~ s/\s*$//;
2050  
2051 my @liste_t = split(/,/,$index_lab);
2052 my @liste;
2053 my $chaine;
2054  
2055 foreach (@liste_t) {
2056 push (@liste,$_) if (/\d+/);
2057 }
2058  
2059 # print $_;
2060 #print "a=$auteur";
2061  
2062 #foreach my $in (@liste)
2063 #{
2064 #print " i=$in";
2065 #}
2066 #print "\n";
2067  
2068 #$tab_aut{$auteur} = \@liste;
2069  
2070 $tab_au[$i] = $auteur;
2071 $tab_lab[$i] = \@liste;
2072 $i = $i + 1;
2073  
2074 #print "$i $tab_lab[$i][0] \n";
2075 }
2076 #print "n=" . @tab_au . "\n";
2077  
2078 # lab
2079 if ( (/\$\s*\^{(\d+)}\$(.*?)(\$.*\$)?\s\\\\/) && ($out_author == 1) ) {
2080 #print "ligne1= $1 $2\n";
2081 my $index= $1;
2082 my $labo = $2;
2083 $index =~ s/^\s*//g;
2084 $index =~ s/\s*$//g;
2085 #print "ligne= $1 --- $2\n";
2086 $labo = accent($labo);
2087 $name_lab{$index} = $labo;
2088 #print "li=$index $labo\n";
2089 # more than 1 line
2090 } elsif ( (/\$\s*\^{(\d+)}\$(.*)\s*/) && ($out_author == 1) ) {
2091  
2092 $ligne_lab = 1;
2093 $chaine = $2;
2094 $index = 0;
2095 $index = $1;
2096 $index =~ s/^\s*//g;
2097 $index =~ s/\s*$//g;
2098  
2099 #print "12= $1 $2\n";
2100 } elsif ( (!/\\\\$/) && ($ligne_lab == 1) ) {
2101 #print "3s $_";
2102 /(.*)/;
2103 #print "3=$1\n";
2104 $chaine .= " $1";
2105  
2106 } elsif ( (/(.*?)(\$.*\$)?\s*\\\\$/) && ($ligne_lab == 1) ) {
2107  
2108 #print "4=$1\n";
2109 $chaine .= " $1";
2110 #print "$chaine\n";
2111 $chaine = accent($chaine);
2112 $name_lab{$index} = $chaine;
2113 $ligne_lab = 0;
2114 $chaine = "";
2115 }
2116 }
2117  
2118 my @total;
2119  
2120 my $nb_aut= @tab_au;
2121  
2122 #foreach my $author (keys %tab_aut)
2123 my $j;
2124  
2125 for ($j=0 ;$j < $nb_aut; $j++) {
2126 #print "au=$author\n";
2127 my @tableau;
2128  
2129 push(@tableau,$tab_au[$j]);
2130  
2131 #print "j $j = $tab_au[$j] \n";
2132  
2133 #print "t= $tab_au[$j] \n";
2134  
2135 my $adr = $tab_lab[$j];
2136 foreach my $lab (@$adr) {
2137 #print " l= $lab\n";
2138 #print " nl= $name_lab{$lab} \n";
2139 push(@tableau,$name_lab{$lab});
2140
2141 }
2142 push(@total,\@tableau)
2143 }
2144  
2145 #print_item(@total);
2146  
2147 return(@total);
2148  
2149 #print "ok \n";
2150 }
2151  
2152  
2153 ###############################################################
2154 #
2155 # collaboration 3: Aleph
2156 #
2157 # Extract authors and lab for article of Aleph collaboration
2158 #
2159 # \begin{sloopypar}
2160 # aut1,
2161 # aut2,
2162 # \command
2163 # name1
2164 # name2
2165 # \end
2166 #
2167 ##############################################################
2168  
2169  
2170 sub grep_article_aleph
2171 {
2172 my ($string) = @_;
2173 my $chaine_file = $string ;
2174 my %index_tab = list_index("footnotetext",$chaine_file);
2175  
2176 my @liste = theenvs("sloppypar",$chaine_file);
2177  
2178 #print "l=$liste \n";
2179 my @article;
2180 my %liste_index;
2181 foreach my $list (@liste) {
2182 my @tab_chaine = split(/\n/,$list);
2183  
2184 my $lab;
2185 my $in_author = 0;
2186 my $in_lab = 0;
2187 my $ok_lab= 0;
2188 my %foot_note;
2189 my @author_wait;
2190 foreach (@tab_chaine) {
2191  
2192 #if ((/^\s*\\\w+/) && (! /^\\mbox{/) && ($in_author == 1)){ print "1=$_\n";
2193 # $in_author = 0; $in_lab = 1; }
2194  
2195  
2196 if ( ((/^\s*\\nopagebreak/) || (/^\s*\\samepage/)) && ($in_author == 1) ) { #print "1=$_\n";
2197 $in_author = 0; $in_lab = 1;
2198 } elsif ((/^\w+,?/) && ($in_lab == 0)) {
2199 $in_author = 1;
2200 s/\s*\$\^{(\w+)}\$\s*$//; my $index = $1; s/,//; push(@author_wait,$_) ;
2201 my $newlab = $index_tab{$index} ;
2202 #print "21=$_\n";
2203 $foot_note{$_} = $newlab if ($newlab ne "");
2204 #print "$_ XXXXXXX i=$index --- $newlab\n";
2205 } elsif ((/^\s*\\mbox{(.*)}/) && ($in_lab == 0)) {
2206 $in_author = 1; $_ = $1;
2207 s/\s*\$\^{(\w+)}\$\s*$//; s/,//; my $index = $1; push(@author_wait,$_) ;
2208 my $newlab = $index_tab{$index} ;
2209 #print "22=$_\n";
2210 $foot_note{$_} = $newlab if ($newlab ne "");
2211 } elsif ((/^\w+,?/) && ($in_lab == 1)) {
2212 s/;
2213 }
2214 $//; #print "3=$_\n";
2215 $lab .= "$_ "; $ok_lab = 1;
2216 } elsif ((/^\s*\\\w+/) && ($in_lab == 1) && ($ok_lab == 1)) { #print "4=$_\n";
2217 $in_author = 0; $in_lab = 0;
2218  
2219 foreach (@author_wait) {
2220 my @item;
2221  
2222 push (@item,$_);
2223  
2224 $lab =~ s/\$\^{[\w,]+}\$\s*$//;
2225 $lab =~ s/\\footnotemark\[\w*\]//;
2226 push (@item,$lab);
2227 $foot_note{$_} =~ s/^Now at //;
2228 $foot_note{$_} =~ s/^Also at //;
2229 $foot_note{$_} =~ s/Permanent address: //;
2230 push(@item,$foot_note{$_}) if (($foot_note{$_} ne "") && (! ($foot_note{$_} =~ /^(Research|Deceased|Supported)/)));
2231 push(@article,\@item);
2232 }
2233  
2234 }
2235  
2236 }
2237 }
2238 return(@article);
2239 }
2240  
2241 ##############################################################
2242 #
2243 # Collaboration 4: L3
2244 #
2245 # Extract authors and lab for article of the L3 collaboration
2246 #
2247 # external file (\input)
2248 #
2249 # name1\r\tute\reflab\
2250 # name2\r\tute{\reflab1,\reflab2}\
2251 #
2252 # \item[\reflab1] lab1
2253 # \item[\reflab2] lab2
2254 #
2255 #################################################################
2256
2257  
2258 sub extract_article_l3
2259 {
2260 my ($string) = @_;
2261 my $tex_string = $string;
2262  
2263 $tex_string =~ s/\\item/\}\\item/g;
2264 # \1 -> $1
2265 $tex_string =~ s/(\\item\[.*\])/$1\{/g;
2266  
2267 #print $tex_string;
2268  
2269 my %index_tab = list_index("item",$tex_string);
2270  
2271 my @article;
2272  
2273 #my @liste = theenvs("sloppypar",$chaine_file);
2274 #\r\tute
2275
2276 my %name;
2277  
2278 my @tab_line = split(/\n/,$tex_string);
2279 my @line_author =grep (/\\r\\tute|\\rlap.\\tute/, @tab_line);
2280 #my @author_index =
2281  
2282 map (s/\\r\\tute|\\rlap.\\tute/ / , @line_author);
2283  
2284 foreach (@line_author) {
2285 my @item;
2286 my ($author,$index_labo) = split(/\s/);
2287 # add space : J.C. smith -> J. C. Smith
2288 #$author =~ s/([^\.]+)$/~$1/;
2289 $author =~ s/\./\. /g;
2290 push(@item,$author);
2291 #print "$index_labo ";
2292  
2293 my @tab_index_lab = split(/,/,$index_labo);
2294  
2295 foreach (@tab_index_lab) {
2296 s/^{//;
2297 s/}?\\$//;
2298 #print "$_ ";
2299 my $lab = $index_tab{$_};
2300 $lab =~ s/\$\^?{\\\w+}\$\s*$//;
2301 push(@item,$lab);
2302 #print "$author $index_tab{$_}\n";
2303 }
2304 #print "$author\n";
2305 push(@article,\@item);
2306 }
2307 return(@article);
2308 #exit;
2309 }
2310  
2311  
2312 ####################################################################
2313 #
2314 # Collaboration 5: Babar
2315 #
2316 # Extract authors and lab for article of the Babar collaboration
2317 #
2318 # \begin{center}
2319 # author1,
2320 # author2
2321 # \inst{lab}
2322 # author3,\footnote{note}
2323 # \end{center}
2324 #
2325 #####################################################################
2326
2327  
2328 sub extract_article_babar
2329 {
2330 my ($string) = @_;
2331 my @article;
2332 my $authors_labs_string;
2333 my @array = theenvs("center",$string);
2334 my $center_string;
2335 foreach $center_string (@array) {
2336 $authors_labs_string = $center_string;
2337 last if ($center_string =~ /\\inst/s);
2338 }
2339
2340 my @labo = greplatexcom("inst",["lab"],$authors_labs_string);
2341 my @footnote = greplatexcom("footnote",["note"],$authors_labs_string);
2342 my $i = 0;
2343 my $j = 0;
2344 my %otherlab;
2345 my @authors_array;
2346
2347 my @line_array = split(/\n/,$authors_labs_string);
2348  
2349 foreach my $line (@line_array) {
2350 if ((!($line =~ /~/)) && (!($line =~ /\\inst/))) {
2351 next;
2352 }
2353 if (($line =~ /\~/) && (! ($line =~ /\\inst/))) {
2354 if ($line =~ /\\footnote\{/) {
2355 # print "<br>$line -- $j -- $footnote[$j]->{note}<br>";
2356 my $footlab = $footnote[$j]->{note};
2357 bichop($footlab);
2358 $footlab =~ s/Also with //;
2359 # print "<br> s=$footlab <br>";
2360 $line =~ s/,\\footnote{.*//;
2361 $otherlab{$line} = $footlab;
2362 $j = $j + 1;
2363 }
2364  
2365 if ($line =~ /\\footnotemark\[(\d+)\]/) {
2366 my $note = $1; $line =~ s/,\\footnotemark\[.*//;
2367 $note = $note -1;
2368 # print "<br>mark ". $line . " -- " . $note . " -- ". $footnote[$note]->{note} . " <br>";
2369 my $footlab = bichop($footnote[$j - 1]->{note});
2370 $footlab =~ s/Also with //;
2371 $otherlab{$line} = $footlab;
2372 }
2373  
2374 $line =~ s/,$//;
2375 push(@authors_array,$line);
2376 }
2377 if ($line =~ /\\inst/) {
2378 bichop($labo[$i]->{lab});
2379 foreach (@authors_array) {
2380 my @item;
2381 push(@item,$_);
2382 push(@item,$labo[$i]->{lab});
2383 push(@item,$otherlab{$_}) if (($otherlab{$_} ne "") && ($otherlab{$_} ne "Deceased"));
2384 push(@article,\@item);
2385 }
2386 @authors_array = ();
2387 $i = $i + 1;
2388 }
2389 }
2390 return @article;
2391 }
2392  
2393
2394 ####################################################################
2395 #
2396 # Collaboration 6: Zeus
2397 #
2398 # Extract authors and lab for article of the Zeus collaboration
2399 #
2400 # author1,
2401 # author2,
2402 # author3\\
2403 # {\it lab1}~$^{a}$
2404 # author3$^{ 1}$,
2405 #
2406 # \newpage
2407 #
2408 ######################################################################
2409  
2410 sub extract_article_zeus
2411 {
2412 my ($string) = @_;
2413 my @article;
2414 my @line_array = split(/\n/,$string);
2415 my $begin; my $in_lab;
2416 my @authors;
2417 my $string_lab;
2418 foreach (@line_array)
2419 {
2420 if ((/\\Large/) && (/zeus/i)) { $begin = 1; }
2421 elsif (($begin == 1) && (/\\newpage/)) { $begin = 0; last;}
2422 elsif (($begin == 1) && (/,\s*$/) && (!(/\{\\it /)) && ($in_lab != 1)) {
2423 s/\$\^\{[^}]+\}\$//;
2424 my $author = $_;
2425 if (/\\mbox/){ my @author_tempo = greplatexcom("mbox",["author"],$_); $author = bichop($author_tempo[0]->{author});}
2426 push(@authors,$author); }
2427 elsif (($begin == 1) && (/\\\\\s*$/) && (!(/\{\\it /)) && ($in_lab != 1)) { s/\$\^\{[^}]+\}\$//g;
2428 my $author = $_;
2429 if (/\\mbox/){ my @author_tempo = greplatexcom("mbox",["author"],$_); $author = bichop($author_tempo[0]->{author});}
2430 push(@authors,$author);}
2431 elsif (($begin == 1) && (/\{\\it /)) {$string_lab .= $_; $in_lab = 1; }
2432 elsif (($begin == 1) && ($in_lab == 1) && (!(/\\par/))) {$string_lab .= $_;}
2433 elsif (($begin == 1) && ($in_lab == 1) && (/\\par/)) {
2434 $string_lab =~ s/^\s*//g;
2435 my ($thelab,$next) = extract_bracketed($string_lab,"{");
2436 $in_lab = 0; $string_lab ="";
2437 $thelab = bichop($thelab); $thelab =~ s/\\it\s*//g;
2438
2439 foreach (@authors)
2440 { my @item;
2441 push(@item,$_);
2442 push(@item,$thelab);
2443 push(@article,\@item);
2444 }
2445
2446 @authors = ();
2447 }
2448
2449 }
2450 return @article;
2451 }
2452  
2453 ####################################################################
2454 #
2455 # Collaboration 7: Fermilab
2456 #
2457 # Extract authors and lab for article with Fermilab report
2458 #
2459 # \begin{center}
2460 # author1,$^1$
2461 # author2,$^$2
2462 # author3
2463 # \end{center}
2464 # \begin{enumerate}
2465 # \item lab1
2466 # \item lab2
2467 # \end{enumerate}
2468 #
2469 # arXiv: hep-ex/0304017
2470 #
2471 ######################################################################
2472  
2473 sub extract_report_fermilab
2474 {
2475 my ($string) = @_;
2476 my @article;
2477 my @center = theenvs("center",$string);
2478 my @enumerate = theenvs("enumerate",$string);
2479 my $string_authors = $center[1];
2480 my $string_labs = $enumerate[0];
2481 my @labs = split(/\\item/,$string_labs);
2482 my ($empty,@authors) = split(/\n/,$string_authors);
2483
2484 foreach (@authors)
2485 {
2486 my @item;
2487 s/\^\*,//g;
2488 /([\w~\.-]+),?\$\^{?([\d]+)}?\$/;
2489 push(@item,$1);
2490 push(@item,$labs[$2]);
2491 push(@article,\@item);
2492 #print "<br>$_ --- $1 --- $2";
2493 }
2494 return @article;
2495 }
2496
2497 1;
2498  
2499  
2500 __END__
↑ Summary