# Is there a way to change styles in imported EPS files?

I know how to replace simple textual tags in imported EPS files using psfrag; but to ensure a consistent appearance for graphics in my documents, I would like to also be able to make substitutions to styles, particularly things like line weights and colors. Is there a way to do this, using either psfrag or some other technique?

I understand that in principle, since the EPS is "just" text, I could write code to perform any arbitrary substitution; but that approach is complex and unstable. Moreover, since nearly all of the EPS files I will be using are exported from another tool, the details of generated EPS are not under my control and will likely change in the future (as they have in the past).

I am particularly interested in what I can accomplish using Mathematica 8.0 as the source for my EPS files. For example, while I can use something like

plot1 = Plot[{Cos[t], Sin[t]}, {t, 0, 2 \[Pi]},
PlotStyle -> {Red, Green},
AxesLabel -> {"e", "s"}, Ticks -> {{}, {}}];
Export["plot1.eps", plot1];


in Mathematica to create an EPS file that I can then incorporate into my LaTaX document using

\psfragfig{plot1}{
\psfrag{e}{$\epsilon$}
\psfrag{s}{$\Sigma$}}


to perform simple textual substitutions, I don't see a way to use this technique to impose a uniform appearance on figures using something, like

\definecolor{tflcentralred}{RGB}{220,36,31}
\definecolor{tfldistrictgreen}{RGB}{0,114,41}
%...
\psfragfig{plot1}{
\psfrag{Red}{tflcentralred}         % Appears to be now way to do this
\psfrag{Green}{tfldistrictgreen}    % Appears to be now way to do this
\psfrag{e}{$\epsilon$}
\psfrag{s}{$\Sigma$}}


Is there a way to change styles such as and colors and line weights in imported EPS files, especially those created by Mathematica, either using techniques and packages in LaTeX, or by modifying the EPS as it is generated in Mathematica (a separate question)? Or is one, in practice (without what amounts to EPS coding), limited to simple text substitutions.

\documentclass{article}
\usepackage{pstool}
\usepackage{tikz}

\begin{document}

\definecolor{tflcentralred}{RGB}{220,36,31}
\definecolor{tfldistrictgreen}{RGB}{0,114,41}

%Generate plot1.eps in Mathematica 8.0 using:
%   plot1 = Plot[{Cos[t], Sin[t]}, {t, 0, 2 \[Pi]},
%     PlotStyle -> {Red, Green},
%     AxesLabel -> {"e", "s"}, Ticks -> {{}, {}}];
%   Export["plot1.eps", plot1];
\psfragfig{plot1}{
\psfrag{Red}{tflcentralred}                     % Appears to be now way to do this
\psfrag{Green}{tfldistrictgreen}            % Appears to be now way to do this
\psfrag{e}{$\epsilon$}
\psfrag{s}{$\Sigma$}}

\begin{tikzpicture}[domain=0:2*3.14159,x=1.8cm,y=3cm,samples=500]
\draw[-] (0,0) -- coordinate (x axis mid) (6.25,0) node[right] {$\epsilon$};
\draw[-] (0,-1) -- coordinate (y axis mid)(0,1)node[above] {$\Sigma$};
\draw[color=tflcentralred] plot (\x,{cos(\x r)});
\draw[color=tfldistrictgreen] plot (\x,{sin(\x r)});
\end{tikzpicture}

\end{document}

-
The simplest answer to your question is I think "no". There is no way to do that. An EPS file is an arbitrarily complex postscript program, so more or less no feature of the output may be reliably found by searching the input. Text (usually) ends up being shown by the show primitive so psfrag gets by by locally redefining that, but to do more in general is asking too much. Obviously for a particular application you may be able to spot particular idioms that are amenable to re-definition but it's always going to be fragile. You would always be better changing the generation (mathematica) –  David Carlisle May 30 '12 at 16:13
@DavidCarlisle: I'd accept that as an answer. –  raxacoricofallapatorius May 30 '12 at 16:47

The simplest answer to your question is I think "no". There is no way to do that. An EPS file is an arbitrarily complex postscript program, so more or less no feature of the output may be reliably found by searching the input. Text (usually) ends up being shown by the show primitive so psfrag gets by by locally redefining that, but to do more in general is asking too much. Obviously for a particular application you may be able to spot particular idioms that are amenable to re-definition but it's always going to be fragile. You would always be better changing the generation (so in this case, try to customise the generation from mathematica).