#!/usr/bin/perl -w # ^---- edit the above path if perl is located elsewhere on your # system (use 'which perl' to find out). Then tell your system # manager they put perl in the wrong place. # # Specify your bibliography directory. Comment out if not desired. # Description in bibliography section below. # $bibdirectory = "/home/bvl/Publications"; # ############################################################################# # # reftex v0.3 by Ben Vollmayr-Lee, bvollmay@bucknell.edu, Apr 2002 # # Purpose: to make references humane in revtex (versions 3 and 4) and conform # to Phys Rev endnote style (which their recommendation, bibtex, does not). # Copyright: you may freely use, modify, and distribute this. But it would # be nice if you informed me because I might like your modifications too. # # Installation: just make this file executable with 'chmod u+x reftex' and # put it in your executable path # Usage: exactly like latex: type 'reftex paper.tex' to get paper.dvi # # Documentation: # This program can be used simply as a reference ordering system for a # single revtex paper, or it can be used with a bibliography file # similar to bibtex, or you can do a combination of the two. This latter # option allows making endnotes within the paper while keeping references # in a bibliography file, for example. # # Here's a summary of how reftex works (paper.tex means your file): # 1) steps through paper.tex and makes a list of your citation names # 2) reads in your bibliography file entries, if you have one # 3) reads in the \bibitem entries in paper.tex # 4) creates ordered set of appropriate \bibitem entries in a new # version of your paper called paper.ref.tex (in suitable form for # cond-mat or journal submission) # 5) runs latex on paper.ref.tex and moves the result to paper.dvi # Thus you can do your editing on paper.tex, compile with reftex to get # paper.dvi with the references done properly, and when you're ready to # submit the paper, use the paper.ref.tex version. # # Bibliography file: # You specify the name of this file in paper.tex via the 'biblocation' # tag (which needs to be commented out by a '%' in the tex file). Two # possible syntaxes: # # % biblocation /path/to/your/bibliography.txt # # or # # % biblocation (BIB)/otherbibfilename.txt # # In the first case, the path can either be relative or absolute. In the # second case, "(BIB)" gets replaced by the directory you have specified # in the variable $bibdirectory at the top of this file. This is useful # for sharing a paper.tex file with a collaborator. If a bibliography is # not specified, then reftex just assumes you don't have one and proceeds # (with a warning that it didn't find a file). The format for this # bibliography file is a separate line for each reference (blank lines OK): # # EPR35 A. Einstein, B. Podolsky, and N. Rosen, PR 47, 777 (1935). # LeeRutenberg97 B.P.Lee and A.D.Rutenberg, PRL 79, 4842 (1997). # % for comments. Nonbreaking space added between initials. # # Here the first item in the line is the citation name, and the # rest is the reference (which can contain multiple papers). Non-journal # references must be in standard tex form. Journals will automatically # get their volume number bold-faced if it not already, and the # abbreviations PR, PRE (and A-D), JPA, EPL, RMP, and JSP are expanded. # # In your revtex paper: # You need to have the \begin{thebibliography} or \begin{references} # tag in the file, as well as the associated \end{} command. Between # them you can include any \bibitem entries you like, though these must # be tex formatted (no expansion of abbreviations like PRE). If a citation # name appears in both your bibliography file and as a \bibitem entry # in your paper, the latter version is used. Only those \bibitem entries # that are actually \cite-ed appear (same goes for the bibliography, for # that matter). # code begins here # deal with command line inputs my $texfile = $ARGV[0]; unless( $texfile && $texfile ne "-h" && $texfile ne "--h" ){ print "The documentation for reftex is located within the source code\n"; exit; } $texfile =~ s/\.tex$//; $bibdirectory =~ s#/$##; # finds all \cite{} arguments in file open(TEXFILE,"$texfile.tex") || die "Cannot open $texfile.tex: $!"; while( ){ if( /biblocation\s+(\S+)/ ){ ($biblocation) = $1; $biblocation =~ s/^\(BIB\)/$bibdirectory/; } # @text = join(",",/(?:\\cite\{(.*?)\})*/ ); <- not right # $k = join(",",@text); # @list = split(/,/,$k); # push(@citations,@list); @text = split( /\\cite\{/ ); shift @text; foreach $k (@text){ ($k) = split(/\}/,$k); @list = split(/,/,$k); push(@citations,@list); } } close(TEXFILE); # now assign refs based on their order of appearance foreach $cite (@citations){ $flag = 0; foreach $ref (@references){ if( $ref eq $cite ){ $flag=1; last; } } if( $flag == 0 ){ push(@references,$cite); } } # read in bibliography entries unless( $biblocation ) { print "No biblocation specified\n"; } open(BIB,$biblocation) || warn "Cannot open $biblocation: $!"; while(){ chomp; next unless /\S+/; ($line) = split(/%/); next unless $line =~ /\S+/; ($refname,@rest) = split(/\s+/,$line); next unless in_list($refname,@references); $line = join(" ",@rest) . "\n"; $line =~ s/([A-Z])\.(\W*)/$1.~/g; # tildify initials $line =~ s/(\d+)\s*,\s*(\d+)\s*\((\d+)\)/\{\\bf $1\}, $2 ($3)/g; # bf vol. # Journal Substitutions $line =~ s/PRA/Phys.\ Rev.\ A/g; $line =~ s/PRB/Phys.\ Rev.\ B/g; $line =~ s/PRC/Phys.\ Rev.\ C/g; $line =~ s/PRD/Phys.\ Rev.\ D/g; $line =~ s/PRE/Phys.\ Rev.\ E/g; $line =~ s/PRL/Phys.\ Rev.\ Lett.\ /g; $line =~ s/JPA/J.\ Phys.\ A/g; $line =~ s/JSP/J.\ Stat.\ Phys.\ /g; $line =~ s/EPL/Europhys.\ Lett.\ /g; $line =~ s/RMP/Rev.\ Mod.\ Phys.\ /g; $refinfo{$refname} = $line; } close BIB; # copy paper.tex to paper.ref.tex, and when reaching the references section, # insert the correct \bibitem entries open(IN,"$texfile.tex"); open(OUT,">$texfile.ref.tex"); $bibparse = 0; $all = ""; while(){ if( $bibparse ) { if(/\\end\{thebibliography\}/ || /\\end\{references\}/){ @bibs = split(/\\bibitem\{/,$all); foreach $case (@bibs){ $case =~ /\}/; $refinfo{$`} = $'; } foreach $ref (@references){ print OUT "\\bibitem{$ref} $refinfo{$ref}\n"; } print OUT $_; $bibparse = 0; } else{ # still reading bibitems chomp; $all .= " $_"; } } else { print OUT $_; } if(/\\begin\{thebibliography\}/ || /\\begin\{references\}/){ $bibparse = 1; } } close(IN); close(OUT); # now run latex on paper.ref.tex and move the result to paper.dvi system("latex $texfile.ref.tex; mv $texfile.ref.dvi $texfile.dvi"); print "\n--- DVI output in $texfile.dvi ---\n"; sub in_list { my ($check,@list) = @_; my ($item); my ($found) = 0; foreach $item (@list){ if( $item eq $check ){ $found=1; last; } } return $found; }