Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This post is a continuation to my earlier post here:

Creating standalone eps files and using batch files to automate the process

Xport gave good answers that work!

One goal of this whole process of automation also helps when using pdfLaTeX is used instead of the traditional tex > dvi > ps > pdf route. With TeXLive 2010, one can just issue the pdfLaTeX command and all eps files get converted on the fly to pdf and get inserted in the document.

I do not like the pdfLaTeX workflow but it compiles much faster than the traditional tex > dvi > ps > pdf route. So I have decided to use pdfLaTeX while a document is still work-in-progress and then I can use the workflow tex > dvi > ps > pdf to get the final compilation with all proper eps files inserted.

Now with pdfLaTeX, an eps file gets converted to pdf as follows:

e.g. jeffcott.eps gets converted to jeffcott-eps-converted-to.pdf and model.eps gets converted to model-eps-converted-to.pdf.

Making use of Xport batch files, I have tried to automate the above:

First we have the file automate.bat as follows:

for %%x in (*.tex) do dobatch.bat %%~nx

where the dobatch.bat is

 rem echo off
 latex -interaction=nonstopmode %1
 dvips -R -t unknown %1
 ps2pdf -dAutoRotatePages#/None -dCompatibilityLevel#1.5 -dPDFSETTINGS#/prepress -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -dEPSCrop %1.ps %1-temp.pdf
 pdfcrop --restricted --hires %1-temp %1.pdf
 rename %1.pdf %1-eps-converted-to.pdf
 pdftops -level3 -eps %1-eps-converted-to.pdf
 del %1.log
 del %1.aux
 del %1.dvi
 del %1.ps
 del %1-temp.pdf
 ps2eps -f --fixps %1-eps-converted-to.eps
 del %1.eps

Let's take an example to see what's happening:

Say I have the file jeffcott.eps and model.eps with unreplaced psfrag labels.

These files are here:

http://petitlien.fr/epspicture

I create the file jeffcott.tex working on jeffcott.epsas follows:

 \documentclass[12pt]{standalone}
 \usepackage[hiresbb,dvips]{graphicx}
 \usepackage[dvips]{color}
 \usepackage{psfrag}
 \usepackage{fourier}
 \newcommand{\figtext}{\small}
 \begin{document}
 {\figtext
 \psfrag{A}{$m$}
 \psfrag{B}{$k,c$}
 \psfrag{Y}{inner stator bore}
 \includegraphics{jeffcott.eps}}
 \end{document}

and a similar one model.tex working on model.eps as given below:

 \documentclass[12pt]{standalone}
 \usepackage[hiresbb,dvips]{graphicx}
 \usepackage[dvips]{color}
 \usepackage{psfrag}
 \usepackage{fourier}
 \newcommand{\figtext}{\small}
 \begin{document}
 {\figtext
 \psfrag{D}{$x$}
 \psfrag{E}{$y$}
 \psfrag{F}{$\omega_\mathrm{ro}$}
 \psfrag{G}{$\omega_\mathit{fo} \thinspace t$}
 \psfrag{H}{$\beta$}
 \psfrag{I}{$a$}
 \psfrag{J}{$r$}
 \psfrag{K}{$\theta$}
 \psfrag{L}{$r$}
 \psfrag{M}{$\mathrm{C}_\mathrm{st}$}
 \psfrag{N}{$\mathrm{C}_\mathrm{ro}$}
 \includegraphics{model.eps}}
 \end{document}

I place jeffcott.tex, model.tex, automate.bat and dobatch.bat in the same folder as jeffcott.eps and model.eps, and then I run automate.bat. The following files are now in that folder:

A. The original files

jeffcott.tex
model.tex
jeffcott.eps
model.eps
automate.bat
dobatch.bat

B. And the created files from running the automate.bat

jeffcott-eps-converted-to.eps
jeffcott-eps-converted-to.eps.eps
jeffcott-eps-converted-to.pdf

model-eps-converted-to.eps
model-eps-converted-to.eps.eps
model-eps-converted-to.pdf

I am close to what I need as jeffcott-eps-converted-to.pdf and model-eps-converted-to.pdf have been created. These are pdf files with all labels by psfrag inserted unlike those pdf files generated by running pdflatex with TeXLive 2010 which would not contain the replaced labels. What I did in the file dobatch.bat was to make sure that I get the same filenames as those which would be created by pdfLaTeX. Now I can just replace the pdfLaTeX pdf versions of my original eps files with these pdf files created with the batch file.

I have four questions:

I. In the file dobatch.bat, there is the line: ps2eps -f --fixps %1-eps-converted-to.eps

whatever code comes after this line in the batch file get ignored. Why is that and how to fix that?

II. Ghostscript cannot read the bbox for jeffcott-eps-converted-to.eps and model-eps-converted-to.eps. This is why I use ps2eps to fix the bbox and it works. And I get the files: jeffcott-eps-converted-to.eps.eps and model-eps-converted-to.eps.eps. Since I have the original eps files: jeffott.eps and model.eps (without the psfrag labels) in the same directory, I would like to have the new correct eps files with all labels included named as jefcottalone.eps and modelalone.eps to emphasize that they stand alone. How to achieve this in th batch file dobatch.bat?

III. In my file jeffcott.tex, I have used the line:

 \documentclass[12pt]{standalone}

Does the standalone package accept the option 12pt? I did not see this in the manual.

IV. In my file jeffcott.tex, I use the command:

\newcommand{\figtext}{\small}

to specify whatever text in the figure should be of size \figtext. It seems to work. Is this the correct way of doing things?

share|improve this question
    
Thanks. I have updated my post and put the tags. See the listings of jeffcott.tex and model.tex in my post for which psfrag labels that are involved. –  yCalleecharan Jul 21 '11 at 5:42
    
I get the impression that pdfLateX does run faster. Perhaps because eps files are usually larger than the corresponding pdf files. Anyway if this is not true, the post here is helping a lot for me to understand eps files better and create standalone eps and pdffiles. –  yCalleecharan Jul 21 '11 at 5:45
    
So you mean that I can just take away the stanadaloneclass and use a normal article class here? Please explain. Thanks. –  yCalleecharan Jul 21 '11 at 5:46
    
I think you need to tidy up your question above, make it a bit shorter but still reflects the essence. I don't know who had down voted your question above, it might be because he/she felt confused when reading it. Thank you. Please also remove your unnecessary comments. I have done it! –  xport Jul 22 '11 at 16:13
add comment

1 Answer

up vote 1 down vote accepted

Scenario:

Please confirm, whether or not your situation like below.

  1. You have a bunch of EPS files.
  2. You want to replace some certain tags on each EPS. To do so, you have prepared files file01.tex for image01.eps, file01.tex for image02.eps, etc. For example, you have prepared file01.tex and file02.tex as follow:

    % file01.tex for image01.eps
    \documentclass[dvips]{article}
    \pagestyle{empty}
    \parindent=0pt
    \usepackage{graphicx}
    \usepackage{psfrag}
    
    \begin{document} 
    \small
    \psfrag{a}{$A$}
    \psfrag{b}{$B$}
    \psfrag{c}{I am C!}
    \includegraphics{image01}
    \end{document}
    
    % file02.tex for image02.eps
    \documentclass[dvips]{article}
    \pagestyle{empty}
    \parindent=0pt
    \usepackage{graphicx}
    \usepackage{psfrag}
    
    \begin{document} 
    \small
    \psfrag{G}{\color{red}$m$}
    \psfrag{H}{\color{red}$k,c$}
    \psfrag{I}{\color{red}inner stator bore}
    \includegraphics{image02}
    \end{document}
    
  3. You want to automate the process to produce a PDF version for each of EPS.

  4. All white spaces surrounding the valuable object in EPS must be trimmed in PDF.

  5. You want to import the resulting PDF files to your main document such as thesis, article, etc.

If it is your real scenario, then I will give you the correct direction. I am confused with your lengthy question.

Solution:

The following is the workflow you must do.

  1. Create a batch file for compiling a single file**.tex to produce file**.pdf. Name the batch file EpsToPdf.bat as follows.

    rem EpsToPdf.bat
    rem It takes a file name without extension.
    rem For example: EpsToPdf file01
    rem Another example: EpsToPdf file02
    
    latex "%1"
    dvips -t unknown "%1"
    ps2pdf "%1.ps" "%1-temp.pdf"
    pdfcrop --hires "%1-temp" "%1.pdf"
    rem acrord32 "%1.pdf"
    del "%1.log"
    del "%1.aux"
    del "%1.dvi"
    del "%1.ps"
    del "%1-temp.pdf"
    
  2. Create another batch file to automate the process of compiling all file**.tex. Name this batch automate.bat as follows.

    rem automatic.bat
    rem just execute without any switch.
    for %%x in (*.tex) do EpsToPdf.bat "%%~nx"
    
  3. Make sure all image**.eps, file**.tex, batch files are in the same directory. This is needed unless you have set the PATH environment variable to the path pointing to the batch files.

  4. Execute automatic.bat by double clicking it. Wait until all PDF are generated. If there are missing PDF, then check the corresponding file**.tex.

  5. To import the resulting PDF to your main document such as thesis, article, journal, etc, create another TeX document as follow. It is just a trivial example.

    % main.tex
    \documentclass{article}
    \usepackage{graphicx,lipsum}
    \begin{document}
    \lipsum[1]
    \includegraphics{file01}
    
    \lipsum[2]
    \includegraphics{file02}
    \end{document}
    

    And compile it using the following batch file, just type TexToPdf main and hit enter in DOS-prompt.

    rem TexToPdf.bat
    rem It takes a file name without extension.
    rem For example: TexToPdf main
    
    pdflatex "%1"
    pdflatex "%1"
    rem acrord32 "%1.pdf"
    del "%1.log"
    del "%1.aux"
    rem del "%1.***" <=== change *** to something meaningful
    

    pdflatex.exe are intentionally executed twice to get correct cross-references.

  6. Done!

Additional:

If you need EPS output as well, then you must insert pdftops -eps "%1.pdf" right after pdfcrop --hires "%1-temp" "%1.pdf" in EpsToPdf.bat above.

But be careful !!!! Read the following carefully !!!

If your TeX input file has the same name as the imported EPS file has, then the original EPS file will be overwritten. You will lose the original EPS! To avoid this, you must not give the TeX input file a name that is equal to the name of the original EPS.

share|improve this answer
    
Yes it's ok. I don't understand your point 4 though, but this doesn't seem to be a big issue. And I would like to have a standalone eps as well with all the psfrag labels inserted. This standalone eps should not be a raster image. Thanks. –  yCalleecharan Jul 21 '11 at 7:05
    
So my goal is to have both standalone pdf and eps files. –  yCalleecharan Jul 21 '11 at 7:07
    
As I pointed out before, any commands in the batch files that comes after ps2eps do not get processed at all. So all the del commands that you had in your batch file after the line ps2eps do not get processed. –  yCalleecharan Jul 21 '11 at 7:09
    
Thanks. I need an EPS file if I need to send someone a standalone EPS figure. For example, journals at times prefer to have standalone EPS figures to work with rather than having to run the PSFRAG command in the LaTeX files. –  yCalleecharan Jul 21 '11 at 7:30
    
With the ps2pdf, maybe the setting -dPDFSETTINGS#/prepress can be useful. –  yCalleecharan Jul 22 '11 at 5:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.