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 luc on Sat 23rd Oct 17:45 (modification of post by view diff)
View followups from luc | 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. #Written by: J.Barney
  10. #Last updated: 22.10.10
  11.  
  12. #Save working directory to come back to
  13. olddir="`pwd`"
  14.  
  15. # we did not jet get any options
  16. interactive=TRUE
  17.  
  18. # set default values for interactive usage
  19. PROG_NAME=$(basename $0)
  20. biblio=FALSE
  21. htmlnow=FALSE
  22. rtfnow=FALSE
  23. opennow=FALSE
  24. workdir=FALSE
  25. backup=FALSE
  26.  
  27. while getopts bd:f:hor OPTION ; do
  28.     interactive=FALSE
  29.     case ${OPTION} in
  30.         b) biblio=TRUE ;;
  31.         d) workdir=$OPTARG ;;
  32.         f) texfile=$OPTARG ;;
  33.         h) htmlnow=TRUE ;;
  34.         o) opennow=TRUE ;;
  35.         r) rtfnow=TRUE ;;
  36.         s) bachup=TRUE ;;
  37.        \?) print -u2 "Usage: ${PROG_NAME} [ -bhors -d workdir -b bibfile -f texfile ]"
  38.            exit 2;;
  39.     esac
  40. done
  41.  
  42. # echo $biblio
  43. # echo $workdir
  44. # echo $texfile
  45. # echo $htmlnow
  46. # echo $opennow
  47. # echo $rtfnow
  48. # echo $backup
  49.  
  50. #Check directory
  51. if [[ $interactive = TRUE ]] ; then
  52.     echo ""
  53.     read -p "Is you latex project in the current directory? y|[n]" workdir
  54.     echo ""
  55. fi
  56. #Select directory besides the working one
  57. if [[ $workdir =~ n|N|(no)|(No)|(FALSE) ]] || [[ -z $workdir ]]; then
  58.     workdir=$(zenity --file-selection --directory --title="Select DIRECTORY of the .tex file");
  59. else workdir="$olddir"
  60. fi
  61. cd "$workdir"
  62.  
  63. #Optional backup
  64. if [[ $interactive = TRUE ]] ; then
  65.     read -p "Would you like to create a backup before compiling? [y]|n" backup
  66. fi
  67. if [[ $backup =~ y|Y|(yes)|(Yes)|(YES)|(TRUE) ]] || [[ -z $backup ]]; then
  68.     workdir="`pwd`"
  69.     mkdir -p "$workdir/backups"
  70.     # why use "nice" here?
  71.     nice tar cvpzf backups/backup_`date +%m_%d_at_%H_%M`.tar --exclude="$workdir/backups" "$workdir/*"
  72. else
  73.     echo "Warning: We are NOT making a backup!"
  74.     echo ""
  75. fi
  76.  
  77. #Select .tex file
  78. if [[ $texfile = FALSE ]] ; then
  79.     #Check to see if there is only one file -- use it if so."
  80.     if [[ `ls *.tex | wc -l` -gt 1 ]]; then
  81.         TEXLIST="`ls *.tex | sed 's/.tex$//'`"
  82.         echo "Select .tex file"
  83.         # TODO: warning this does not work with spaces in filenames!
  84.         select texfile in $TEXLIST
  85.         do
  86.             break
  87.         done
  88.         else
  89.             texfile="`ls *.tex`"
  90.             texfile="{texfile%.tex}"
  91.             echo "Using 1 found .tex file: $texfile"
  92.     fi
  93.     echo ""
  94.  
  95. fi
  96.  
  97. #Check for .bib
  98. if [[ $interactive = TRUE ]] && [[ -e *.bib ]] ; then
  99.     read -p ".bib file found. Include it? [y]|n" biblio
  100.     echo ""
  101.     if [[ $biblio =~ y|Y|(yes)|(Yes)|(YES) ]] || [[ -z $biblio ]]; then
  102.         #reset biblio for easy reuse (see further down)
  103.         biblio=TRUE
  104.         #Select if more than 1 .bib file
  105.         if [[ `ls *.bib | wc -l` -gt 1 ]]; then
  106.             BIBLIST="`ls *.bib | sed 's/.bib$//'`"
  107.             echo "Multiple .bibs found, select one"
  108.             # TODO: warning this does not work with spaces in filenames!
  109.             select biblioname in $BIBLIST
  110.             do
  111.                 break
  112.             done
  113.             echo ""
  114.             else
  115.                 biblioname="`ls *.bib`"
  116.                 biblioname="{biblioname%.bib}"
  117.                 echo "Using 1 found .bib file: $biblioname"
  118.                 sleep 2s
  119.         fi
  120.     else
  121.         #reset biblio for easy reuse (see further down)
  122.         biblio=FALSE
  123.     fi
  124. fi
  125.  
  126. latex "${texfile}.tex"
  127. #biblio was reset to be either "yes" or "no"
  128. if [[ $biblio = yes ]] ; then
  129.     bibtex "${biblioname}.bib"
  130. fi
  131. latex "${texfile}.tex"
  132. latex "${texfile}.tex"
  133. dvips "${texfile}.div"
  134. ps2pdf "${texfile}.ps" "${texfile}.pdf"
  135.  
  136. echo ""
  137. echo "Compilation complete."
  138. echo ""
  139.  
  140. if [[ $interactive = TRUE ]] ; then
  141.     read -p "Create .rtf version now? [y]|n" rtfnow
  142.     if [[ $rtfnow =~ y|Y|(yes)|(Yes)|(YES) ]] || [[ -z $rtfnow ]]; then
  143.         latex2rtf "${texfile}.tex"
  144.     fi
  145.     echo ""
  146. fi
  147. if [[ $interactive = TRUE ]] ; then
  148.     read -p "Create .html version now? [y]|n" htmlnow
  149.     if [[ $htmlnow =~ y|Y|(yes)|(Yes)|(YES) ]] || [[ -z $htmlnow ]]; then
  150.         latex2html "${texfile}.tex"
  151.     fi
  152.     echo ""
  153. fi
  154. if [[ $interactive = TRUE ]] ; then
  155.     read -p "Open .pdf now? (Y/n): " opennow
  156.     if [[ $opennow =~ y|Y|(yes)|(Yes)|(YES) ]] || [[ -z $opennow ]]; then
  157.         evince "${texfile}.pdf" &
  158.     fi
  159. fi
  160. cd "$olddir"
  161. exit 0
  162. #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