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:41 (modification of post by luc view diff)
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. #Written by: J.Barney
  10. #Last updated: 22.10.10
  11.  
  12. #Save working directory to come back to
  13. OLDDIR="`pwd`"
  14.  
  15. #Check directory
  16. echo ""
  17. read -p "Is you latex project in the current directory? y|[n]" switchdir
  18. echo ""
  19.  
  20. #Select directory besides the working one
  21. if [[ $switchdir =~ n|N|(no)|(No) ]] || [[ -z $switchdir ]]; then
  22.     texdirectory=$(zenity --file-selection --directory --title="Select DIRECTORY of the .tex file");
  23.     cd "$texdirectory"
  24. fi
  25.  
  26. #Optional backup
  27. read -p "Would you like to create a backup before compiling? [y]|n" backup
  28. if [[ $backup =~ y|Y|(yes)|(Yes)|(YES) ]] || [[ -z $backup ]]; then
  29.     CURDIR="`pwd`"
  30.     if [[ ! -e $CURDIR/backups ]]; then
  31.         echo "Backups directory not detected, making one..."
  32.         mkdir "$CURDIR/backups"
  33.     fi
  34.     BACKUPDATE=`date +%m_%d_at_%H_%M`
  35.     cd "$CURDIR/backups"
  36.     nice tar cvpzf backup_$BACKUPDATE.tar --exclude="$CURDIR/backups" "$CURDIR/*"
  37.     cd "$CURDIR"
  38. else
  39.     echo "Warning: We are NOT making a backup!"
  40.     echo ""
  41. fi
  42.  
  43. #Select .tex file
  44. #Check to see if there is only one file -- use it if so."
  45. if [[ `ls *.tex | wc -l` -gt 1 ]]; then
  46.     TEXLIST="`ls *.tex | sed 's/.tex$//'`"
  47.     echo "Select .tex file"
  48.     # TODO: warning this does not work with spaces in filenames!
  49.     select texfile in $TEXLIST
  50.     do
  51.         break
  52.     done
  53.     else
  54.         texfile="`ls *.tex`"
  55.         texfile="{texfile%.tex}"
  56.         echo "Using 1 found .tex file: $texfile"
  57. fi
  58. echo ""
  59.  
  60. #Check for .bib
  61. if [[ -e *.bib ]] ; then
  62.     read -p ".bib file found. Include it? [y]|n" biblio
  63.     echo ""
  64.     if [[ $biblio =~ y|Y|(yes)|(Yes)|(YES) ]] || [[ -z $biblio ]]; then
  65.         #reset biblio for easy reuse (see further down)
  66.         biblio="yes"
  67.         #Select if more than 1 .bib file
  68.         if [[ `ls *.bib | wc -l` -gt 1 ]]; then
  69.             BIBLIST="`ls *.bib | sed 's/.bib$//'`"
  70.             echo "Multiple .bibs found, select one"
  71.             # TODO: warning this does not work with spaces in filenames!
  72.             select biblioname in $BIBLIST
  73.             do
  74.                 break
  75.             done
  76.             echo ""
  77.             else
  78.                 biblioname="`ls *.bib`"
  79.                 biblioname="{biblioname%.bib}"
  80.                 echo "Using 1 found .bib file: $biblioname"
  81.                 sleep 2s
  82.         fi
  83.     else
  84.         #reset biblio for easy reuse (see further down)
  85.         biblio="no"
  86.     fi
  87. fi
  88.  
  89. latex "${texfile}.tex"
  90. #biblio was reset to be either "yes" or "no"
  91. if [[ $biblio = yes ]] ; then
  92.     bibtex "${biblioname}.bib"
  93. fi
  94. latex "${texfile}.tex"
  95. latex "${texfile}.tex"
  96. dvips "${texfile}.div"
  97. ps2pdf "${texfile}.ps" "${texfile}.pdf"
  98.  
  99. echo ""
  100. echo "Compilation complete."
  101. echo ""
  102. read -p "Create .rtf version now? [y]|n" rtfnow
  103. if [[ $rtfnow =~ y|Y|(yes)|(Yes)|(YES) ]] || [[ -z $rtfnow ]]; then
  104.     latex2rtf "${texfile}.tex"
  105. fi
  106. echo ""
  107. read -p "Create .html version now? [y]|n" htmlnow
  108. if [[ $htmlnow =~ y|Y|(yes)|(Yes)|(YES) ]] || [[ -z $htmlnow ]]; then
  109.     latex2html "${texfile}.tex"
  110. fi
  111. echo ""
  112. read -p "Open .pdf now? (Y/n): " opennow
  113. if [[ $opennow =~ y|Y|(yes)|(Yes)|(YES) ]] || [[ -z $opennow ]]; then
  114.         evince "${texfile}.pdf" &
  115. fi
  116. cd "$OLDDIR"
  117. exit 0
  118. #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