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.

128 lines
3.3 KiB

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