-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmakedependlatex
executable file
·70 lines (57 loc) · 2.72 KB
/
makedependlatex
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
#!/bin/bash
# Copyright 2012 Wenjun Deng <wdeng@wdeng.info>
# This file is part of Omega Tools.
# Omega Tools is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# Omega Tools is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with Omega Tools. If not, see <http://www.gnu.org/licenses/>.
VERSION='2012-07-05 14:55:16-04:00'
if [ -z "${1}" ];
then
echo
echo "makedependlatex version ${VERSION}"
echo
echo "Generate dependency file from latex source to include in Makefile."
echo
echo "Usage: makedependlatex <latex file name> [target file name]"
echo
exit
fi
if [ ! -f ${1} ];
then
echo "File ${1} does not exist."
exit 1
fi
dependfile=`echo ${1} | sed 's/\(\.[^\.]*\)\?$/.d/'`
pdffile=`echo ${1} | sed 's/\(\.[^\.]*\)\?$/.pdf/'`
dvifile=`echo ${1} | sed 's/\(\.[^\.]*\)\?$/.dvi/'`
#target=`echo ${1} | sed 's/\(\.[^\.]*\)\?$//'`
if [ -n "${2}" ];
then
pdffile=`echo ${2} | sed 's/\(\.[^\.]*\)\?$/.pdf/'`
dvifile=`echo ${2} | sed 's/\(\.[^\.]*\)\?$/.dvi/'`
fi
# find input/include files
# if one line has multiple figures, only one of them will be found. this needs to be fixed.
# if a line has "\%", the following operation will treat it as a commented line. this needs to be fixed.
sed -n 's/^[^%]*\\\(input\|include\){\(.*\)}/\2/p' ${1} | sed 's/\(.*\)/\n\1.d : \1.tex\n\tmakedependlatex \1.tex '"${pdffile}"'\n\n-include \1.d/' > ${dependfile}1
sed -n 's/^[^%]*\\\(input\|include\){\(.*\)}/\2.tex/p' ${1} > ${dependfile}
# find figures
# if one line has multiple figures, only one of them will be found. this needs to be fixed.
# if a line has "\%", the following operation will treat it as a commented line. this needs to be fixed.
sed -n 's/^[^%]*\\\(includegraphics\|begin{overpic}\)\(\[.*\]\)\?{\(.*\)}.*$/\3/p' ${1} >> ${dependfile}
# find bib files
# if a line has "\%", the following operation will treat it as a commented line. this needs to be fixed.
sed -n 's/^[^%]*\\bibliography{\(.*\)}/\1,/p' ${1} | sed 's/,/.bib\n/g' >> ${dependfile}
sort -u ${dependfile} -o ${dependfile}~
paste -s --delimiters=" " ${dependfile}~ > ${dependfile}
sed "s/^.*$/# Generated by makedependlatex version ${VERSION}\n# Generated at `date`\n\n${pdffile} : &\n\n${dvifile} : &/" < ${dependfile} > ${dependfile}~
#mv ${dependfile}~ ${dependfile}
cat ${dependfile}~ ${dependfile}1 > ${dependfile}
rm -f ${dependfile}~ ${dependfile}1