summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/pgfplots/pgf2pdf.sh
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2008-01-28 19:32:04 +0000
committerKarl Berry <karl@freefriends.org>2008-01-28 19:32:04 +0000
commita898113387e9657ab658eb9cccb60988c3a3a2cc (patch)
tree71a6fccd47c26e89685cad790a5b5930f3dc0483 /Master/texmf-dist/doc/latex/pgfplots/pgf2pdf.sh
parentfd2cf1cc29725cf8ee1100cbd37655a0c8f51f0b (diff)
new package pgfplots (26jan08)
git-svn-id: svn://tug.org/texlive/trunk@6435 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/latex/pgfplots/pgf2pdf.sh')
-rw-r--r--Master/texmf-dist/doc/latex/pgfplots/pgf2pdf.sh176
1 files changed, 176 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/latex/pgfplots/pgf2pdf.sh b/Master/texmf-dist/doc/latex/pgfplots/pgf2pdf.sh
new file mode 100644
index 00000000000..8af96cf3814
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/pgfplots/pgf2pdf.sh
@@ -0,0 +1,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