#!/bin/tcsh -f #(ie run the tshell on this but don't read the .cshrc or .tcshrc) set ver = "version = 1.02 of replacebib 2009 Nov 14" # 2009 Nov 14, 1.02: improve version description # 2009 Jun 26, 1.01: functional - add author documentation # 2009 Jun 26, 1.00: origin if ($#argv == 0) then echo 'replacebib [source name] [target name]' echo echo 'Replace the bibliography calls in a LaTeX document' echo 'with the bibliography text itself.' echo 'This is required by PNAS as described in the instructions at' echo 'http://www.pnas.org/site/misc/LaTex.shtml' echo echo 'The source is the latex file to use as input.' echo 'The target is the latex file with the bibliography inserted.' echo echo 'SET UP:' echo echo '1. Below your \begin{document} line put this line:' echo '\bibliographystyle{pnas}' echo 'Use the pnas.bst file available from' echo 'http://www.ccrnp.ncifcrf.gov/~toms/latex.html' echo "(Note: You can use any format, this program won't care.)" echo echo '2. At the point where your bibliograph should go, insert:' echo '\bibliography{all}' echo 'where "all" is the name of your bibliograph database eg "all.bib".' echo 'This is just above "\end{article}" for the PNAS style.' echo echo '3. Use the pnas.bst file available from' echo 'http://www.ccrnp.ncifcrf.gov/~toms/latex.html' echo echo '4. Run latex to create your source.bbl file.' echo echo 'WHAT THIS PROGRAM DOES:' echo echo 'Remove the \bibliographystyle{pnas} line.' echo 'Replace \bibliography{...} with the source bbl file.' echo echo 'If there is only one argument (any token) then:' echo '- the source is set to "paper"' echo '- the target is set using the version name.' echo 'The version name is on a line containing "version = "'. echo 'The version name is a space delimited word containing ".tex".' # found by the ver program:' # echo 'http://www.ccrnp.ncifcrf.gov/~toms/delila/ver.html' # echo '(This coded into replacebib so there is no dependency.)' echo echo 'For example if your paper contains:' echo ' \newcommand{\theversion}%' echo ' {{version = 1.88 of emmgeo.tex 2009 Nov 10}}' echo 'and you run this script with the argument "-bib":' echo ' replacebib -bib' echo 'then the target name will be "emmgeo-bib.tex"' echo echo 'RESULTS:' echo echo 'The output target file is generated.' echo 'The program reports the line where the biblography was inserted' echo 'and show the first few and last difference lines' echo 'between the input and output files.' echo 'You should verify that the \bibliographystyle{pnas}' echo 'line is gone and that the entire bibliography has been inserted.' echo echo "permanent location of this program:" echo "http://alum.mit.edu/www/toms/ftp/replacebib" echo echo "$ver" echo " Dr. Thomas D. Schneider" echo " National Institutes of Health" echo " schneidt@mail.nih.gov" echo " toms@alum.mit.edu (permanent)" echo " http://alum.mit.edu/www/toms (permanent)" exit endif if ($#argv == 1) then set source = 'paper' # now use paper.tex to find the target name if !(-f ${source}.tex) then echo "There is no ${source}.tex file." exit #else # echo "${source}.tex exists." endif set version = "`grep 'version =' ${source}.tex`" if ("$version" == '') then echo 'No version line exists - HALT' exit endif echo "Using version line:" echo "$version" set rawtarget = `echo "$version" | tr ' ' '\n' | grep '.tex' ` set target = `echo "$rawtarget" | sed "s/.tex/$1/"` else set source = `echo $1 | sed 's/.tex//'` set target = `echo $2 | sed 's/.tex//'` endif if !(-f ${source}.tex) then echo There is no ${source}.tex file. exit else echo "source ${source}.tex exists." endif if !(-f ${source}.bbl) then echo There is no ${source}.bbl file. exit else echo "source ${source}.bbl exists." endif echo the target name is: "${target}.tex" if ("${target}.tex" == "${source}.tex") then echo "${source}.tex = ${target}.tex - HALT to avoid overwriting source" exit endif # grep '\bibliography{' ${source}.tex set breakpoint = `grep -n '\bibliography{' ${source}.tex|tr ':' '\n' |head -1` if ("$breakpoint" == '') then echo "'\bibliography{' is NOT in ${source}.tex" exit endif echo "'\bibliography{' is in ${source}.tex at line $breakpoint" @ headpart = $breakpoint - 1 head -${headpart} ${source}.tex |\ grep -v '\bibliographystyle{' |\ cat > ${target}.tex # echo "new stuff" >> ${target}.tex cat "${source}.bbl" >> ${target}.tex tail +${breakpoint} ${source}.tex |\ cat >> ${target}.tex #cat ${target}.tex echo "------- diff ${source}.tex ${target}.tex | head" diff ${source}.tex ${target}.tex | head echo "------- diff ${source}.tex ${target}.tex | tail" diff ${source}.tex ${target}.tex | tail echo "-------"