[Tex/LaTex] Using TikZ and psfrag

psfragtikz-pgf

I use psfrag to replace tags in figures by LaTeX text and formulas. Recently I wanted to go one step further, lets say I have a figure that has two tags in it "a" and "b", I'd like to have a nice arrow going from "a" to "b", so my idea was to create nodes using psfrag

\psfrag{a}{\tikz[remember picture]\node (A){a};}
\psfrag{b}{\tikz[remember picture]\node (B){b};}

then import the figure and then add the arrow

\tikz \draw[->, remember picture] (A) -- (B) ;

needless to say (?) it doesn't work…..psfrag is doing some clever things in the background, but the nodes that have created are not available for me later…

Any ideas on how I could either make psfrag work or get similar functionality (within my framework more-or-less)?

Best Answer

A different approach could be to open the EPS file in inkscape and then save it as an EPS using the "EPS+LaTeX" option, which creates a tex file that contains all the text and a reference to the bare figure. The tex file is then called in the main document using \input

Here's an example using a file I just opened and saved in inkscape:

\documentclass{minimal}

\usepackage{graphicx}
\usepackage{tikz}
\begin{document}

% Inkscape encloses all text in \smash{}, so we'll use that to automate creating nodes
% Not sure if that's safe (do other things routinely call \smash{}?)
\let\oldsmash\smash
\renewcommand{\smash}[1]{\oldsmash{\tikz[remember picture] \node (#1) {#1};}}

\tikzstyle{every picture} = [remember picture]

\input{figure.eps_tex}

\tikz[overlay,->] \draw (a) -- (b);

\end{document}