You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
3.3 KiB

5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
  1. #!/bin/bash
  2. . util/util.sh
  3. TOGGLEFILE=util/toggle.tex
  4. CHAPTERFILE=util/chapter.tex
  5. ALLCHAPTERFILE=util/allchapter.tex
  6. FILENAMEPREFIX=questionnaire
  7. SINK=/dev/null
  8. VALID_ARGS="abdh"
  9. BURST=0
  10. DEBUG=0
  11. ANNOTATE=0
  12. printUsage() {
  13. printf "A shell wrapper for this questionnaire using latexmk.\n"
  14. printf "Currently this wrapper supports compiling of the whole script and a burst mode,\nas well as three different <version>s: 'blank', solution, spacing and all which will compile all three in one run.\n\n"
  15. printf "Usage: ./compile <flags> <version> \n"
  16. printf "Flags:\n"
  17. printf " -b Compile in burst mode, i.e. each chapter into a individual file.\n"
  18. printf " -d Print LuaLaTeX output to terminal.\n"
  19. printf " -a Annotate all questions and solutions with their base filename.\n"
  20. printf " -h Print this help message and exit.\n"
  21. }
  22. while getopts $VALID_ARGS op
  23. do
  24. case ${op} in
  25. b) BURST=1
  26. ;;
  27. d) DEBUG=1
  28. ;;
  29. a) ANNOTATE=1
  30. ;;
  31. h) printUsage
  32. info "Exiting..."
  33. exit
  34. ;;
  35. esac
  36. done
  37. set_chapter() {
  38. printf "$1\n" > $CHAPTERFILE
  39. }
  40. do_annotate() {
  41. echo "\\annotatetrue" >> $TOGGLEFILE
  42. }
  43. rename() {
  44. filename="$FILENAMEPREFIX"
  45. while [ $# -gt 0 ]
  46. do
  47. filename="${filename}_$1"
  48. shift
  49. done
  50. cp main.pdf $filename.pdf
  51. }
  52. compile_file() {
  53. local mode=$1
  54. local chapter=$2
  55. if [ $mode = "solution" ]
  56. then
  57. echo "\solutiontrue" > $TOGGLEFILE
  58. [ $ANNOTATE -eq 1 ] && do_annotate
  59. [ "$#" -eq 1 ] && info "Compiling questionnaire with solutions." || info "Compiling chapter $chapter with solutions."
  60. [ $DEBUG -eq 1 ] && make pdf || make pdf >> $SINK 2>&1
  61. rename "with_solutions" $chapter
  62. elif [ $mode = "spacing" ]
  63. then
  64. echo "\spacingtrue" > $TOGGLEFILE
  65. [ $ANNOTATE -eq 1 ] && do_annotate
  66. [ "$#" -eq 1 ] && info "Compiling questionnaire with space for your solutions." || info "Compiling chapter $chapter with space for your solutions."
  67. [ $DEBUG -eq 1 ] && make pdf || make pdf >> $SINK 2>&1
  68. rename "with_spacing" $chapter
  69. fi
  70. }
  71. compile_simple_file() {
  72. [ "$#" -eq 0 ] && info "Compiling whole questionnaire." || info "Compiling chapter $1 from the questionnaire."
  73. echo "" > $TOGGLEFILE
  74. [ $ANNOTATE -eq 1 ] && do_annotate
  75. [ $DEBUG -eq 1 ] && make all || make all >> $SINK 2>&1
  76. rename $1
  77. }
  78. compile_wrapper() {
  79. [ $BURST -eq 1 ] && local chapter=$1 && shift
  80. option_processed=0
  81. for arg in "$@"
  82. do
  83. [ $arg = "solution" ] && compile_file solution $chapter && option_processed=1
  84. [ $arg = "spacing" ] && compile_file spacing $chapter && option_processed=1
  85. [ $arg = "normal" ] && compile_simple_file $chapter && option_processed=1
  86. [ $arg = "all" ] && compile_simple_file $chapter && compile_file spacing $chapter && compile_file solution $chapter && option_processed=1
  87. done
  88. [ $option_processed -eq 0 ] && compile_simple_file $chapter
  89. }
  90. compile_chapter() {
  91. #for chapter in smtzthree proplogic satsolver ndpred predlogic ndpred smt bdd eqchecking symbenc temporal
  92. for chapter in smtzthree eqchecking
  93. do
  94. set_chapter "\\chapter${chapter}true"
  95. compile_wrapper "$chapter" "$@"
  96. done
  97. }
  98. compile_complete() {
  99. cp $ALLCHAPTERFILE $CHAPTERFILE
  100. compile_wrapper "$@"
  101. }
  102. main() {
  103. if [ $BURST -eq 1 ]
  104. then
  105. rm -f main.pdf
  106. compile_chapter "$@"
  107. else
  108. compile_complete "$@"
  109. fi
  110. }
  111. main "$@"
  112. ls -altr *pdf