mktexproj (1690B)
1 #!/bin/sh 2 3 help() { 4 echo "Usage: $(basename -- "$0") -h" 5 echo "-h :" 6 echo " Displays usage information" 7 echo "-n <folder_name> :" 8 echo " Creates a new latex project folder, with the given name." 9 echo "-t <title> :" 10 echo " Sets the document title." 11 } 12 13 DIRNAME= 14 TITLE= 15 16 OPTSTRING="ht:n:" 17 while getopts "${OPTSTRING}" OPT; do 18 case "${OPT}" in 19 h) 20 help && exit 1 21 ;; 22 t) 23 [ ! "${OPTARG}" = "" ] && TITLE="${OPTARG}" 24 ;; 25 n) 26 [ ! "${OPTARG}" = "" ] && DIRNAME="${OPTARG}" 27 ;; 28 default) 29 help 30 ;; 31 esac 32 done 33 34 [ "${DIRNAME}" = "" ] && \ 35 echo "Incorrect usage! No project name given (see -h)!" && exit 1 36 37 [ "${TITLE}" = "" ] && \ 38 echo "Incorrect usage! No project title given (see -h)!" && exit 1 39 40 mkdir -p "$DIRNAME" 41 42 ## create the skeleton document if it doesnt exist 43 cat > "$DIRNAME/document.tex" <<EOF 44 \\documentclass{article} 45 46 \\usepackage[utf8]{inputenc} 47 \\usepackage{amsmath} 48 \\usepackage{listings} 49 50 \\setcounter{tocdepth}{1} % show sections 51 \\setcounter{tocdepth}{2} % + subsections 52 \\setcounter{tocdepth}{3} % + subsubsections 53 %\\setcounter{tocdepth}{4} % + paragraphs 54 %\\setcounter{tocdepth}{5} % + subparagraphs 55 56 \\author{MikoĊaj Lenczewski} 57 \\title{$TITLE} 58 59 \\begin{document} 60 61 \\maketitle 62 \\newpage 63 64 \\tableofcontents 65 \\newpage 66 67 Hello, World! 68 69 \\end{document} 70 EOF 71 72 ## create the build script 73 cat > "$DIRNAME/build" <<'EOF' 74 #!/bin/sh 75 76 . "$(dirname $0)/common.sh" 77 78 pdflatex "$OPTS" "$SRC" 79 EOF 80 81 chmod +x "$DIRNAME/build" 82 83 ## create the build options script 84 cat > "$DIRNAME/common.sh" <<EOF 85 #!/bin/sh 86 87 export ROOT="$(dirname $0)" 88 export OUT="$ROOT/out" 89 export OPTS="-output-directory=\$OUT" 90 export SRC="$ROOT/document.tex" 91 92 [ ! -d \$OUT ] && mkdir \$OUT 93 EOF