-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountTeXCommands
More file actions
executable file
·44 lines (39 loc) · 982 Bytes
/
countTeXCommands
File metadata and controls
executable file
·44 lines (39 loc) · 982 Bytes
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
#/usr/bin/env zsh
#
# countTeXCommands: make a ranklist of TeX \-commands used.
# For newcommand and begin, also collect the arguments.
# sjd
#
for x in $@; do
echo "arg |$x|"
done
args=""
verbose=""
while [[ "$#" > 0 ]]; do case "$1" in
-h|--help) cat <<EOF
Ussage:
countTeXCommands
This runs a pipe to extract TEX commands from a file(s), and report frequency.
Options:
--args: Also include their arguments.
EOF
return;;
-a|--args) args=1;;
-v|--verbose) verbose=1;;
*) break;;
esac; shift;
done
cmd='((begin|end)\{[^}]*\}|[a-zA-Z][a-zA-Z]*)'
cb='\{[^}]*\}'
sb='[^\\\\]*]'
expr="(\\\\$cmd($cb|$sb)*)"
[ $verbose ] && echo "cmd $cmd; cb $cb; sb $sb; expr $expr"
for x in $*; do
echo "arg |$x|"
done
if ! [[ $args ]]; then
[ $verbose ] && echo "No args..."
command grep -hoE "(\\\\$cmd)" $@ | sort -f | uniq -c -i | sort -rn --key=1,1
else
command grep -hoE "($expr)" "$@" | sort -f | uniq -c -i | sort -rn --key=1,1
fi