Krazy fixes (mainly i18n)
[kdenetwork.git] / kopete / plugins / latex / kopete_latexconvert.sh
blob71ee04f80f2926f20df09b49e355003dc6b009bb
1 #!/bin/sh
2 #############################################################
3 # TEX2IM: Converts LaTeX formulas to pixel graphics which #
4 # can be easily included in Text-Processors like #
5 # M$ or Staroffice. #
6 # #
7 # Required software: latex, convert (image magic) #
8 # to get color, the latex color package is required #
9 #############################################################
10 # Version 1.8 (http://www.nought.de/tex2im.html) #
11 # published under the GNU public licence (GPL) #
12 # (c) 14. May 2004 by Andreas Reigber #
13 # Email: anderl@nought.de #
14 #############################################################
17 # Default values
20 resolution="150x150"
21 format="png"
22 color1="white"
23 color2="black"
24 trans=1
25 noformula=0
26 aa=1
27 extra_header="$HOME/.tex2im_header"
29 if [ -f ~/.tex2imrc ]; then
30 source ~/.tex2imrc
33 OPTERR=0
35 if [ $# -lt 1 ]; then
36 echo "Usage: `basename $0` [options] file.tex, for help give option -h" 1>&2
37 exit 1
40 while getopts hanzb:t:f:o:r:vx: Optionen; do
41 case $Optionen in
42 h) echo "tex2im [options] latex_expression
44 The content of input file should be _plain_ latex mathmode code!
45 Alternatively, a string containing the latex code can be specified.
47 Options:
48 -v show version
49 -h show help
50 -a change status of antialiasing
51 default is on for normal mode and
52 off for transparent mode
53 -o file specifies output filename,
54 default is inputfile with new extension
55 -f expr specifies output format,
56 possible examples: gif, jpg, tif......
57 all formates supported by 'convert' should work,
58 default: png
59 -r expr specifies desired resolution in dpi,
60 possible examples: 100x100, 300x300, 200x150,
61 default is 150x150
62 -b expr specifies the background color
63 default: white
64 -t expr specifies the text color
65 default: black
66 -n no-formula mode (do not wrap in eqnarray* environment)
67 default: off
68 -z transparent background
69 default: off
70 -x file file containing extra header lines.
71 default: ~/.tex2im_header"
72 exit 0 ;;
73 v) echo "TEX2IM Version 1.8"
74 exit 0 ;;
75 r) resolution=$OPTARG;;
76 o) outfile=$OPTARG;;
77 z) trans=1
78 aa=0;;
79 a) if [ $aa -eq 0 ]; then
80 aa=1
81 else
82 aa=0
83 fi;;
84 n) noformula=1;;
85 b) color1=$OPTARG;;
86 t) color2=$OPTARG;;
87 f) format=$OPTARG;;
88 x) extra_header=$OPTARG;;
89 esac
90 done
93 # Generate temporary directory
96 if test -n "`type -p mktemp`" ; then
97 tmpdir="`mktemp /tmp/tex2imXXXXXX`"
98 rm $tmpdir
99 mkdir $tmpdir
100 else
101 tmpdir=/tmp/tex2im$$
102 if [ -e $tmpdir ] ; then
103 echo "$0: Temporary directory $tmpdir already exists." 1>&2
104 exit 1
106 mkdir $tmpdir
108 homedir="`pwd`" || exit 1
111 # Names for input and output files
114 while [ $OPTIND -le $# ]
117 eval infile=\$${OPTIND}
119 if [ -z $outfile ]; then
120 if [ -e "$infile" ]; then
121 base=`basename ${infile} .tex` ;
122 outfile=${base}.$format
123 else
124 outfile=out.$format
129 # Here we go
133 cat << ENDHEADER1
134 \documentclass[12pt]{article}
135 \usepackage{color}
136 \usepackage{amsmath,latexsym,amsfonts,amssymb,ulem}
137 \usepackage[dvips]{graphicx}
138 \pagestyle{empty}
139 ENDHEADER1
140 ) > $tmpdir/out.tex
143 # Do we have a file containing extra files to include into the header?
146 if [ -f $extra_header ]; then
148 cat $extra_header
149 ) >> $tmpdir/out.tex
152 if [ $noformula -eq 1 ]; then
154 cat << ENDHEADER2
155 \pagecolor{$color1}
156 \begin{document}
157 {\color{$color2}
158 ENDHEADER2
159 ) >> $tmpdir/out.tex
160 else
162 cat << ENDHEADER2
163 \pagecolor{$color1}
164 \begin{document}
165 {\color{$color2}
166 \begin{eqnarray*}
167 ENDHEADER2
168 ) >> $tmpdir/out.tex
171 # Kopete does not need to parse the content of a file.
172 #if [ -e "$infile" ]; then
173 # cat $infile >> $tmpdir/out.tex
174 #else
175 echo "$infile" >> $tmpdir/out.tex
178 if [ $noformula -eq 1 ]; then
180 cat << ENDFOOTER
181 }\end{document}
182 ENDFOOTER
183 ) >> $tmpdir/out.tex
184 else
186 cat << ENDFOOTER
187 \end{eqnarray*}}
188 \end{document}
189 ENDFOOTER
190 ) >> $tmpdir/out.tex
193 cd $tmpdir
194 for f in $homedir/*.eps; do
195 test -f ${f##*/} || ln -s $f . # multi-processing!
196 done
197 latex -interaction=batchmode out.tex > /dev/null
198 cd "$homedir"
199 dvips -o $tmpdir/out.eps -E $tmpdir/out.dvi 2> /dev/null
202 # Transparent background
205 if [ $trans -eq 1 ]; then
206 if [ $aa -eq 1 ]; then
207 convert +adjoin -antialias -transparent $color1 -density $resolution $tmpdir/out.eps $tmpdir/out.$format
208 else
209 convert +adjoin +antialias -transparent $color1 -density $resolution $tmpdir/out.eps $tmpdir/out.$format
211 else
212 if [ $aa -eq 1 ]; then
213 convert +adjoin -antialias -density $resolution $tmpdir/out.eps $tmpdir/out.$format
214 else
215 convert +adjoin +antialias -density $resolution $tmpdir/out.eps $tmpdir/out.$format
220 if [ -e $tmpdir/out.$format ]; then
221 mv $tmpdir/out.$format $outfile
222 else
223 mv $tmpdir/out.$format.0 $outfile
226 let OPTIND=$OPTIND+1
227 outfile=""
228 done
231 # Cleanup
234 rm -rf $tmpdir
235 exit 0