CrunchBang Linux Pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

CrunchBang Linux Pastebin

Posted by jmbarnes on Sat 23rd Oct 18:48 (modification of post by view diff)
download | new post

  1. #!/bin/bash
  2. #
  3. #A script to compile .tex files to .pdf (and optionally, .rtf or .html)
  4. #with bibliography support.
  5. #
  6. #Depends on: latex, bibtex, dvips, ps2pdf,
  7. #Suggests: latex2rtf, latex2html, evince (or any other pdf viewer)
  8. #
  9. #Started by: jmbarnes
  10. #moved along by: luc
  11. #
  12. #Last updated: 23.10.10
  13. #
  14. #USAGE:
  15. #Accepts the following command line arguments:
  16. #-d DIRECTORY -- directory to work from
  17. #-f TEXFILE -- name of .tex file to process
  18. #-b BIBFILE -- use named .bib file.
  19. #-s -- create a .tar backup
  20. #-h -- create an html version using latex2html
  21. #-r -- create an rtf version using latex2rtf
  22. #-o -- open the .pdf when finished
  23. #
  24. #EXAMPLE:
  25. #./latexcompile.sh -d ~/Dropbox/Paper -f thesis.tex -b references.bib -ho
  26. #This would: use "thesis.tex" from the Paper directory, process the
  27. #"references.bib" file, create an html version and open the .pdf. No .rtf would be created
  28. #
  29.  
  30.  
  31.  
  32. #Save working directory to come back to
  33. OLDDIR="`pwd`"
  34. PROG_NAME=$(basename $0)
  35.  
  36. #Set variables
  37. while getopts d:f:b:hors OPTION ; do
  38.         case ${OPTION} in
  39.             b) biblioname=$OPTARG
  40.                biblio=y ;;
  41.             d) workdir=$OPTARG ;;
  42.             f) texfile=$OPTARG ;;
  43.             h) htmlnow=y ;;
  44.             o) opennow=y ;;
  45.             r) rtfnow=y ;;
  46.             s) backup=y ;;
  47.             \?) print -u2 "Usage: ${PROG_NAME} [ -bhors -d workdir -b bibfile -f texfile ]"
  48.             exit 2;;
  49.         esac
  50. done
  51.  
  52. #Check directory if necessary
  53. if [ "$workdir" = "" ]; then
  54.     echo ""
  55.     read -p "Is you latex project in the current directory? y|[n] :" switchdir
  56.     echo ""
  57.     else
  58.         cd $workdir
  59. fi
  60.  
  61. #Select directory besides the working one
  62. if [ "$switchdir" = "n" ] || [ "$switchdir" = "N" ] || [ "$switchdir" = "no" ] || [ "$switchdir" = "No" ]; then
  63.     texdirectory=$(zenity --file-selection --directory --title="Select DIRECTORY of the .tex file");
  64.     cd $texdirectory
  65. fi
  66.  
  67. #Optional backup
  68. if [ "$backup" = "" ]; then
  69. read -p "Would you like to create a backup before compiling? y | [n] : " backup
  70. fi
  71. case $backup in
  72.     y | Y | yes | Yes )
  73.         CURDIR="`pwd`"
  74.         if [ ! -e "$CURDIR/backups" ]; then
  75.             echo "Backups directory not detected, making one..."
  76.             mkdir $CURDIR/backups
  77.         fi
  78.         BACKUPDATE=`date +%m_%d_at_%H_%M`
  79.         cd $CURDIR/backups
  80.         nice tar cvpzf backup_$BACKUPDATE.tar --exclude=$CURDIR/backups $CURDIR/*
  81.         cd $CURDIR
  82.     ;;
  83.     n | N | no | No )
  84.         echo "Warning: NO backup being made."
  85.         echo ""
  86.     ;;
  87. esac
  88.  
  89.  
  90. #Select .tex file
  91. if [ "$texfile" = "" ]; then
  92. if [[ `ls *.tex | wc -l` -gt 1 ]]; then
  93.     TEXLIST="`ls | grep .tex | sed 's/\(.*\)\..*/\1/'`"
  94.     echo "Select .tex file"
  95.     select texfile in $TEXLIST
  96.     do
  97.         break
  98.     done
  99.     else
  100.         texfile="`ls | grep .tex | sed 's/\(.*\)\..*/\1/'`"
  101.         echo "Using 1 found .tex file: $texfile"
  102. fi
  103. echo ""
  104. fi
  105.  
  106.  
  107. #Check for .bib
  108. if [ "$biblioname" = "" ]; then
  109. if [ -e *.bib ]; then
  110.     read -p ".bib file found. Include it? (y/n): " biblio
  111.     echo ""
  112.     if [ "$biblio" = "y" ] || [ "$biblio" = "Y" ] || [ "$biblio" = "yes" ] || [ "$biblio" = "Yes" ]; then
  113.         #Reset biblio for down-script ease
  114.         biblio="yes"
  115.         if [[ `ls *.bib | wc -l` -gt 1 ]]; then
  116.             BIBLIST="`ls | grep .bib | sed 's/\(.*\)\..*/\1/'`"
  117.             echo "Multiple .bibs found, select one"
  118.             select biblioname in $BIBLIST
  119.             do
  120.                 break
  121.             done
  122.             echo ""
  123.             else
  124.                 biblioname="`ls | grep .bib | sed 's/\(.*\)\..*/\1/'`"
  125.                 echo "Using 1 found .bib file: $biblioname"
  126.                 sleep 2s
  127.         fi
  128.     fi
  129. fi
  130. fi
  131.  
  132. #The actual compiling bit
  133. latex $texfile.tex
  134. if [ "$biblio" = "yes" ]; then
  135.     bibtex $biblioname.bib
  136. fi
  137. latex $texfile.tex
  138. latex $texfile.tex
  139. dvips $texfile.dvi
  140. ps2pdf $texfile.ps $texfile.pdf
  141.  
  142. echo ""
  143. echo "Compilation complete."
  144. echo ""
  145.  
  146. #Create rtf?
  147. if [ "$rtfnow" = "" ]; then
  148.     read -p "Create .rtf version now? (y/n): " rtfnow
  149. fi
  150. if [ "$rtfnow" = "y" ] || [ "$rtfnow" = "Y" ]; then
  151.     latex2rtf $texfile.tex
  152. fi
  153. echo ""
  154.  
  155. #Create html?
  156. if [ "$htmlnow" = "" ]; then
  157.     read -p "Create .html version now? (y/n): " htmlnow
  158. fi
  159. if [ "$htmlnow" = "y" ] || [ "$htmlnow" = "Y" ]; then
  160.     latex2html $texfile.tex
  161. fi
  162. echo ""
  163.  
  164. #Open pdf?
  165. if [ "$opennow" = "" ]; then
  166.     read -p "Open .pdf now? (Y/n): " opennow
  167. fi
  168. if [ "$opennow" = "Y" ] || [ "$opennow" = "y" ]; then
  169.         evince $texfile.pdf &
  170. fi
  171.  
  172.  
  173. cd $OLDDIR
  174. exit 0
  175. #end

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me