#!/bin/csh -f #(ie run the cshell on this but don't read the .cshrc) echo version = 2.57 of l 2012 Apr 29 # 2012 Apr 29, 2.57: only remove if the paper name is not paper # 2012 Jan 06, 2.56: cp paper.pdf $name.pdf THEN remove the paper.pdf # 2011 Oct 14, 2.55: cp instead of mv so that skim doesn't restart! # 2011 Oct 14, 2.54: mv instead of cp for paper.pdf to final name # 2011 Oct 14, 2.53: handle version/name better when using latexdiff # 2011 Aug 09, 2.52: allow argument tex file # 2011 Jan 27, 2.51: no need for focus with new skim! # 2010 Nov 04, 2.50: err but bug # 2010 Nov 02, 2.49: deal with no version better # 2010 Nov 01, 2.48: not active # 2010 Nov 01, 2.47: show only one page of error log # 2010 Nov 01, 2.46: not functioning? - error is in showpdf # 2010 Oct 29, 2.45: focus on terminal after error # 2010 Oct 29, 2.44: dump xdvi - use skim instead; uses showpdf # 2010 Oct 09, 2.43: handle when no name is defined # 2010 Sep 16, 2.42: fully remove test of ssh - that's showpdf's issue # 2010 Sep 05, 2.41: allow dash in file name! # 2010 Sep 02, 2.40: switch to skim base # 2010 Mar 08, 2.39: detect ssh to adjust method # 2010 Mar 08, 2.38: remove creation of done directory - not used # 2009 Nov 10, 2.37: spell LOSING correctly # 2009 Jul 19, 2.36: when error, give the paper.log # 2009 Jul 11, 2.35: focus on Terminal after pdf display in OSX # 2009 Jul 11, 2.34: don't display empty pdf # 2009 Jul 11, 2.33: on MacOSX (Darwin) make pdf with time tag in /tmp # 2006 Dec 21, 2.32: error in Emergency stop detection # 2006 Dec 11, 2.31: write error location to file # 2006 Oct 09, 2.30: remove sleep in front of kickxdvi # 2006 Feb 10, 2.29: clean documentation a bit # 2005 Dec 12, 2.28: fix # on Mar 21 note. # 2005 Apr 18, 2.27: kickxdvi only once avoids killing xdvi? # 2005 Mar 22, 2.26: finish removing lockfile # 2005 Mar 21, 2.25: LaTeX.lock is a pain. Only turn on if there is a # -lock argument # 2004 Jun 29, 2.24: add 1 second of sleep before xrefresh to avoid # blowing xdvi away? this did not help # 2004 Feb 6, 2.23: LaTeX.lock mechanism - remove lock if no paper.tex # 2003 Nov 17, 2.22: LaTeX.lock mechanism - work with errors # 2003 Nov 16, 2.21: LaTeX.lock mechanism # 2003 Nov 4, 2.20: replace popcross with xrefresh! # 2003 Jan 25, 2.19: no clear at start # 2002 Oct 30, 2.18: return to /dev/null and popcross! # 2002 Oct 30, 2.17: replace cat /dev/null with -interaction=nonstopmode # 2002 Oct 21, 2.16: replace popcross with kickxdvi # 2000 Mar 6, 2.14: done is created as a directory (more useful than a file) # 1999 Nov 18: removal of a paper triggers bibtex call now # 1999 Aug 19: when done, `touch done` so that other # programs can be triggered (ie latex2html!) echo Run laTeX on paper.tex # Thomas D. Schneider, Ph.D. # National Institutes of Health # National Cancer Institute # Gene Regulation and Chromosome Biology Laboratory # Molecular Information Theory Group # Frederick, Maryland 21702-1201 # schneidt@mail.nih.gov # toms@alum.mit.edu (permanent) # http://alum.mit.edu/www/toms (permanent) if ($#argv == 0) then echo '' echo 'usage: l [optional tex file name]' echo 'The l script runs LaTeX on the paper.tex in the current directory.' echo 'If a name is given, then paper.tex is set to point to that name first.' echo '' echo 'If there are undefined citations, BibTeX is also run and LaTeX' echo 'rerun. This automates the calling of LaTex. Further automation' echo 'is done by the atp script and atchange. See:' echo 'http://alum.mit.edu/www/toms/atchange.html' echo '' echo 'The l script uses topostscript to automatically convert from' echo 'paper.dvi to paper.ps, a postscript version of the paper. The user' echo 'can then run ps2pdf to create a PDF if desired.' echo '' echo 'The l script uses a locking mechanism to prevent two copies from' echo 'running at the same time.' echo '' echo 'The l script uses a locking mechanism to prevent two copies from' echo 'running at the same time.' echo '' echo 'dependencies on other programs:' echo ' topostscript' echo ' showpdf' # echo ' focus' echo '' # exit endif if ($#argv == 0) then if !(-f paper.tex) then echo "No paper.tex file" exit endif else set name = `echo "$1"|sed 's/\.tex//'`.tex echo "the base name is $name" if ("$name" == '.tex') then echo "$1 does not end with '.tex'" exit endif if (-e paper.tex) then if ("`readlink paper.tex`" == "$1") then echo "paper.tex link found" echo "leaving it alone, it matches $1" else echo "removing link that does not match $name" rm -f paper.tex lk paper.tex ${name} endif else lk paper.tex ${name} endif endif set beep = "" # the name of the paper: set paper = "paper" if !(-f ${paper}.tex) then echo "${paper}.tex does not exist" exit endif echo "processing paper.tex -> `readlink ${paper}.tex`" # the location in the paper of an error found: set paperline = "$paper.lin" # locking mechanism: LOCK set dolock = false if ($#argv > 0) then if ("$1" == '-lock') then set doloc = true endif endif if ($dolock == true) then set lockfile = LaTeX.lock if (-f $lockfile) then echo "The l script is already running in this directory\!" echo `pwd` echo `ls $lockfile` echo "If this is in error, remove the file $lockfile" echo "and l will proceed to run LaTeX." rm -i $lockfile if (-f $lockfile) then echo "Ok, l is shutting down." exit else echo "$lockfile is gone, l is continuing." endif endif # if the lock was removed, make a new one. if !(-f $lockfile) then echo "$lockfile" > $lockfile echo "The l script is running." >> $lockfile echo `date` >> $lockfile endif else set lockfile = "/dummy-file-name-for-lockfile-mechanism" endif if !(-f $paper.tex) then echo $paper.tex does not exist\! # make a beep sound: echo -n "$beep" # locking mechanism: UNLOCK if (-f $lockfile) then rm -f $lockfile endif exit endif # This script has to have a mechanism to update the xdvi display of # the paper. The original solution was 'popcross', a script that # would put up a cross consisting of two thin windows (or, later, just # a single horizontal window and then removing them. This would # triggger xdvi to referesh, but it is an ugly solution. The simple # solution is to use the Xwindows refresh function. The method has # been tested under Gnome. It is a great final solution! #set kickxdvi = xrefresh # You can replace refresh with setxdvi when one has a modern xdvi! # set overfull = Overfull set overfull = NoOverfull echo ALL $overfull MESSAGES WILL BE SUPPRESSED # see Lamport page 177 for dealing with overfull boxes. # basically, do this: # \documentclass[12pt,draft]{article} # draft will mark the overfull boxes and the solution # will become obvious... # run latex. The cat /dev/null prevents # latex from stopping. Errors are reported to paper.log cat /dev/null | latex $paper | grep -v $overfull # 2002 Oct 30: A cleaner way to do this: # latex paper -interaction=nonstopmode | grep -v $overfull # THIS DOES NOT POP UP THE ERROR DISPLAY!!! # determine the name to call the paper if (-f ${paper}.tex) then echo "The tex file exists, get the name and version" # set v = "`grep 'version = ' ${paper}.tex|head -1|tr -cd '[:alnum:]- .'`" # set v = "`grep 'version = ' ${paper}.tex|head -1`" # for latexdiff, avoid % version lines! set v = "`grep 'version = ' ${paper}.tex|grep -v '^%'|head -1`" if ("$v" == '') then set name = "$paper" set version = 'no_version' else #set version = `echo "$v"|clmn 2` #set name = `echo "$v"|clmn 4|sed 's/\.tex//'` # The above hardwired for position instead of the version string and 'of'. # set vline = `echo "$v"|sed 's/version/@/'|tr '@' '\n'|head -2|tail -1` set vline = `echo "$v"|sed 's/version =/@/'|tr '@' '\n'|head -2|tail -1` set version = `echo "$vline"|clmn 1` set name = `echo "$vline"|clmn 3|sed 's/\.tex//'` echo "version line is '${v}'" echo "version is '$version'" echo "name is '$name'" cp ${paper}.pdf ${name}.pdf # mv ${paper}.pdf ${name}.pdf endif else echo "The tex file does not exist, name" endif echo "name: ${name}; version: ${version}" # zq # say $name $version # from here on use $name # set stoptag = '\! Emergency stop.' set stoptag = ' Emergency stop.' set stopline = `grep "${stoptag}" ${paper}.log` #echo paper is $paper #say "$stoptag" #echo "$stopline" #say "$stopline" # if ("`grep 'Emergency stop' ${paper}.log`" == '') then if ("${stopline}" == '') then # THE PAPER IS OK - proceed echo Test if bibtex call is needed # The warning we watch for is like: # LaTeX Warning: # Citation `Lin.Riggs1975' on page 13 undefined on input line 1381 set tmp = /tmp/`whoami`.paper.bibtest grep "LaTeX Warning: Citation" $paper.log |\ grep "undefined" $paper.log |\ wc -l | sed -e "s/ //g" > $tmp # cat $tmp if (`cat $tmp` == 0) then echo references ok else echo "NEW REFERENCE CITATION: calling BiBTeX\!" # show current status bibtex $paper cat /dev/null | latex $paper | grep -v $overfull cat /dev/null | latex $paper | grep -v $overfull endif # 1999 Nov 18 # The method above does not detect *removal* of a paper # we can detect this as a difference between the # number of \citation{ and \bibcite{ lines in paper.aux: set citation = `grep "\citation{" $paper.aux | wc -l` set bibcite = `grep "\bibcite{" $paper.aux | wc -l` if !($citation == bibcite) then echo "LOSING REFERENCE CITATION: calling BiBTeX\!" bibtex $paper cat /dev/null | latex $paper | grep -v $overfull cat /dev/null | latex $paper | grep -v $overfull endif topostscript $paper echo -n "$beep" # is $paper.ps empty? if (`head -1 $paper.ps | wc -l` == 0) then echo "empty $paper.ps file" exit endif ps2pdf $paper.ps # mv paper.pdf $name.pdf # Don't move it - skim would restart # Instead, copy and then remove: if ("$name" != 'paper') then cp paper.pdf $name.pdf rm -f paper.pdf endif if (`uname` == "Darwin") then # set ttyssh = `env | grep SSH_TTY` # # force non-ssh method - silently # set ttyssh = '' # if ($ttyssh == '') then # let showpdf figure out how to show the results # echo NOT using ssh - open directly echo "showpdf ${name}.pdf" showpdf ${name}.pdf # focus # back on the terminal # else # echo using ssh - open directly # # transmit a renamed version # set timetag = `date "+%Y%b%d-%H-%M-%S"` # echo pdf time tag is $timetag # set tmppdf = /tmp/`whoami`${timetag}.pdf # echo pdf with time tag is $tmppdf # cp $paper.pdf $tmppdf # #open $tmppdf # showpdf $tmppdf # focus # back on the terminal # endif endif rm -f $tmp else # begin latexerrors %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% echo ERROR FOUND say error found # RECORD LINE OF ERROR in $paperline # example error line: # l.113 } set errortag = "`grep '^l\.' $paper.log | tail -1`" echo "$errortag" set line = `echo "$errortag"| tr -dc "[:digit:]"` echo "at line $line" # errors are recorded as NEGATIVE error lines echo "-$line" > "$paperline" echo DISPLAY LaTeX ERRORS set err = "`whoami`-${name}" set tmperr = "/tmp/${err}.tex" echo "\documentstyle[12pt]{article}" > $tmperr echo "\begin{document}" >> "$tmperr" echo "\begin{verbatim}" >> "$tmperr" # cat paper.log >> $tmperr # 2010 Nov 01: only show the relevant part of the log set stopline = `grep --line-number "$stoptag" $paper.log|tr ':' ' '|clmn 1` echo "line number of '$stoptag' in paper.log file is: $stopline" @ afterstop = $stopline + 15 cat "paper.log" |\ head -$afterstop |\ tail -30 >> $tmperr echo "\end{verbatim}" >> $tmperr echo "\end{document}" >> $tmperr pushd /tmp # latex $err.tex latex $tmperr # creates $err.dvi # echo xdvi display shows the last page of the errors set page = '' # xdvi $err.dvi +$page & # xdvi is a pain - takes too much control topostscript $err.dvi # line numbers don't work # echo "showpdf $err.dvi.ps -l $stopline $tmperr" # showpdf $err.dvi.ps -l $stopline $tmperr showpdf $err.dvi.ps # focus >> /dev/null # back on the terminal echo $tmperr ========================= echo $err ========================= popd # end latexerrors %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% echo > paper.dvi #$kickxdvi & echo "****************************************" set error = "* ERROR IN PAPER - fix paper.tex file\! *" echo "$error" echo cat paper.log # new as of 2009 jul 19 echo # echo "$error" echo "************* $error ***************************" # beep echo -n "$beep" sleep 2 # beep echo -n "$beep" pushd /tmp rm -f $err.aux $err.dvi $err.log $err.tex popd endif # rm -f $okrun if ($dolock == true) then # locking mechanism: UNLOCK if (-f $lockfile) then rm -f $lockfile else echo "l script: Something is wrong, there was no $lockfile $beep" endif endif