# Replacing labels in EPS file by LaTeX - text not where it should be

I am spawning a .eps file with octave by using this .m file:

function dummy
xlim([0 81]);
x = [0:0.01:81];
y=x.^0.5+x.^0.4+x.^0.3+x.^0.2+x.^0.1;
plot (x,y*1.85,"-;aaaa;",'linewidth',2,x,y*1.00,"-;bbbb;",'linewidth',2,x,y*1.25,"-;cccc;",'linewidth',2,x,x/2,"-;dddd;",'linewidth',2);
legend ("location", "northwest");
xlabel ("kkkk");
ylabel ("yyyy");
set (gca (), "xtick",[]);
set (gca (), "ytick",[]);
set (gca (), "fontname","DejaVuSans");
print('-dtex', 'dummy.tex');
endfunction


and including it with this LaTeX "container":

\documentclass[12pt]{article}
\usepackage{psfrag}
\usepackage[dvips]{graphicx,color}
\thispagestyle{empty}

% You can run this by typing the following commands:
%    latex 2dplot.tex
%    dvips -o 2dplot.ps 2dplot.dvi

\begin{document}

% The syntax of the "psfrag" command is:
%    \psfrag{tag}[<posn>][<psposn>][<scale>][<rot>]{replacement}
% See the file pfgguide.ps for full documentation.

\begin{figure}
\psfrag{aaaa}{\small{$y$}}
\psfrag{bbbb}{\small{$s_1 \cdot y$}}
\psfrag{cccc}{\small{$s_2 \cdot y$}}
\psfrag{dddd}{\small{$k(\Sigma + n + g)$}}
\psfrag{kkkk}{\small{$k$}}
\psfrag{yyyy}{\small{$y$}}
\includegraphics{dummy.eps}
\end{figure}

\end{document}


But the psfrag replacements show up at bottom left corner of the page.
Running latex ./dummy.tex does not yield any errors.

-

The replacements not showing on the actual picture are OK. From the psfrag manual:

When viewing the output with a DVI previewer such as dviwin or xdvi, a vertical list of the replacements will be placed on the left side of each figure. This list allows you to check the typesetting of your replacements; it disappears in the final PostScript version. Unfortunately, DVI drivers are incapable of placing the PSfrag replacements on top of the figure, so for that you will need to print it or use a PostScript previewer like GhostView

You should convert your dvi to ps or pdf or print it in order for the replacements to apply.

-
You'll also see the same behavior when using TikZ or pstricks to draw images with TeX text included in the image. A DVI previewer won't position the text properly, but a postscript or PDF version will be fine. This is due to the limitations of the DVI previewers. –  Ken Bloom May 5 '11 at 15:08

As for an alternative to Octave, here is how I would do in R:

x <- seq(0, 81, by=.01)
y <- x^.5+x^.4+x^.3+x^.2+x^.1
dat <- data.frame(x, y1=y*1.85, y2=y, y3=y*1.25, y4=x/2)

library(lattice)
lp <- xyplot(y1+y2+y3+y4~x, dat, type="l", xlab="k", ylab="y",
main="Tour title here",
col = c('blue', 'red', 'green', 'cyan'),
key=list(x=0.05, y=0.95, text=list(c(expression(y),
expression(s[1] %.% y),
expression(s[2] %.% y),
expression(k(Sigma + n + g)))),
lines=list(lty=1, col=c('blue','red','green','cyan'))))


It can be saved as PDF with

pdf("yourfilename.pdf", width=5, height=5)
print(lp)
dev.off()


or quite in the same manner with the postscript() function for EPS output.

Here is the result:

-
ocatve is not capable of inserting greek letters and fun, therefore I wanted to replace the dummy labels aaaa, bbbb and so on with the correct greek formule –  drahnr May 5 '11 at 12:58
@drahnr I missed that point. Would you like me to give you the R syntax for producing such a plot? –  chl May 5 '11 at 13:02
even if I use your print(...) , I still get the PSfrag replacments all rendered at the bottom right of the dvi and the legend gets not adjusted as desired –  drahnr May 5 '11 at 13:06
give me whatever you have :> I am thankful for everything, maybe point me to a R howto :) thank you –  drahnr May 5 '11 at 13:06
@drahnr While we're in (and because I read another comment of yours), you can change line thickness with lwd= ($>1$ means larger) and line type with lty= (1=solid, 2=dashed, 3=dotted, 4=dash-and-dot). It might help if this is for a BW paper. Be sure to add this in both the legend (inside the key list) and the call to xyplot. Should you want to add a grid layout, use type=c("l", "g"). Good luck! –  chl May 5 '11 at 16:14

Generally, I'd be inclined to alter a graphic item by altering the code that created it. If that cannot be done, I'd use inkscape on it. These two options yield a graphic that can be used in any application (e.g. presentation application, web application), and not just in latex. So, heresy that this may be in this group, I'd advise dropping your work with psfrag, seeing as you've had difficulties.

-
Postprocessing with inkscape is uggly, in case the grpahs change in the future I'll have to redo it anytime even only a tiny bit changes. Not an option. It is for a paper so.. –  drahnr May 5 '11 at 13:00