-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkbib
executable file
·168 lines (149 loc) · 6.71 KB
/
checkbib
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/bash
# Usage: checkbib [-l|--latex] [BIBFILE_NAME]
# checkbib does some basic checks on a bib file. It calls ./python/bibtex_check.py and biber.
# If -l|--latex is present, then checkbib checks the file as a BibLaTeX file; otherwise, it checks
# the file as a BibTeX file.
RELAXED_ENTRIES="Delbos_Gratton_Pauwels_Zhang_2023\|Gratton_Vicente_Zhang_2021\|Zhang_newuoas\|Huang_Zhang_2023\|Li_Zhang_2023\|_short"
BIBLATEX=0
BIBFILE=""
# Log files
LOG="$(basename -- "$0").log"
BCPYLOG="bcpy.log"
BIBERLOG="biber.log"
# Check whether biber is available with a high enough version.
BIBER_MINVER=2.14
if ! command -v biber &> /dev/null ; then
printf "\nbiber version >= %s is needed, but biber is not found.\n\n" "$BIBER_MINVER"
exit 3
fi
BIBER_VER="$(biber --version | grep -Eo '[0-9]\.[0-9]+' | head -1)"
if (( $(echo "$BIBER_MINVER > $BIBER_VER" | bc -l) )); then
printf "\nbiber version >= %s is needed, but the current version is %s.\n\n" "$BIBER_MINVER" "$BIBER_VER"
exit 3
fi
if [[ $# -gt 2 ]]; then
printf "Usage: checkbib [-l|--latex] [BIBFILE_NAME] \n"
exit 1
fi
# Parse the arguments
while [[ -n "$1" ]]; do
case "$1" in
-l|--latex)
BIBLATEX=1
;;
*)
if [[ -z "$BIBFILE" ]]; then
BIBFILE="$1"
fi
;;
esac
shift
done
# Get the name of the bib file with full path.
# If the input is empty, then use the latest bib file under the current directory.
if [[ -z "$BIBFILE" ]]; then
BIBFILE=$(find ./ -maxdepth 1 -type f -name "*.bib" -print0 | xargs -r -0 ls -1 -t | head -1)
fi
BIBFILE=$(readlink -f "$BIBFILE")
if [[ -z "${BIBFILE##*/}" ]]; then
printf "\nNo bib file found.\n"
exit 2
elif [[ ! -f "$BIBFILE" ]]; then
printf "\n%s does not exist.\n" "$BIBFILE"
exit 2
fi
# Get the directory where this script resides
TEXTOOLSDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
BCPYOUTPUT="bibtex_check.html"
if [[ $BIBLATEX -eq 1 ]] ; then
BCPY="python3 $TEXTOOLSDIR/python/bibtex_check.py -o $BCPYOUTPUT -l -b"
else
BCPY="python3 $TEXTOOLSDIR/python/bibtex_check.py -o $BCPYOUTPUT -b"
fi
if [[ $BIBLATEX -eq 1 ]] ; then
printf "\nChecking %s in BibLaTeX mode ...\n" "$BIBFILE"
printf "Result of checking %s in BibLaTeX mode\n" "$BIBFILE" > $LOG
else
printf "\nChecking %s in BibTeX mode ...\n" "$BIBFILE"
printf "Result of checking %s in BibTeX mode\n" "$BIBFILE" > $LOG
fi
printf "===> Looking for non-ASCII characters ...\n"
grep --color='auto' -P -n "[^\x00-\x7F]" "$BIBFILE" | sed "s|^|WARN - |" | grep --color='auto' -P -v '[\p{Han}]'
{
printf "===> Non-ASCII characters:\n"
grep -P -n "[^\x00-\x7F]" "$BIBFILE" | sed "s|^|WARN - |" | grep -P -v '[\p{Han}]'
} >> "$LOG"
printf "\n===> Checking the capital letters that need to be protected by curly braces ...\n"
{
printf "\n--------------------------------------------------\n"
printf "===> Capital letters that need to be protected by curly braces:\n"
} >> "$LOG"
CAPITAL_WORDS="Yuan Powell \
COBYLA UOBYQA NEWUOA BOBYQA LINCOA PDFO \
KKT Karush Kuhn Tucker \
Armijo BFGS Banach Bernoulli Bregman Broyden Cauchy DFP DFO Euclid Euclidean Euler \
Eulerian Fenchel Fortran GNU Gauss Gaussian Hermit Hermitian Hessian Hilbert Hilbertian \
Jacobi Jacobian Kronecker Lagrange Lagrangian Laplace Laplacian Lebesgue Levenberg Lipschitz \
Lipschitzian MATLAB Matlab Marquardt Moore Newton Newtonian ODE PDE Plateau Python RAS \
Riemann Riemannian Rockafellar SGD Schwarz Seidel Givens Householder Frobenius Schmidt \
Einstein Fenchel Moreau Young Minkowski Stiefel Grassmann Grassmannian Neumann Fischer Halmos \
Turing Knuth Dirichlet Poisson DtN Steklov Courant Hausdorff Hoffman Taylor Nesterov Polyak \
Lasso LASSO ADMM APG FISTA CPU FPU GPU Hadamard Weierstrass Liouville Abel Abelian Galois \
Hamilton Hamiltonian Atiyah Fourier Gronwall Bellman LaSalle Bihari Monte Carlo Sobolev \
Frank Wolfe \
Ky Fan \
Gram Schmidt \
Poincare Poincar.*\\\\'e.* Poincar.*\\\\'{e}.* \
Frechet Fr.*\\\\'e.*chet Fr.*\\\\'{e}.*chet \
Fejer Fej.*\\\\'e.*r Fej.*\\\\'{e}.*r Fejerian Fej.*\\\\'e.*rian Fej.*\\\\'{e}.*rian \
Holder H.*\\\\\"o.*lder H.*\\\\\"{o}.*lder Holderian H.*\\\\\"o.*lderian H.*\\\\\"{o}.*lderian \
KL K-L Kurdyka Lojasiewicz \\\\L.*ojasiewicz {\\\\L.*}.*ojasiewicz"
for WORD in $CAPITAL_WORDS ; do
grep -n "title\s*=" "$BIBFILE" | sed "s|^|WARN - |" | grep -v "{.*{.*$WORD.*}.*}" | grep -v "=\s*{$WORD" | grep --color='auto' "$WORD"
grep -n "title\s*=" "$BIBFILE" | sed "s|^|WARN - |" | grep -v "{.*{.*$WORD.*}.*}" | grep -v "=\s*{$WORD" | grep --color='auto' "$WORD" >> "$LOG"
done
printf "\n===> Running %s %s ...\n" "$BCPY" "$BIBFILE"
# Writing "$BCPY" in the next line will not work.
$BCPY "$BIBFILE" | grep "flawed name\|missing field\|wrong type\|non-unique id" \
| grep -v "arXiv" \
| sed "s|^<div id=|WARN - |" | sed "s|</li></ul><form class='bibTag_control'>.*$||" \
| sed "s|class='bibTag .*<ul class='enumprob'><li>|, |" | sed "s|</li><li>|, |" \
| grep -vi "'Reddi_Kale_Kumar_2018'.*missing field 'pages'" \
| grep -v "$RELAXED_ENTRIES" \
> $BCPYLOG 2>&1
cat $BCPYLOG
{
printf "\n--------------------------------------------------\n===> Message from %s:\n" "$BCPY"
cat $BCPYLOG
} >> "$LOG"
rm $BCPYLOG
rm $BCPYOUTPUT
printf "\n===> Running biber --tool -V %s ...\n" "$BIBFILE"
# Ignore warnings on `volume = {to appear}`.
# Ignore a few other unharmful warnings.
biber --tool -V "$BIBFILE" \
| grep -v "Invalid value of field 'volume' must be datatype 'integer' - ignoring field" \
| grep -v "INFO" | grep -v "_publisher" | grep -v "_number" | sed 's/skipping.*$//' \
| grep -vi "'Conn_Scheinberg_Toint_1998'.*missing mandatory field 'editor'" \
| grep -vi "'Gallard_etal_2018'.*missing mandatory field 'editor'" \
| grep -vi "'Kennedy_Martins_2013'.*missing mandatory field 'editor'" \
| grep -vi "'Yao_etal_2019'.*missing mandatory field 'editor'" \
| grep -vi "'Reddi_Kale_Kumar_2018'.*missing field 'pages'" \
| grep -v "$RELAXED_ENTRIES" \
> "$BIBERLOG" 2>&1
rm "$BIBFILE.blg"
BIBDIR="$(dirname "${BIBFILE}")"
BIBNAME="$(basename -- "$BIBFILE" | awk -F"." '{print $1}')"
rm -f "$BIBDIR"/"$BIBNAME"_bibertool.bib # This file will not be generated if $BIBFILE contains errors.
# biber 2.16 (as of 2021-04-03) produces ~/_bibertool.bib if it is invoked by
# "biber --tool -V FILE_WITH_FULL_PATH" and there exists a dot (.) in the full path of the directory
# containing the file.
rm -f ~/_bibertool.bib
cat $BIBERLOG
{
printf "\n--------------------------------------------------\n===> Message from biber:\n"
cat $BIBERLOG
} >> "$LOG"
rm $BIBERLOG
printf "\nDone. Log written in %s.\n\n" "$LOG"
exit 0