3

I prepare my figures in a drawing tool (OmniGraffle), export them to PDF and then use \includegraphics to include them in my tex file (which is compiled using pdflatex).

Some of these figures have references to theorems of the text. It would be great if I could just write "Theorem \ref{thm:foobar}" in the drawing tool, and have \ref{thm:foobar} replaced by the actual number when the PDF file is included during compilation.

This is probably not possible, but I figured I might as well give it a try.

N.N.
  • 36,163
Andreas
  • 61
  • 2
    you can replace text in eps files with psfrag. not sure there is a pdf version. you could use the overpic package however, if you want to put stuff on top of the picture. this may not be as convenient as having it replaced but might be just enough in your case – Martin H Jun 30 '11 at 19:33
  • You can't replace things in included PDFs with text nor have working hyperlinks there (existing ones are stripped). Drawing on the PDF like Martin H already said is probably the best way to do it. – Martin Scharrer Jun 30 '11 at 20:44
  • xfig can be configured to let LaTeX render all text inside an xfig figure (and probably is one of the reasons so many people still use this rather archaic program). With OmniGraffle, I only see a possibility if you export your figures to EPS and switch over to the dvi->ps->pdf route to be able to use pgsfrag. – Daniel Jul 01 '11 at 07:25
  • As alternative for overpic I also recommend the TikZ based solution shown in Drawing on an image with TikZ, which will be part of the TeX.SX bundle. – Martin Scharrer Jul 01 '11 at 11:36

3 Answers3

3

The easiest solution seems to be the overpic package.

I also had a look at the pstool package. It allows you to replace text in EPS files and then automatically transforms them to PDFs to be used with pdflatex. However, this is still cumbersome, and I did not manage to get pstool working with my MacTeX distribution.

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
Andreas
  • 61
  • pstool works for me and according to the documentation, from version 1.5 onwards, it should support cross-references. – quazgar Aug 07 '13 at 20:21
3

If you're willing to go the latex->dvips->ps2pdf route, Xfig provides an easy solution in conjunction with the [psfrag package]. The discussion below does not have to be produced in Xfig. However, the concepts illustrated was easiest to duplicate using Xfig.

Assume that image.eps was generated in Xfig, looking like this:

Xfig sample picture

Using \psfrag{<tag>}{<LaTeX text>}, you can modify mylabel1 in image.eps to be any LaTeX command, including referencing a theorem (say):

\documentclass{article}
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\usepackage{psfrag}% http;//ctan.org/pkg/psfrag
\usepackage{hyperref}% http://ctan.org/pkg/hyperref
\newtheorem{theorem}{Theorem}% \begin{theorem}...\end{theorem}
\begin{document}
\begin{figure}[t]
  \centering
  \psfrag{mylabel1}{Theorem~\ref{thm:first}}%
  \includegraphics{image}
  \caption{This is a figure}
\end{figure}
\begin{theorem}
This is the first theorem. \label{thm:first}
\end{theorem}
\end{document}

Xfig with reference to in-document label

The hyperref package was added to highlight the reference.


As mentioned in the comments. There exists no formal pdffrag counterpart to psfrag. Xfig, however, provides a means around that via xfigfrag. However, development on this stopped on 2009-11-28. See the xfigfrag README on how to use this tool.

For the moment, an experimental pdffrag exists in the form of the pdfrack package. Although I haven't used it in a setting that requires referencing (or any setting for that matter).

Werner
  • 603,163
1

This problem now can be perfectly solved by the Inkscape using --export-latex option.
The text in graphics will be well preserved in a latex file so you can do whatever you want on those text, such as adding a reference.
Your graphics may need to be edited in Inkscape first since the position of text may not be perfect if the graphics is not created by Inkscape at first.

However, the recommended way to include the exported graphics seems problematic. Instead of defining the free variable \svgwidth, I'd like to have the pdf_tex file wrapped with resizebox like:

\begin{figure}
    \resizebox{\columnwidth}{!}{\input{testgraphic.pdf_tex}}
\end{figure}