blob: 8af96cf3814c4e8cf65de450d05294d277b484f0 (
plain)
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
169
170
171
172
173
174
175
176
|
#!/bin/sh
TEX_FILE=""
TEX_LOG_FILE=""
TEX_DEFINES=""
OLD_DIR=`pwd`
DRIVER="dvipdfm"
DRIVER="pdftex"
ALSO_EPS_OUTPUT=0
function dumpHelp() {
echo -e \
"`basename $0` [OPTIONS] [--texdefs <defsfile> | --mainfile <latexmainfile>.tex ] [plot1.pgf plot2.pgf .... plotn.pgf]\n"\
"converts each plot*.pgf to plot*.pdf.\n"\
"This is done by running \n"\
" latex --jobname plot1 latexmainfile\n"\
"for each single plot. See the pgfmanual section \"Externalizing graphics\".\n"\
"Options:\n"\
"--eps\n"\
" will also produce eps output files.\n"\
"--driver D\n"\
" will use either \"dvipdfm\", \"dvips\" or \"pdflatex\"\n"\
" please note that only pdflatex works without additional\n"\
" work.\n"\
"--mainfile FILE\n"\
"--texdefs FILE\n"\
" Uses a clean tex file which inputs FILE and the PGF image to convert\n"\
" and processes this one.\n"\
""
exit 0;
}
LONGOPTS="mainfile:,eps,driver:,texdefs:"
SHORTOPTS="f:t:"
ARGS=`getopt -l "$LONGOPTS" "$SHORTOPTS" "$@"`
if [ $? -ne 0 ]; then
echo "`basename $0`: Could not process command line arguments. Use the '--help' option for documentation."
exit 1
fi
eval set -- "$ARGS"
while [ $# -gt 0 ]; do
ARG=$1
# echo "PROCESSING OPTION '$ARG' (next = $@)"
case "$ARG" in
--texdefs|-t) shift; TEX_DEFINES="$1"; shift;;
--driver) shift; DRIVER="$1"; shift;;
--mainfile|-f) shift; TEX_FILE="$1"; TEX_LOG_FILE="${1%%.tex}.log"; shift;;
--eps) shift; ALSO_EPS_OUTPUT=1; shift;;
--) shift; break;;
*) break;
esac
done
if [ -n "${TEX_DEFINES}" ]; then
if [ "${TEX_DEFINES:0:1}" != "/" ]; then
TEX_DEFINES=`pwd`/${TEX_DEFINES}
fi
fi
if [ $# -ne 0 ]; then
PGF_FILES=("$@")
elif [ -n "${TEX_LOG_FILE}" ]; then
# search for lines with
# (XXXX.pgf
PGF_FILES=(`sed -n '{s/.*(\([a-zA-Z0-9._-+^~]\+\.pgf\).*/\1/g;T ende;p};: ende' < $TEX_LOG_FILE`)
#PGF_FILES=(./errplot_L2.pgf)
else
echo "No input files." 1>&2
exit 1
fi
for A in "${PGF_FILES[@]}"; do
if [ ! -f "$A" ]; then
echo "$A not found: no such file" 1>&2
exit 1
fi
TARGET_FILE=$(sed -n '{s/.*\\beginpgfgraphicnamed{\(.*\)}.*/\1/g;T ende;p};: ende' < "$A")
if [ $? -ne 0 -o -z "$TARGET_FILE" ]; then
echo "There is no valid \\beginpgfgraphicnamed{TARGET}...\\endpgfgraphicnamed command in $A. Can't be exported to pdf. Please see the PGF manual for details." 1>&2
exit 1
fi
echo "processing \"$A\"" 1>&2
CMD="latex"
case $DRIVER in
pdftex|pdflatex)
CMD="pdflatex"
;;
esac
if [ -z "${TEX_DEFINES}" ]; then
cd `dirname "${TEX_FILE}"`
$CMD --interaction nonstopmode --jobname "$TARGET_FILE" "${TEX_FILE}" # 1>/dev/null
CODE=$?
cd $OLD_DIR
else
# Die Idee hier ist wie folgt:
# - Erstelle ein fast leeres Tex-File
# - darin steht NUR
# \input $TEX_DEFINES
# und
# \input $A
# - das TeX-file wird mit pgflatex uebersetzt
# - die ausgabe wird nach $TARGET_FILE geschrieben
# - fertig.
#
# BUGS:
# - TARGET_FILE != A wird nicht funktionieren (nur die endungen natuerlich)
DRIVER="pdftex"
cd `dirname "$A"`
BASE=`basename $TARGET_FILE`
TMP_TEX_FILE=`mktemp tmp_${BASE}_XXXXXX`
mv "$TMP_TEX_FILE" "${TMP_TEX_FILE}.tex"
TMP_TEX_FILE="$TMP_TEX_FILE.tex"
rm -f "${BASE}.pdf"
cat >"$TMP_TEX_FILE" <<-EOF
\documentclass[a4paper]{report}
\usepackage{german}
\usepackage[utf8]{inputenc} % erlaubt direkte Nutzung von Umlauten
%\usepackage{ifpdf}
%\usepackage{graphicx}
\usepackage[intlimits]{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
%\def\pgfsysdriver{pgfsys-dvipdfm.def}
%\def\pgfsysdriver{pgfsys-pdftex.def}
\usepackage{tikz}
\pgfrealjobname{${TMP_TEX_FILE%%.tex}}
\input{${TEX_DEFINES}}
\begin{document}
\let\oldjobname=\jobname%
% make sure that PGF recognises that jobname==target file name
% even if --jobname has a different path.
\def\jobname{${TARGET_FILE}}%
\input{`basename $A`}%
\let\jobname=\oldjobname
\end{document}
EOF
$CMD --interaction nonstopmode --jobname "$BASE" "${TMP_TEX_FILE}" 1>/dev/null
CODE=$?
if [ $CODE -eq 0 ]; then
rm -f "$TMP_TEX_FILE"
fi
cd $OLD_DIR
fi
if [ $CODE -ne 0 ]; then
echo -e "FAILED: could not convert\n\t$A\n->\t$TARGET_FILE";
rm -f "${TARGET_FILE}.pdf"
exit 1;
fi
CMD=""
case $DRIVER in
dvipdfm)
dvipdfm -o ${TARGET_FILE}.pdf "${TARGET_FILE}.dvi" || exit 1
pdfcrop "${TARGET_FILE}.pdf" "${TARGET_FILE}.pdf" || exit 1
;;
dvips)
dvipdfm -o ${TARGET_FILE}.ps "${TARGET_FILE}.dvi" || exit 1
;;
esac
if [ $ALSO_EPS_OUTPUT -eq 1 ]; then
pdftops -eps "${TARGET_FILE}.pdf" "${TARGET_FILE}.eps" || exit 1
fi
done
cd $OLD_DIR
|