|
| 1 | +#!/usr/bin/evn bash |
| 2 | + |
| 3 | +# https://www.nongnu.org/chktex/ChkTeX.pdf |
| 4 | + |
| 5 | +utils_dir=$(cd $(dirname $0) || exit 1; pwd) |
| 6 | +cd ${utils_dir} |
| 7 | + |
| 8 | +SRC_DIR=${SRC_DIR:=$(dirname $utils_dir)} |
| 9 | +BLD_DIR=${BLD_DIR:=${SRC_DIR}/cmake-build-release} |
| 10 | + |
| 11 | +latex_warn_edit() { |
| 12 | + local error_code="$1" |
| 13 | + local error_file="$2" |
| 14 | + |
| 15 | + if [[ -z "$error_code" || -z "$error_file" ]]; then |
| 16 | + echo "Usage: latex_warn_edit <error_code> <output_file>" >&2 |
| 17 | + return 2 |
| 18 | + fi |
| 19 | + |
| 20 | + if [[ ! -f /tmp/ALL_LATEX_WARNINGS ]]; then |
| 21 | + echo "ERROR: /tmp/ALL_LATEX_WARNINGS does not exist" >&2 |
| 22 | + return 1 |
| 23 | + fi |
| 24 | + |
| 25 | + grep "CODE=${error_code} " /tmp/ALL_LATEX_WARNINGS > "$error_file" |
| 26 | + |
| 27 | + if [[ ! -s "$error_file" ]]; then |
| 28 | + echo "No warnings found for CODE=${error_code}" |
| 29 | + return 0 |
| 30 | + fi |
| 31 | + vim -q "$error_file" |
| 32 | +} |
| 33 | + |
| 34 | +cat ${BLD_DIR}/ITKSoftwareGuide-build/SoftwareGuide/LaTeXWrapper.sh |fgrep -v TEXINPUTS |
| 35 | +cd ${BLD_DIR}/ITKSoftwareGuide-build |
| 36 | + |
| 37 | +export TEXINPUTS=.:${SRC_DIR}/SoftwareGuide/../Latex:${SRC_DIR}/SoftwareGuide:${SRC_DIR}/SoftwareGuide/Latex:${SRC_DIR}/SoftwareGuide/Art:${BLD_DIR}/ITKSoftwareGuide-build/SoftwareGuide:${BLD_DIR}/ITKSoftwareGuide-build/SoftwareGuide/Examples:${BLD_DIR}/ITKSoftwareGuide-build/SoftwareGuide/Art:${BLD_DIR}/ITKSoftwareGuide-build/SoftwareGuide/Latex: |
| 38 | + |
| 39 | +cat > ${utils_dir}/.chktexrc << EOF |
| 40 | +# Add directories to TeX input search path |
| 41 | +TeXInputs = { |
| 42 | +${SRC_DIR}/SoftwareGuide/../Latex |
| 43 | +${SRC_DIR}/SoftwareGuide |
| 44 | +${SRC_DIR}/SoftwareGuide/Latex |
| 45 | +${SRC_DIR}/SoftwareGuide/Art |
| 46 | +${BLD_DIR}/ITKSoftwareGuide-build/SoftwareGuide |
| 47 | +${BLD_DIR}/ITKSoftwareGuide-build/SoftwareGuide/Examples |
| 48 | +${BLD_DIR}/ITKSoftwareGuide-build/SoftwareGuide/Art |
| 49 | +${BLD_DIR}/ITKSoftwareGuide-build/SoftwareGuide/Latex |
| 50 | +} |
| 51 | +EOF |
| 52 | + |
| 53 | +IGNORE_WARNING_CODES=" -n 1 -n 3 -n 8 -n 12 -n 13 -n 36 -n 37" |
| 54 | + |
| 55 | +chktex \ |
| 56 | + --localrc ${utils_dir}/.chktexrc \ |
| 57 | + ${IGNORE_WARNING_CODES} \ |
| 58 | + --format '%f:%l:%c: CODE=%n MESSAGE=%m!n' \ |
| 59 | + ${SRC_DIR}/SoftwareGuide/Latex/ITKSoftwareGuide-Book*.tex \ |
| 60 | + |sed 's/!n/\n/g' \ |
| 61 | + > /tmp/ALL_LATEX_WARNINGS |
| 62 | + |
| 63 | + echo vim -q /tmp/ALL_LATEX_WARNINGS |
| 64 | + |
| 65 | + cat /tmp/ALL_LATEX_WARNINGS |grep "ITKSoftwareGuide-build/SoftwareGuide/Examples" > /tmp/CXX_LATEX_WARNINGS |
| 66 | + cat /tmp/ALL_LATEX_WARNINGS |grep -v "ITKSoftwareGuide-build/SoftwareGuide/Examples" > /tmp/GUIDE_LATEX_WARNINGS |
| 67 | + |
| 68 | + |
| 69 | +cat /dev/null << EOF_FILE |
| 70 | +#latex_warn_edit 27 could_not_execute_command |
| 71 | +latex_warn_edit 3 enclose_parenthesis |
| 72 | +latex_warn_edit 0000 delete_space_pagereferences |
| 73 | +latex_warn_edit 9 mismatch_blocks # Not all are relavant for fixing |
| 74 | +latex_warn_edit 10 solo_block_delimiter |
| 75 | +latex_warn_edit 11 use_ldots |
| 76 | +latex_warn_edit 12 error.interword_spacing #Not recommended to be fixed |
| 77 | +latex_warn_edit 13 error.intersentence_spacing #Not recommended to be fixed |
| 78 | +latex_warn_edit 15 no_match_paren |
| 79 | +latex_warn_edit 17 match_paren |
| 80 | +latex_warn_edit 18 avoid_doublequotes |
| 81 | +latex_warn_edit 26 remove_spaces_in_front_of_punctuation |
| 82 | +latex_warn_edit 29 make_times_prettier |
| 83 | +latex_warn_edit 31 text_maybe_ignored |
| 84 | +latex_warn_edit 32 single_quote_begin |
| 85 | +latex_warn_edit 35 use_cos_instead |
| 86 | +latex_warn_edit 36 space_in_front_parenthesis # too many false positives in correct code |
| 87 | +latex_warn_edit 37 space_after_parenthesis # too many false positives in correct code |
| 88 | +latex_warn_edit 39 double_space_found |
| 89 | +latex_warn_edit 44 misc_regex_concerns |
| 90 | +
|
| 91 | +# These are pedantic codes that like make the code worse for trying to fix: |
| 92 | +# CODE=1 MESSAGE=Command terminated with space. |
| 93 | +# CODE=3 MESSAGE=You should enclose the previous parenthesis with '{}'. FALSE ALARMS SEE You should enclose the previous parenthesis with '{}'. |
| 94 | +# CODE=8 MESSAGE=Wrong length of dash may have been used. |
| 95 | +# CODE=12 MESSAGE=Interword spacing ('\ ') should perhaps be used. |
| 96 | +# CODE=13 MESSAGE=Intersentence spacing ('\@') should perhaps be used. |
| 97 | +# CODE=36 MESSAGE=You should put a space in front of parenthesis. |
| 98 | +# CODE=37 MESSAGE=You should avoid spaces after parenthesis. |
| 99 | +# CODE=37 MESSAGE=You should avoid spaces in front of parenthesis. |
| 100 | +
|
| 101 | +# |
| 102 | +# Error codes found by chktex |
| 103 | +# CODE=9 MESSAGE=')' expected, found '}'. |
| 104 | +# CODE=9 MESSAGE=']' expected, found '}'. |
| 105 | +# CODE=9 MESSAGE='}' expected, found ')'. |
| 106 | +# CODE=9 MESSAGE='}' expected, found ']'. |
| 107 | +# CODE=10 MESSAGE=Solo ')' found. |
| 108 | +# CODE=10 MESSAGE=Solo '}' found. |
| 109 | +# CODE=11 MESSAGE=You should use \ldots to achieve an ellipsis. |
| 110 | +# CODE=15 MESSAGE=No match found for '('. |
| 111 | +# CODE=17 MESSAGE=Number of '(' doesn't match the number of ')'! |
| 112 | +# CODE=17 MESSAGE=Number of '{' doesn't match the number of '}'! |
| 113 | +# CODE=18 MESSAGE=Use either '' or '' as an alternative to '"'. |
| 114 | +# CODE=26 MESSAGE=You ought to remove spaces in front of punctuation. |
| 115 | +# CODE=27 MESSAGE=Could not execute LaTeX command. |
| 116 | +# CODE=29 MESSAGE=$\times$ may look prettier here. |
| 117 | +# CODE=31 MESSAGE=This text may be ignored. |
| 118 | +# CODE=32 MESSAGE=Use ' to begin quotation, not '. |
| 119 | +# CODE=35 MESSAGE=You should perhaps use '\cos' instead. |
| 120 | +# CODE=39 MESSAGE=Double space found. |
| 121 | +# CODE=44 MESSAGE=User Regex: -2:Use \toprule, \midrule, or \bottomrule from booktabs. |
| 122 | +# CODE=44 MESSAGE=User Regex: -2:Vertical rules in tables are ugly. |
| 123 | +# CODE=44 MESSAGE=User Regex: 1:Capitalize before references. |
| 124 | +EOF_FILE |
0 commit comments