4

In my document I'm embedding figures using the following code:

\begin{figure}[!t]
  \centering
  \def\svgwidth{1.2\columnwidth}
  \resizebox{\columnwidth}{!}{
    \endlinechar=255\relax
    \begin{picture}(1,0.63636365)
      \put(0,0){\includegraphics[width=\unitlength]{figure.eps}}
      \put(0.50454546,0.58636365){\color[rgb]{0,0,0}\makebox(0,0)[b]{\smash{some text $ax^2+bx+c=0$.}}}
    \end{picture}
  }
  \caption{Caption.}
  \label{fig:figure}
\end{figure}

Where the image (figure.eps) contains no text and all annotations are added on top of the image using \put commands.

This method works very well (annotations can include any LaTeX macros, which is extremely useful) as long as I'm sticking to TeX. Now, however, I'd like to take the resulting figures (preferably in a vector format) and put them in some other tool.

Questions:

  1. Is there any way of outputting these floats into PDF files with no margins, captions and with page dimensions equal to the specified float size? I imagine I'd have to somehow wrap each float in a .tex file with a custom preamble.
  2. Is it possible to automate this process so that if I want to dump all my N figures to PDFs I don't have to repeat the step (1) N times.
2
  • 1
    Sounds like a job for standalone.
    – N.N.
    Commented Sep 28, 2011 at 10:38
  • @N.N.: for multi-page document I would use the preview package directly. Commented Sep 28, 2011 at 10:57

2 Answers 2

6

In general I recommend you to place all your complicated figures into separate files and use e.g. the standalone class to be able to compile them separatly and then \input them easily in the main document with the standalone package.

For your existing document you can use the preview package (which is used internally by standalone). It only compiles things wrapped in a preview environment and every such environment as a page. With the tightpage option you get tight pages as I requested.

I would use code like the following to redefine figure to use preview environments and to disable (or include) the \caption. The resulting PDF should have one picture per page. You can then use the page=<number> option of \includegraphics to include it or split it into several PDFs using tools like pdftk allfigures.pdf burst output figure%02d.pdf or Ghostscript.

\documentclass{article}

\usepackage[active,tightpage]{preview}

\makeatletter
\renewenvironment{figure}[1][]{%
    \begin{preview}%
        \renewcommand\caption[2][]{}% or
        %\def\@captype{figure}% If you want to include the caption
}{%
    \end{preview}%
}
\makeatother

\begin{document}

text text text text 

\begin{figure}[!t]
    \rule{5cm}{8cm}% dummy replacement
    \caption{some caption}
\end{figure}

text text text text 

\begin{figure}[!t]
    \rule{8cm}{5cm}% dummy replacement
    \caption{some caption}
\end{figure}

text text text text 


\end{document}
4
  • thanks for the detailed answer. It works almost perfectly. "Almost" because there seems to be some problems with resizebox - it works fine up to width of ~12cm. Also, another, possibly related issue is that if I enable captions (as in your comment) all page widths are fixed to 4.79in (12.16cm).
    – Andrzej
    Commented Sep 28, 2011 at 13:01
  • @Andrzej: You need to comment out the new-line character which is taken as a space, i.e. write \resizebox{\columnwidth}{!}{% instead of \resizebox{\columnwidth}{!}{. This is a common mistake. Or use the adjustbox package with \begin{adjustbox}{width=\columnwidth} <content> \end{adjustbox} instead. Commented Sep 28, 2011 at 14:15
  • @Andrzej: The \caption creates a new paragraph which is \linewidth wide. You could add a {minipage}{<your linewidth>} environment to change that, but I would not include the captions anyway. Commented Sep 28, 2011 at 14:16
  • thanks, it works. I had to comment out all whitespaces (not just after resizebox) but that is not a problem. Thanks again, problem solved.
    – Andrzej
    Commented Sep 28, 2011 at 15:20
1

If you're OK with your procedures so far, I suppose you could set \pagestyle{empty} in the preamble, have only one float per page by inserting a \clearpage instruction after each float, and finally break up the resulting n-page pdf file into n separate pdf files. (Setting the pagestyle to empty will simplify cropping each page.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .