#!/bin/bash # eq2eps - by Vitaly N. Golovach, May 5, 2006 # I did not intend to make it short ;-) ################################################## argN=3 userpacksdef="amsfonts,bm,amstext,amssymb" if [ $# -gt $argN ] then echo "Too many arguments: $# instead of maximum of ${argN}." exit 1 fi if [ -z "$1" -o "$1" = "--help" -o "$1" = "-help" ] then echo "Usage: eq2eps 'equation' filename.eps [usepackages]" echo "Description: Converts a LaTeX equation to an EPS file with a tight bounding box." echo " The equation should be taken in single quotes, unless it consists of a single word." echo " Example: eq2eps 'y = f(x)' yfx.eps" echo " Note that the eqnarray environment is used, which means that multiple-line equations are allowed." echo " Example: eq2eps 'x&=&f_x(t) \\\\ x&=&f_y(t) \nonumber\\\\ z&=&f_z(t)' zeroes.eps" echo " The \\nonumber option is inserted automatically to the first and last lines." echo " Some usepackages are already present here: $userpacksdef " echo " Additional usepackages, separated by comma, can be included as third argument." echo " Example: eq2eps 'y=f(\bm{r})' yfr.eps bm,amssymb,amstext" exit 0 fi if [ -z "$2" ] then echo "Please specify the output file name, for example: eq2eps 'i^2=-1' i2.eps" exit 1 fi if [ -z "$3" ] then addonsty="" else addonsty=",$3" fi echo "\tolerance=20000" > filetmptexnosuchnamepleasebutifsothenitisriskytooverwriteit.tex echo "\documentclass[12pt]{report}" >> filetmptexnosuchnamepleasebutifsothenitisriskytooverwriteit.tex echo "\usepackage{${userpacksdef}${addonsty}}" >> filetmptexnosuchnamepleasebutifsothenitisriskytooverwriteit.tex echo "\pagestyle{empty}" >> filetmptexnosuchnamepleasebutifsothenitisriskytooverwriteit.tex echo "\begin{document}" >> filetmptexnosuchnamepleasebutifsothenitisriskytooverwriteit.tex echo "\begin{eqnarray}" >> filetmptexnosuchnamepleasebutifsothenitisriskytooverwriteit.tex echo "\nonumber" >> filetmptexnosuchnamepleasebutifsothenitisriskytooverwriteit.tex echo $1 >> filetmptexnosuchnamepleasebutifsothenitisriskytooverwriteit.tex echo "\nonumber" >> filetmptexnosuchnamepleasebutifsothenitisriskytooverwriteit.tex echo "\end{eqnarray}" >> filetmptexnosuchnamepleasebutifsothenitisriskytooverwriteit.tex echo "\end{document}" >> filetmptexnosuchnamepleasebutifsothenitisriskytooverwriteit.tex latex -interaction=nonstopmode filetmptexnosuchnamepleasebutifsothenitisriskytooverwriteit.tex | grep "no such output is expected here" if [ -f filetmptexnosuchnamepleasebutifsothenitisriskytooverwriteit.dvi ] then nothingtodo="" else echo "LaTeX translation error. Check the arguments and try again." exit 1 fi dvips -q -E filetmptexnosuchnamepleasebutifsothenitisriskytooverwriteit.dvi -o $2 if [ -f filetmptexnosuchnamepleasebutifsothenitisriskytooverwriteit.tex ] then rm filetmptexnosuchnamepleasebutifsothenitisriskytooverwriteit.tex fi if [ -f filetmptexnosuchnamepleasebutifsothenitisriskytooverwriteit.dvi ] then rm filetmptexnosuchnamepleasebutifsothenitisriskytooverwriteit.dvi fi if [ -f filetmptexnosuchnamepleasebutifsothenitisriskytooverwriteit.log ] then rm filetmptexnosuchnamepleasebutifsothenitisriskytooverwriteit.log fi if [ -f filetmptexnosuchnamepleasebutifsothenitisriskytooverwriteit.aux ] then rm filetmptexnosuchnamepleasebutifsothenitisriskytooverwriteit.aux fi if [ -f filetmptexnosuchnamepleasebutifsothenitisriskytooverwriteit.ps ] then rm filetmptexnosuchnamepleasebutifsothenitisriskytooverwriteit.ps fi