-
Notifications
You must be signed in to change notification settings - Fork 20
/
texsize
executable file
·82 lines (70 loc) · 1.87 KB
/
texsize
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
#!/bin/bash
# -*- coding: utf-8 -*-
#
# texsize
#
# purpose: list graphics file included in latex doc, and their size
# license: MIT License
# author: François-Xavier Coudert
# e-mail: [email protected]
# updated: 2014-05-12
#
if [ $# -ne 1 ] ; then
echo "Usage: $0 basename"
exit 1
fi
if ! ( [ -e "$1.log" ] && [ -e "$1.pdf" ] ) ; then
echo "Error: '$1.log' and '$1.pdf' should exist"
exit 1
fi
function filesize {
# This is ugly, and portable
wc -c < $1
# GNU stat variant
#stat -Lf '%z'
# BSD stat variant
#stat -Lc '%s'
}
function humansize {
awk "BEGIN{sum=$1;
hum[1024**3]=\"GB\";hum[1024**2]=\"MB\";hum[1024]=\"kB\";
for (x=1024**3; x>=1024; x/=1024){
if (sum>=x) { printf \"%5.1f %s\",sum/x,hum[x];break }
}}"
}
# Find list of included files
LC_ALL=C
inc=`tr '\n' '#' < $1.log \
| sed -e 's/#//g' -e 's/</#</g' | tr '#' '\n' \
| grep '<' | sed -e 's/>.*//' -e 's/<//' \
| egrep -v '(pfb|cmap)$' | egrep -v '^use ' \
| sed -e 's/,.*//' | grep -v ' ' | sed -e 's@^\./@@' \
| sort | uniq `
# Only those that exist (same false positives otherwise)
files=""
for i in $inc ; do
if [ -e "$i" ]; then
files="$files $i"
fi
done
# Check that we have at least one file
if [ "x$files" = "x" ]; then
echo "No figure included in this document"
exit 1
fi
sorted=`ls -lLrS $files | sed 's/.* //'`
pdfsize=`filesize $1.pdf`
sum="0"
echo "List of included figures sorted by ascending size:"
for i in $sorted ; do
s=`filesize $i`
sum=`echo "$sum + $s" | bc -l`
printf "% 40s : " $i
humansize $s
printf " (%.1f%%)\n" `echo "100.0 * $s / $pdfsize" | bc -l`
done
echo "-------------------------------------------------------------"
echo " Total PDF size: $pdfsize /" `humansize $pdfsize`
echo -n " Total graphics size:" `humansize $sum`
printf " (%.1f%%)\n" `echo "100.0 * $sum / $pdfsize" | bc -l`
exit 0