[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LaTeX in octave/automated plots

From: A. Scottedward Hodel
Subject: LaTeX in octave/automated plots
Date: Sun, 25 Nov 2007 14:10:24 -0600

From time to time I've seen discussion on how to integrate LaTeX code into Octave plots and, in turn, to integrate those plots into a LaTeX document.  I'm in the process of writing a textbook with more than 250 plots/m-files, entirely done in Octave, and so the ability to automate this process is an important feature.

I've tried several approaches which I summarize here.  If others have additional suggestions/recommendations to add to the discussion, that would be wonderful.  My preferences of the approaches below are (2) and (4), and I'm currently using (4) so that I can avoid color plots.  If you are interested in seeing the results, an earlier version of my lecture notes for the class I'm teaching this fall is at"">
I've been rewriting them actively in the last month as I prepare a formal textbook proposal.

(1) eps only  Print as an eps file directly:
print -deps -mono myfile.eps
advantage: direct, easy to do.
disadvantage: fonts do not immediately match LaTeX (can be adjusted with Font commands in print), cannot put LaTeX commands into legends, labels, titles, etc.

(2) epslatex/dvips Use epslatex, then use dvips -E* in a shell script to generate a cropped .eps file that can be resized.
advantage: permits the use of LaTeX commands in text, etc.
disadvantage: current epslatex does not respond to the -mono directive.  (This was discussed earlier on this list; the problem appears to be with gnuplot)

(3) eps/psfrag Print as an eps file and use psfrag in LaTeX to process embedded LaTeX commands (requires an additional shell script)
advantage: seems straightforward for simple plots; see, e.g.,
disadvantage: LaTeX tags must be handled manually in the LaTeX file itself; I have been unable to get the \tex[bl][bl]{Your LaTeX text here} to work properly, so it is difficult to automate this process.

(4) xfig/fig2ps Print as a fig file, then use fig2ps to generate an eps file
advantage: easily automated in a Makefile.
- cannot change size of fig file plot (can scale with includegraphics, but cannot change size of original plot).
- linestyle commands do not affect the line style in the xfig plot.
Nevertheless, this is the option I most prefer of the set.  The Makefile I use to automatically run my m-files and generate .eps files is below.

I hope this description is of use to others on this list.

A. Scottedward Hodel, 334 844-1854, fax 334 844-1809

# Makefile:
# Use this part for epslatex (need external script to run LaTeX and dvips)
#%_out.tex %.eps : %.m
# @echo "creating $@ from $<"
# fn=`echo $< | sed '1,$$s/\.m$$//'` ; \
# echo "\par\noindent{\bf $< Output}~" > $${fn}.out.tmp ; \
# echo "\\begin{verbatim}" >> $${fn}.out.tmp ; \
# echo " $${fn} ; print -depslatex -mono MakefilePlot.tex " \
#  | octave -q  >> $${fn}.out.tmp ; \
# echo "\\end{verbatim} " >> $${fn}.out.tmp ; \
# mv $${fn}.out.tmp $${fn}_out.tex ; \
# bash finishPlot $${fn}.eps

# use this part for xfig/fig2ps
%.eps : %.fig
@echo "creating $@ from $<"
fig2ps --forcespecial --add=epsfig --input=../2120head.tex \
 --bbox=dvips --eps $<
rm -f *.fig2ps.tmp.*

%_out.tex %.fig : %.m
@echo "creating $@ from $<"
fn=`echo $< | sed '1,$$s/\.m$$//'` ; \
echo "\par\noindent{\bf $< Output}~" > $${fn}.out.tmp ; \
echo "\\begin{verbatim}" >> $${fn}.out.tmp ; \
echo " $${fn} ; print -dfig -mono '$${fn}.fig'" \
 | octave -q  >> $${fn}.out.tmp ; \
echo "\\end{verbatim} " >> $${fn}.out.tmp ; \
mv $${fn}.out.tmp $${fn}_out.tex

mfiles = $(shell ls *.m)
tmpeps = $(patsubst %.m, %.eps, $(mfiles))
tmptex = $(patsubst %.m, %_out.tex, $(mfiles))

all: $(tmpeps) $(tmptex)

rm -f *.eps *.fig $(tmptex) $(tmpeps) $(patsubst %.m, %.tex, $(mfiles))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]