#!/usr/local/bin/perl #******************************************************************* # jnl2revtex v0.5 Copyright (c) 1993 Karl J. Runge, Nov 16 $VERSION="v0.5"; # # A script to attempt to change a jnl3 TeX file # into a REVTeX file. # # It will not do everything..... # It is based on how I use jnl. Certain things are assumed... # (and when I assume, I make an ASS of yoU and ME) #-------------------------------------------------------------------- # INSTALLATION: Go down to the section below denoted "TAYLOR" # You may have to change some of the commands to get this script # to run. Later you may want to change the Defaults in that section. #-------------------------------------------------------------------- #******************************** # This is what jnl2revtex does: * #******************************** # -- Replaces [for the most part!] jnl syntax with REVTeX syntax. # -- Takes .ref and makes properly ordered \bibitem section. # -- Takes .eqn and makes properly ordered \label and references to eqns # including \eqalign ones. If an equation has no label it keeps that way. # -- Reruns Tex if no .ref or .eqn files are found. # -- Tests your Topmatter format. # -- Tries to 'fix' your Topmatter format. (-t -topmatter) # -- Tests your \eqalign format. # -- Tries to 'fix' your \eqalign format (NOT YET, TODO). # -- Removes lines starting with '%' (override-able -keepcomments). # -- Removes lines ending with '% norevtex' (i.e. things you want with jnl only). # # -- Replaces all your \def macros occurences. (override-able -nd, ...) # -- Tests your \def's (i.e. you should only have one per line with '}' at EOL). # -- Optionally just replace user macro definitions, no jnl -> revtex. # -- Never alters your jnl sourcefile, puts new stuff in new file. # # ---------------------------------------------------------------------- #*********** # Caveats: * #*********** # -> Your whole source must be in 1 file. [Are there any combiners out there? # (if TODO this, worry about nested \inputs, $TEXINPUTS searches)] # -> Refis and Refto should have no spaces, i.e. # \refis{runge} ...., not \refis { runge}, etc # \refis{runge,smith} ...., not \refis{runge, smith}, etc # jnl2revtex does try to fix this though... (-badboy) # but how to automatically fix this robustly?? # -> Must have \equationfile and \referencefile in jnl sourcefile # (TODO) # -> Don't split \journal call over 2 lines (well, -badboy tries to fix) # -> Eqalign---must be in form: (with no spaces at end either...) # $$ # \eqalign # { # blah # } # $$ # -> The script is a tribute to Rube Goldberg: you must have: # awk, ed, ex, grep, sed, and vi (yes, vi!) on your system. # -> PACS must be there like....(Although it does try to 'fix' this) # \abstract # # blah, blah, ... # # PACS numbers: 64.70.Pf, 05.30.Jp, 05.70.Jk, 75.10.Nr # \endtopmatter # # # -> Should have braces for \title{} \author{} \affil{} # but I made it try to do this automatically (TRY_FIX_TOPMATTER="on") # -> No support for Tables or FigureCaptions, sorry... # -> See BOTTOM of this file for other unsupported jnl3 features # (let me know if you put them in!!) # TODO: auto-order \defs? so called are last?? (did it by calling thrice) # --------------------------------------------------------------------------- # Legals: do whatever you want with this program, # but don't receive any money for distributing it (right...), and # give Karl J. Runge credit for it. # --------------------------------------------------------------------------- #**************************************************************************** # inline file substituter, grepper # Usage: &prep(FileName,'script'); sub prep { local($i); local($fn,$script) = @_; # local vars if ( $script !~ /;\s*$/ ) { $script .= ';'; } # make sure script if ( $script !~ /print/ ) { $script .= 'print;'; } # make sure print #print "$script","\n"; open(PREP,"$fn"); @PREP = ; # read in file open(PREP,">$fn"); local($OLD) = select(PREP); # get ready to write for ( $i = 0; $i < @PREP; $i++) { $_ = $PREP[$i]; eval $script; } select($OLD); close(PREP); } # ** BEGIN TAYLOR SECTION *************************************************** # UNIX Commands $TEX="tex"; $TMP_PREFIX=""; # Temp file prefix (i.e. directory + trailing /) # Initialize some switches $TRY_FIX_TOPMATTER="on"; # try to insert { and } in topmatter part. $REPLACE_DEF="on"; # replace user defs in whole file. $CLEAN_UP="on"; # remove temporary files when done. $KEEP_COMMENTS="off"; # strip TeX ' %' comment lines. $GOODBOY="off"; # assume nasty jnl sourcefile. $DEFONLY="off"; # "on" ONLY do \def replacements. $SAFE="off"; # Umm, "on" means don't try aggressive # changes. # See "% My own jnl defs" small section below to see if you agree... # ** END TAYLOR SECTION (free free to change elsewhere, of course)*********** $SRC=""; $DEST=""; # Define help sub help { print "","\n"; print "Usage: $0 [options] infile[.tex] [outfile[.tex]]","\n"; print "","\n"; print "where:","\n"; print " infile is jnl source file (or basename)","\n"; print " outfile is (optional) REVTeX output filename (or basename)","\n"; print " default is infile_RT.tex","\n"; print "","\n"; print "options:","\n"; print " -d replace (expand) all simple macros (\\def)","\n"; print " (Thanks to Cyrus Umrigar)","\n"; if ( "$REPLACE_DEF" eq "on" ) { print " [Default]","\n"; } print "","\n"; print " -nd do not expand macros","\n"; print " -keepdef","\n"; if ( $REPLACE_DEF eq "off" ) { print " [Default]","\n"; } print "","\n"; print " -t try to fix topmatter section","\n"; print " -topmat","\n"; if ( $TRY_FIX_TOPMATTER eq "on" ) { print " [Default]","\n"; } print "","\n"; print " -nt do not try to fix topmatter section","\n"; print " -notopmat","\n"; if ( $TRY_FIX_TOPMATTER eq "off" ) { print " [Default]","\n"; } print "","\n"; print " -keepcomments yes, keep % comments","\n"; if ( $KEEP_COMMENTS eq "on" ) { print " [Default]","\n"; } print "","\n"; print " -goodboy assume nice sourcefile, no macros at end of line or","\n"; print " spaces in \\refto, \\cite, or \\refis","\n"; if ( $GOODBOY eq "on" ) { print " [Default]","\n"; } print "","\n"; print " -badboy expect badboy macros and spaces positioning","\n"; if ( "$GOODBOY" eq "off" ) { print " [Default]","\n"; } print "","\n"; print " -safe -s do some safe things...","\n"; if ( "$SAFE" eq "on" ) { print " [Default]","\n"; } print "","\n"; print " -defonly ONLY replace \\defs, no jnl -> revtex work","\n"; if ( "$DEFONLY" eq "on" ) { print " [Default] !!","\n"; } print "","\n"; print " -help -q print this info","\n"; print "","\n"; print " -v print version info","\n"; print "","\n"; } # Process args: while ($_ = $ARGV[0]) { shift; CASE: { /-d/ && ($REPLACE_DEF="on", last CASE); /-g.*/ && ($GOODBOY="on", last CASE); /-b.*/ && ($GOODBOY="off", last CASE); /-nd.*/ && ($REPLACE_DEF="off", last CASE); /-keepdef.*/ && ($REPLACE_DEF="off", last CASE); /-defonly.*/ && ($DEFONLY="on", last CASE); /-keepcom.*/ && ($KEEP_COMMENTS="on", last CASE); /-topmat.*/ && ($TRY_FIX_TOPMATTER="on", last CASE); /-notopmat.*/ && ($TRY_FIX_TOPMATTER="off", last CASE); /-t.*/ && ($TRY_FIX_TOPMATTER="on", last CASE); /-nt.*/ && ($TRY_FIX_TOPMATTER="off", last CASE); /-s.*/ && ($SAFE="on", last CASE); /-help/ && (&help, exit 0); /-q/ && (&help, exit 0); /-v/ && ((print "jnl2revtex $VERSION Copyright (c) 1993 Karl J. Runge\n"), exit 0); /-.*/ && (&help, exit 1); if ( "$SRC" eq "" ) { $SRC="$_"; } elsif ( "$DEST" eq "" ) { $DEST="$_"; } else { print "\n"; print "jnl2revtex $_: Only two filenames please!\n"; print "jnl2revtex: Using file \"$SRC\", as source.\n"; print "jnl2revtex: Using file \"$DEST\", as destination.\n"; } } } if ( "$DEFONLY" eq "on" ) { $REPLACE_DEF="on"; } # Find and make Names chop($BASE=`basename $SRC .tex`); chop($DIR=`dirname $SRC`); $SRC="${DIR}/${BASE}.tex"; if ( "$DEST" eq "" ) { $DEST="${DIR}/${BASE}_RT.tex"; } else { chop($BASE2=`basename $DEST .tex`); chop($DDIR=`dirname $DEST`); $DEST="${DDIR}/${BASE2}.tex"; } if ( "$SRC" eq "$DEST" ) { print "Umm, I don't like source equal to destination...\n"; $DEST="${DIR}/${BASE}_RT.tex"; print "Destination will be $DEST, continue? (y/n) "; $CONT = ; if ( "$CONT" ne "y" ) { print "exiting...\n"; exit 1; } } $EQN="${DIR}/${BASE}.eqn"; $REF="${DIR}/${BASE}.ref"; # Temp files (lots, eh?) $TOPS="${TMP_PREFIX}j2rt.tops$$"; $TOPS2="${TMP_PREFIX}j2rt.tops2$$"; $DEFS="${TMP_PREFIX}j2rt.defs$$"; $DEFS2="${TMP_PREFIX}j2rt.defs2$$"; $DEFDUMP="${TMP_PREFIX}j2rt.defdump$$"; $DEFEXTRA="${TMP_PREFIX}j2rt.defextra$$"; $REFIS0="${TMP_PREFIX}j2rt.refis0-$$"; # $IN="${TMP_PREFIX}j2rt.in$$"; $OUT="${TMP_PREFIX}j2rt.out$$"; $PRESENT="${TMP_PREFIX}j2rt.present$$"; # $EDCMD="${TMP_PREFIX}j2rt.ed$$"; $GOTBB="${TMP_PREFIX}j2rt.got$$"; $EQNAL="${TMP_PREFIX}j2rt.eqnal$$"; $EQNAL2="${TMP_PREFIX}j2rt.eqnal2$$"; $D1SAVE="DEFS1_${BASE}_${$}"; $D2SAVE="DEFS2_${BASE}_${$}"; # Misc chop($DATE=`date`); @CLEAN=($TOPS, $TOPS2, $DEFS, $DEFS2, $IN, $OUT, $PRESENT, $EDCMD, $GOTBB, $EQNAL, $EQNAL2, $REFIS0, $D1SAVE, $D2SAVE); # Functions sub p2in { system("cp $PRESENT $IN"); } sub out2p { system("cp $OUT $PRESENT"); } sub clean { if ( "$CLEAN_UP" ne "off" ) { foreach $i (@CLEAN) { system("rm -f $i"); } } } sub Top { print "%% Created $DATE [for the most part!] by...\n"; print "%% jnl2revtex ${VERSION}, Copyright Karl J. Runge 1993\n"; print "%% LaTeX format: REVTeX 3.0\n"; print '\documentstyle[preprint,aps]{revtex}',"\n"; print '%\documentstyle[aps]{revtex}',"\n"; print '%\documentstyle[eqsecnum,aps]{revtex}',"\n"; print '%\documentstyle[twocolumn,aps]{revtex}',"\n"; print '%',"\n"; print '% Following for twocolumn+wide abstract',"\n"; print '%\documentstyle[floats,aps]{revtex}',"\n"; print '%\twocolumn[\hsize\textwidth\columnwidth\hsize\csname',"\n"; print '%@twocolumnfalse\endcsname',"\n"; print '%\TITLE to \PACS',"\n"; print '%\vskip2pc]',"\n"; print '%\NARROWTEXT',"\n"; print '%',"\n"; print '\begin{document}',"\n"; print '\draft',"\n"; print "\n"; } # Test for fileutilities: $do_test = ""; if ( $do_test ) { foreach $i ('awk', 'ed', 'ex', 'grep', 'sed', 'vi',) { print "testing $i\n"; chop($TEST=`type $i | grep 'not found'`); if ( "$TEST" ne "" ) { print "Looks like you do not have $i on your system!\n"; print "Bye...\n"; exit 1; } } } # Test for required files if ( ! -f $SRC ) { print "jnl2revtex: cannot find $SRC, exiting\n"; exit 1; } if ( $DEFONLY eq "on" ) {goto DEFONLY_LABEL;} # More tests for required files $RETEX=FALSE; if ( ! -f $EQN ) { print "cannot find $EQN, Will re-TeX\n"; $RETEX=TRUE; } if ( ! -f $REF ) { print "cannot find $REF, Will re-TeX\n"; $RETEX=TRUE; } if ( "$RETEX" eq "TRUE" ) { chop($TEST1=`grep '\\equationfile' $SRC`); chop($TEST2=`grep '\\referencefile' $SRC`); $STOP=FALSE; if ( "$TEST1" eq "" ) { print "Umm, sourcefile $SRC has no \\equationfile line\n"; $STOP=TRUE; } if ( "$TEST2" eq "" ) { print "Umm, sourcefile $SRC has no \\referencefile line\n"; $STOP=TRUE; } if ( "$STOP" eq "TRUE" ) { exit 1; } print "\n"; system("$TEX $SRC"); print "\n"; } if ( ! -f $EQN || ! -f $REF ) { print "cannot find $EQN or $REF, please fix $SRC and try again...\n"; exit 1; } else { print "\n"; print "Looks ok for $EQN and $REF\n"; print "\n"; } # Ok, we have the files, let's get to work... #***************************************** if ( "$TRY_FIX_TOPMATTER" eq "off" ) { $STOP=""; open(SRC,"$SRC"); while () { # print $_ if ($. < 24); if ( $_ =~ /\\title/ && $_ !~ /{/ ) { print "\n"; print " \\title should have '{' close by, go put on same line $. to make me happy\n\n"; $STOP="TRUE"; } if ( $_ =~ /\\author/ && $_ !~ /{/ ) { print "\n"; print " \\author should have '{' close by, go put on same line $. to make me happy\n\n"; $STOP="TRUE"; } if ( $_ =~ /\\affil/ && $_ !~ /{/ ) { print "\n"; print " \\affil should have '{' close by, go put on same line $. to make me happy\n\n"; $STOP="TRUE"; } } if ( "$STOP" ) {exit 1;} } #***************************************** open(SRC,"$SRC"); @SRC = ; close(SRC); $STOP=""; for ($i = 0; $i < @SRC; $i++) { if ( $SRC[$i] =~ /\\eqalign/ && $SRC[$i] !~ /^\s*%/ ) { if ( $SRC[$i] =~ /{/ ) { $STOP="TRUE"; print "\\eqalign does not look OK...please fix near LINE $i\n"; print "$SRC[$i]"; } if ( $SRC[$i] =~ /\$\$/ ) { $STOP="TRUE"; print "\\eqalign does not look OK...please fix near LINE $i\n"; print "$SRC[$i]"; } if ( $SRC[$i - 1] !~ /\$\$/ ) { $STOP="TRUE"; print "\\eqalign does not look OK...please fix near LINE $i\n"; } if ( $SRC[$i + 1] !~ /{/ ) { $STOP="TRUE"; print "\\eqalign does not look OK...please fix near LINE $i\n"; } } } if ( "$STOP" ) {print "exiting....\n"; exit 1;} system "cp $SRC $PRESENT"; # Put PRESENT into IN &p2in; # First strip out TeX comments...at least those with first character '%' # Later, perhaps, trim partially commented lines. if ( "$KEEP_COMMENTS" eq 'off' ) { # system "perl -n -i -e 'print unless /^\\s*%/;' $IN"; &prep($IN,'print unless /^\s*%/;'); } #system "perl -n -i -e 'print unless /norevtex/;' $IN"; &prep($IN,'print unless /norevtex/;'); print "Comment and % norevtex lines out...\n\n"; # Let's do references print "\n", "Start References...\n"; open(IN,"$IN"); open(OUT,">$OUT"); while () { print OUT; last if /\\references/; } open(IN,"$IN"); open(REFIS0,">$REFIS0"); $on=""; while () { if ( /\\references/ ) {$on = "True";} print REFIS0 if $on; last if /\\endreferences/; } open(REFIS0,"$REFIS0"); $save=""; while () { if ( /\\refis\{(\w+)\}/ ) { $cutstart{$1} = $. - 1; $save = $1; } if ( /^\s*$/ && $save ) { $cutend{$save} = $. - 1; } } open(REFIS0,"$REFIS0"); # read in whole file @REFIS0 = ; open(REF,"$REF"); open(OUT,">>$OUT"); while () { if ( /\\refis \{(\w+)\}/ ) { foreach $i ($cutstart{$1} .. $cutend{$1}) { print OUT "$REFIS0[$i]"; } } } close(REF); close(OUT); open(IN,"$IN"); open(OUT,">>$OUT"); $on=""; while () { if ( /\\endreferences/ ) {$on = "True";} print OUT if $on; } close(OUT); close(IN); # Reload &out2p; &p2in; # Do it again, trying to snarf out unwanted spaces... if ( "$SAFE" eq "off" && "$GOODBOY" eq "off" ) { print "\nTry to trim spaces from \\refto and \\cite\n"; $edit = ""; foreach $key (keys(%cutstart)) { $edit .= " s/$key ,/$key,/g;"; $edit .= " s/, $key/,$key/g;"; } # print "edit line is:\n\n $edit\n"; system "perl -pi -e \'$edit\' $IN"; } # Change to revtex syntax #system "perl -pi -e 's/\\\\refis/\\\\bibitem/; s/\\\\references/\\\\begin{references}/; s/\\\\endreferences/\\\\end{references}/;' $IN"; &prep($IN,'s/\\\\refis/\\\\bibitem/; s/\\\\references/\\\\begin{references}/; s/\\\\endreferences/\\\\end{references}/;'); print "\nDid References...\n"; # Remove jnl top inputs, and ref/eqn inits foreach $i ('\\\\input.*jnl', '\\\\input.*reforder', '\\\\input.*eqnorder', '\\\\equationfile', '\\\\referencefile') { # system "perl -n -i -e 'print unless /$i/' $IN"; &prep($IN,"print unless /$i/"); } #print `date`,"\n"; print "jnl inputs out...\n"; # Dump in some jnl3 defs (first, of course): #\gdef\journal#1, #2, #3, 1#4#5#6{{\sl #1~}{\bf #2}, #3 (1#4#5#6)} open(DEFS,">$DEFS"); print DEFS <<'_end'; % %%%%%%%%%%%%%%% begin jnl3 defs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % My own jnl defs \def\head{\section} \def\subhead{\subsection} \def\singlespace{} \def\doublespace{} \def\triplespace{} % %\def\singlespace{\baselineskip=\normalbaselineskip} %\def\doublespace{\baselineskip=\normalbaselineskip \multiply\baselineskip by 2} %\def\triplespace{\baselineskip=\normalbaselineskip \multiply\baselineskip by 3} \def\pra {\journal Phys. Rev. A, } \def\prb {\journal Phys. Rev. B, } \def\prc {\journal Phys. Rev. C, } \def\prd {\journal Phys. Rev. D, } \def\prl {\journal Phys. Rev. Lett., } \def\pr {\journal Phys. Rev., } \def\apl {\journal Appl. Phys. Lett., } \def\jmp {\journal J. Math. Phys., } \def\jcp {\journal J. Chem. Phys., } \def\rmp {\journal Rev. Mod. Phys., } \def\jpc {\journal J. Phys. C. } \def\jpf {\journal J. Phys. F. } \def\cmp {\journal Comm. Math. Phys., } \def\np {\journal Nucl. Phys., } \def\pl {\journal Phys. Lett., } \def\apjl {\journal Astrophys. Jour. Lett., } \def\apj {\journal Astrophys. Jour., } \def\annp {\journal Ann. Phys. (N.Y.), } %%%%%%%%%%%%%% Various little user definitions %%%%%%%%%%%%%%%%%%%%%%%% \def\square{\kern1pt\vbox{\hrule height 1.2pt\hbox{\vrule width 1.2pt\hskip 3pt \vbox{\vskip 6pt}\hskip 3pt\vrule width 0.6pt}\hrule height 0.6pt}\kern1pt} \def\half {{ {1} \over {2} }} \def\third {{ {1} \over {3} }} \def\fourth {{ {1} \over {4} }} \def\12 {{1\over2}} \def\eg {{\it e.g.,\ }} \def\Eg {{\it E.g.,\ }} \def\ie {{\it i.e.,\ }} \def\Ie {{\it I.e.,\ }} \def\etal {{\it et al.\ }} \def\etc {{\it etc.\ }} \def\via {{\it via\ }} \def\cf {{\sl cf.\ }} \def\qed {\vrule height 1.2ex width 0.5em} \def\const {{\rm const}} %%%%%%%%%%%%%%% end jnl3 defs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% _end close(DEFS); DEFONLY_LABEL: # COME IN HERE FOR DEFONLY, don't forget strip comments, and clean if ( "$DEFONLY" eq "on" ) { system "cat $SRC > $PRESENT"; &p2in; system "rm -f $DEFS; touch $DEFS"; if ( "$KEEP_COMMENTS" eq "off" ) { # system "perl -n -i -e 'print unless /^\\s*%/;' $IN"; &prep($IN,'print unless /^\s*%/;'); } } # Pull out definitions, they better all be one per line!!!! #Xcat $IN | grep '\\def\\' >> $DEFS system "perl -n -e 'print if /\\\\def\\\\/' $IN >> $DEFS"; # Do a quick check: open(DEFS,"$DEFS"); $CHECK=""; while () { if ( !/^\s*%/ && !/}/ ) { $CHECK = "on"; } } if ( $CHECK && "$SAFE" eq "on" ) { print "Looks like TeX defs have extra stuff on lines, take a look:\n"; sleep 2; print "\n", system "cat $DEFS | more"; print "\n"; print "Should we continue? (y/n) "; $CONT = ; if ( "$CONT" eq "n" ) { print "OK, exiting\n"; &clean; exit 1; } } # Clean DEFS for him/her anyway... #X sed -e 's/ *$//' $DEFS > $DEFS2; cp $DEFS2 $DEFS # system "perl -pi -e 's/\\s*\$/\\n/' $DEFS"; &prep($DEFS,'s/\s*$/\n/'); # whew...there must be a better way! # Strip out defs #Xcat $IN | grep -v '\\def\\' > $OUT; out2p; p2in #system "perl -n -i -e 'print unless /\\\\def\\\\/' $IN"; &prep($IN,'print unless /\\\\def\\\\/'); print "Did Definition strip out...\n"; # Might as well put the top in if ( "$DEFONLY" eq "off" ) { open(OUT,">$OUT"); select OUT; &Top; close(OUT); select STDOUT; } elsif ( "$DEFONLY" eq "on" ) { system "echo '' > $OUT"; } # Put defs back in: open(OUT,">>$OUT"); print OUT "% ************************** begin definitions **************************\n"; print OUT "\n"; close(OUT); system "cat $DEFS >> $OUT"; open(OUT,">>$OUT"); print OUT "\n"; print OUT "% ************************** end definitions **************************\n\n"; close(OUT); # Put rest of document back in system "cat $IN >> $OUT"; &out2p; &p2in; # If we are asked to hardwire in expanded defs then... if ( "$REPLACE_DEF" eq "on" ) { open(DEFS,">$DEFS"); open(IN,"$IN"); while () { #X cat $IN | grep '^ *\\def\\' > $DEFS print DEFS if /^\s*\\def\\/; } close(IN); close(DEFS); open(IN,"$IN"); open(OUT,">$OUT"); while () { print OUT unless /^\s*\\def\\/; } #X cat $IN | grep -v '\\def\\' > $OUT; out2p; p2in # system "perl -n -i -e 'print unless /\\\\def\\\\/' $IN"; &prep($IN,'print unless /\\\\def\\\\/'); $testFix = 'yes'; if ( "$GOODBOY" eq "off" && ! $testFix ) { print "\nFix macros at very end of line:\n"; # now just in case one has a line ending in macro: \prl$ # Hmm which is correct, my brain hurts... open(DEFS,"$DEFS"); open(IN,"$IN"); @IN = ; while () { local($|) = 1; if ( /\\def\\(\w+)\{/ ) { print "."; ### &prep($IN,"s/\\\\$1\$/\\\\$1 /"); system "perl -pi -e 's/\\$1\$/\\$1 /' $IN"; ## for (@IN) { s/$1$/$1 /; } } } close(DEFS); ## open(IN,">$IN"); ## print IN @IN; close(IN); } elsif ( "$GOODBOY" eq "off" && $testFix ) { print "\nFix macros at very end of line:\n"; open(DEFS,"$DEFS"); $edit = ''; while () { if ( /\\def\\(\w+)\s*\{/ ) { $edit .= " s/\\\\$1\$/\\\\$1 /;"; } } close(DEFS); &prep($IN,$edit); } # Thanks to Cyrus Umrigar for this... #sed -e '/hyphenation/d' -e '/^$/d' -e '/^%/d' -e 's/\\/\\\\/g' -e s/\'/\''\\'\'\'/g -e 's;\\\\def; -e '\''s:;' -e 's;{;:;' -e 's;}$;:g'\''\\;' $DEFS > $DEFS2 open(JUG,">JUG"); print JUG <<'EOC'; sed -e '/hyphenation/d' -e '/^$/d' -e '/^%/d' -e 's/\\/\\\\/g' -e s/\'/\''\\'\'\'/g -e 's;\\\\def; -e '\''s:;' -e 's;{;:;' -e 's;}$;:g'\'' \\;' \ EOC print JUG "$DEFS > $DEFS2 \n"; close(JUG); system "/bin/sh JUG"; system "rm -f JUG"; system "echo '\$1 > \$2' >> $DEFS2"; print <<`EOC`; ex $DEFS2 > /dev/null <<_end 1s/^/sed / w q _end EOC system "chmod 755 $DEFS2"; system "cp $DEFS DEFS1_${BASE}_${$}"; system "cp $DEFS2 DEFS2_${BASE}_${$}"; print "\nDo full replacement of user \\def \n"; system "$DEFS2 $IN $OUT"; &out2p; &p2in; #Hmmm, if we do it again we get around the nested user defined # macros, eh? # Should move this to TAYLOR section and explain...TODO $MACTEST="on"; if ( "$MACTEST" eq "on" ) { $| = 1; print "...once more..."; system "$DEFS2 $IN $OUT"; &out2p; &p2in; print "...once more..."; system "$DEFS2 $IN $OUT"; &out2p; &p2in; print "\n"; } print "\nReplaced Standard Definitions with verbatim\n"; # EXIT HERE IF DEFONLY if ( "$DEFONLY" eq "on" ) { system "cp $IN $PRESENT"; system "cp $PRESENT $DEST"; print "\nDefs subbed into sourcefile $DEST\n"; &clean; exit 0; } $testing = "on"; if ( ! $testing ) { open(IN,"$IN"); open(OUT,">$OUT"); while () { print OUT if (!/def\\journal/ && !/^%.*def/ ); } close(OUT); close(IN); system "cp $OUT $IN"; print 'Now remove \\journal, GULP!!! (with vi no less!)',"\n"; #system "perl -p -i -e 's/^\\\\journal/ \\\\journal/' $IN"; &prep($IN,'s/^\\\\journal/ \\\\journal/'); # Store VI commands in $EDCMD open(EDCMD,">$EDCMD"); print EDCMD <<'EOQ'; /\\journal/ /,/ r@?\\journal? /@/ :s//}, {\\bf / 2-/\\journal/ /,/ /,/ r@?\\journal? /@/ :s//},/ 2-/\\journal/ /,/ /,/ /,/ wxPPr@ ?\\journal? /@/ :s//(/ 2-/\\journal/ /,/ /,/ /,/ eexPPlr@ ?\\journal? /@/ :s//)/ 2-/\\journal/ :s//{ \\sl / :wq EOQ close(EDCMD); open(JUG,">JUG"); print JUG <<"EOC"; grep '\\\\journal' $IN > $GOTBB while [ -s $GOTBB ] do echo -n "." vi $IN < $EDCMD > /dev/null grep '\\\\journal' $IN > $GOTBB done echo ""; echo "Well, removed journal I guess..." EOC close(JUG); close(IN); system("/bin/sh JUG"); } else { # test idea... open(IN,"$IN"); open(OUT,">$OUT"); while () { print OUT if (!/def\\journal/ && !/^%.*def/ ); } close(OUT); close(IN); system "cp $OUT $IN"; print 'Now remove \\journal',"\n"; open(IN,"$IN"); open(OUT,">$OUT"); while () { s/\\journal([^,]*),([^,]*),([^,]*),\s*(\w\w\w\w)/\{\{\\sl $1\~\}\{\\bf $2\}, $3 \($4\)\}/; print OUT; } close(IN); close(OUT); system "cp $OUT $IN"; open(IN,"$IN"); @IN = ; for (@IN) { if ( /\\journal/ ) { # check for leftover split line journal s/\n//; } } open(IN,">$IN"); print IN @IN; close(IN); open(IN,"$IN"); open(OUT,">$OUT"); while () { s/\\journal([^,]*),([^,]*),([^,]*),\s*(\w\w\w\w)/\{\{\\sl $1\~\}\{\\bf $2\}, $3 \($4\)\}/g; # note g print OUT; } close(IN); close(OUT); system "cp $OUT $IN"; } } # jnl topmatter: # (Should merge with $SAFE variable some{how,day} if ( "$TRY_FIX_TOPMATTER" eq "off" ) { # Change '\affil' to '\address' #X sed -e 's/\\affil/\\address/' $IN > $OUT; out2p; p2in # Change '\abstract' to stuff # Hope this is mutually exclusive of previous line... #X sed -e 's/\\abstract/\\date{\\today} \\maketitle \\begin{abstract}/' $IN > $OUT; out2p; p2in #X sed -e 's/\\prlabstract/\\date{\\today} \\maketitle \\begin{abstract}/' $IN > $OUT; out2p; p2in # Here's a real cheap one # Change 'PACS' to stuff #X sed -e 's/PAC/\\end{abstract} \\pacs{PAC/' $IN > $OUT; out2p; p2in #X sed -e 's/\\endtopmatter/} \\narrowtext/' $IN > $OUT; out2p; p2in # Hope he doesn't have both \endtopmatter and \body... #X sed -e 's/\\body/} \\narrowtext/' $IN > $OUT; out2p; p2in open(IN,"$IN"); @IN = ; for (@IN) { s/\\affil/\\address/; s/\\abstract/\\date{\\today} \\maketitle \\begin{abstract}/; s/\\prlabstract/\\date{\\today} \\maketitle \\begin{abstract}/; s/PAC/\\end{abstract} \\pacs{PAC/; s/\\endtopmatter/} \\narrowtext/; s/\\body/} \\narrowtext/; } open(IN,">$IN"); print IN @IN; close(IN); } elsif ( "$TRY_FIX_TOPMATTER" eq "on" ) { print "\n","Doing fancy topmatter fixin ","\n"; open(IN,"$IN"); open(OUT,">$OUT"); while () { last if ( /\\title/ || /\\topmatter/ ); print OUT; } close(OUT); open(IN,"$IN"); open(TOPS,">$TOPS"); open(BOTS,">BOTS"); $top=""; $bot=""; while () { if ( /\\title/ || /\\topmatter/ ) {$top = "on";} print TOPS if $top; print BOTS if $bot; if ( /\\endtopmatter/ || /\\body/ ) {$top = ""; $bot = "on";} } close(TOPS); close(BOTS); close(IN); # Strip blank lines # system "perl -n -i -e 'print unless /^\\s*\$/' $TOPS"; &prep($TOPS,'print unless /^\s*$/'); # Check for PACS occurence... $PACEXIST="TRUE"; chop($PACTEST = `grep 'PACS' $TOPS`); if ( "$PACTEST" eq "" ) { $PACEXIST="FALSE"; # system "perl -p -i -e 's/\\\\endtopmatter/PACS \\\\endtopmatter/' $TOPS"; # system "perl -p -i -e 's/\\\\body/PACS \\\\body/' $TOPS"; &prep($TOPS,'s/\\\\endtopmatter/PACS \\\\endtopmatter/'); &prep($TOPS,'s/\\\\body/PACS \\\\body/'); } open(TOPS,"$TOPS"); @TOPS = ; for (@TOPS) { s/\\title/\\title{/; s/\\author/} \\author{/; s/\\affil/} \\address{/; s/\\abstract/} \\date{\\today} \\maketitle \\begin{abstract}/; s/\\prlabstract/} \\date{\\today} \\maketitle \\begin{abstract}/; # Here's a real cheap one # Change 'PACS' to stuff s/PACS/\\end{abstract} \\pacs{PACS/; s/\\endtopmatter/} \\narrowtext/; # OR s/\\body/} \\narrowtext/; } open(TOPS,">$TOPS"); print TOPS @TOPS; close(TOPS); # OK TOPS ready... if ( "$PACEXIST" eq "FALSE" ) { # The customer is always right: # system "perl -pi -e 's/PACS/ /' $TOPS"; &prep($TOPS,'s/PACS/ /'); } system "cat $TOPS >> $OUT"; system "cat BOTS >> $OUT"; system "rm -f BOTS"; system "cp $OUT $IN"; } print "\nDid Topmatter...\n"; #*********************************************************************** # Bulk of paper now... # FORM IS: # $$ # \eqalign # { # blah # } # $$ print "\nBegin EQALIGN stuff\n"; # '&(' to '\eqno' #sed -e 's/&(/\\eqno(/' $IN > $OUT; out2p; p2in &prep($IN,'s/&\(/\\\\eqno\(/'); open(IN,"$IN"); @IN = ; for ($i = 0; $i < @IN; $i++) { $_ = $IN[$i]; if ( /\\eqalign/ ) { $IN[$i - 1] =~ s/\$\$/\\begin\{eqnarray\}/; $IN[$i] =~ s/\\eqalign/%/; $IN[$i + 1] =~ s/\{/%/; J1: for ($j = $i; $j < @IN; $j++) { $IN[$j] =~ s/&/&&/g; $IN[$j] =~ s/\\cr/\\nonumber\\\\/; if ( $IN[$j] =~ /\$\$/ ) { $IN[$j] =~ s/\$\$/\\end\{eqnarray\}/; $IN[$j - 1] =~ s/\}/%/; last J1; } } J2: for ($j = $i; $j < @IN; $j++) { if ( $IN[$j] =~ /(\\eqno\((\w*)\)\s*\\nonumber\\\\)/ ) { local($foo1) = $1; local($foo2) = $2; $foo1 =~ s/(\W)/\\\1/g; # print "Foo $foo1 $foo2\n"; $IN[$j] =~ s/$foo1/\\label\{$foo2\}/; last J2; } } } } open(IN,">$IN"); print IN @IN; close(IN); print "\nEnd EQALIGN stuff\n"; # '\refto' to '\cite' #sed -e 's/\\refto/\\cite/g' $IN > $OUT; out2p; p2in &prep($IN,'s/\\\\refto/\\\\cite/g'); # So many ways to say goodbye.... # '\endit' to '\end{document}' and other possibilities #sed -e 's/\\endit/\\end{document}/' $IN > $OUT; out2p; p2in #sed -e 's/\\endpaper/\\end{document}/' $IN > $OUT; out2p; p2in #sed -e 's/\\endjnl/\\end{document}/' $IN > $OUT; out2p; p2in #sed -e 's/\\enddocument/\\end{document}/' $IN > $OUT; out2p; p2in # Should reCHECK someday... #sed -e 's/\\end\\$/\\end{document}/' $IN > $OUT; out2p; p2in &prep($IN,'s/\\\\endit/\\\\end{document}/; s/\\\\endpaper/\\\\end{document}/; s/\\\\endjnl/\\\\end{document}/; s/\\\\enddocument/\\\\end{document}/;'); #sed -e 's/\\end\\$/\\end{document}/' $IN > $OUT; out2p; p2in &prep($IN,'s/\\\\end\\$/\\\\end{document}/'); # '\eqno' to '\label' #sed -e 's/\\eqno/\\label/g' $IN > $OUT; out2p; p2in &prep($IN,'s/\\\\eqno\\((\w*)\\)/\\\\label\\{\1\}/g'); # Equation labels.... open(EQN,"$EQN"); $igot = 0; while () { if ( /tag\s*\{(\w*)\}/ ) { $EQNL[$igot++] = $1; } } # system "perl -pi -e \'$edit\' $IN"; print "\nNow start equation labels...\n"; $edit = ""; foreach $i (@EQNL) { $edit .= " s/\\\\\\($i\\)/\\\\ref\\{$i\\}/g;"; } &prep($IN,$edit); print "\nDid all equation labels...\n"; print "Now many change all '\$\$' to \\begin{equation}\n"; #sleep 3 open(IN,"$IN"); @IN = ; open(IN,">$IN"); for (@IN) { # single liners: $$ ... $$ if ( /\$\$.*\$\$/ ) { s/\$\$//; print IN "\$\$\n"; } print IN $_; } #print IN @IN; close(IN); open(IN,"$IN"); @IN = ; open(IN,">$IN"); $blooking = "yes"; for (@IN) { if ( /\$\$/ ) { if ( $blooking ) { s/\$\$/\\begin\{equation\}/; $blooking = ''; } else { # Be Careful... s/\$\$/\\end\{equation\}/; $blooking = 'yes'; } } } print IN @IN; close(IN); for ($i = 0; $i < @IN; $i++) { $_ = $IN[$i]; if ( /\\begin\{equation/ ) { $gotlabel = ''; for ($j = $i; $j < @IN; $j++) { $gotlabel = 1 if ( $IN[$j] =~ /\\label/ ); if ( $IN[$j] =~ /\\end\{equation/ ) { $jhold = $j; last; } } if ( ! $gotlabel ) { $IN[$i] =~ s/\\begin\{equation\}/\$\$/; $IN[$jhold] =~ s/\\end\{equation\}/\$\$/; } } } print IN @IN; close(IN); print "\n Whew, done with \$\$ equations\n"; system "cp $IN $PRESENT"; print "\n Done!!!!\n"; # Make final version.... system "cp $PRESENT $DEST"; print "\nRevtex3.0 in sourcefile $DEST\n"; &clean; exit 0;