psfrag substitute when using pdflatex
My standard way of including math in figures so far was to use psfrag and latex+dvips+ps2pdf.
I am now moving to pdflatex and tend to prepare my graphics in pdf format. I was wondering if there exists a way to include math in pdf graphics similar to psfrag. I am aware of auto-pst-pdf package but prefer not to use it since on large projects it runs much slower than pdflatex and I am not sure if it can handle microtype as well as pdflatex.
pdftex psfrag auto-pst-pdf
add a comment |
My standard way of including math in figures so far was to use psfrag and latex+dvips+ps2pdf.
I am now moving to pdflatex and tend to prepare my graphics in pdf format. I was wondering if there exists a way to include math in pdf graphics similar to psfrag. I am aware of auto-pst-pdf package but prefer not to use it since on large projects it runs much slower than pdflatex and I am not sure if it can handle microtype as well as pdflatex.
pdftex psfrag auto-pst-pdf
1
auto-pst-pdf is more recommended for running PSTricks withpdflatexand pstool is better recommended for psfrag withpdflatex. See Will Robertson's answer, author for both packages.
– texenthusiast
Nov 15 '13 at 14:37
Please see your questions. None has an accepted answer. It is not good practically to leave too many questions with no accepted answers as if no answer satisfies you and you don't leave any comment for improvement. You should reconsider which answer helps and satisfies you best and accept it. Accepting is simply clicking the check mark button below the score of any answer.
– kiss my armpit
Nov 16 '13 at 7:04
Thanks, I was not aware of this. I have accepted those responses that were satisfactory and will continue to do this.
– per
Nov 17 '13 at 4:18
add a comment |
My standard way of including math in figures so far was to use psfrag and latex+dvips+ps2pdf.
I am now moving to pdflatex and tend to prepare my graphics in pdf format. I was wondering if there exists a way to include math in pdf graphics similar to psfrag. I am aware of auto-pst-pdf package but prefer not to use it since on large projects it runs much slower than pdflatex and I am not sure if it can handle microtype as well as pdflatex.
pdftex psfrag auto-pst-pdf
My standard way of including math in figures so far was to use psfrag and latex+dvips+ps2pdf.
I am now moving to pdflatex and tend to prepare my graphics in pdf format. I was wondering if there exists a way to include math in pdf graphics similar to psfrag. I am aware of auto-pst-pdf package but prefer not to use it since on large projects it runs much slower than pdflatex and I am not sure if it can handle microtype as well as pdflatex.
pdftex psfrag auto-pst-pdf
pdftex psfrag auto-pst-pdf
asked Nov 15 '13 at 7:28
perper
365214
365214
1
auto-pst-pdf is more recommended for running PSTricks withpdflatexand pstool is better recommended for psfrag withpdflatex. See Will Robertson's answer, author for both packages.
– texenthusiast
Nov 15 '13 at 14:37
Please see your questions. None has an accepted answer. It is not good practically to leave too many questions with no accepted answers as if no answer satisfies you and you don't leave any comment for improvement. You should reconsider which answer helps and satisfies you best and accept it. Accepting is simply clicking the check mark button below the score of any answer.
– kiss my armpit
Nov 16 '13 at 7:04
Thanks, I was not aware of this. I have accepted those responses that were satisfactory and will continue to do this.
– per
Nov 17 '13 at 4:18
add a comment |
1
auto-pst-pdf is more recommended for running PSTricks withpdflatexand pstool is better recommended for psfrag withpdflatex. See Will Robertson's answer, author for both packages.
– texenthusiast
Nov 15 '13 at 14:37
Please see your questions. None has an accepted answer. It is not good practically to leave too many questions with no accepted answers as if no answer satisfies you and you don't leave any comment for improvement. You should reconsider which answer helps and satisfies you best and accept it. Accepting is simply clicking the check mark button below the score of any answer.
– kiss my armpit
Nov 16 '13 at 7:04
Thanks, I was not aware of this. I have accepted those responses that were satisfactory and will continue to do this.
– per
Nov 17 '13 at 4:18
1
1
auto-pst-pdf is more recommended for running PSTricks with
pdflatex and pstool is better recommended for psfrag with pdflatex. See Will Robertson's answer, author for both packages.– texenthusiast
Nov 15 '13 at 14:37
auto-pst-pdf is more recommended for running PSTricks with
pdflatex and pstool is better recommended for psfrag with pdflatex. See Will Robertson's answer, author for both packages.– texenthusiast
Nov 15 '13 at 14:37
Please see your questions. None has an accepted answer. It is not good practically to leave too many questions with no accepted answers as if no answer satisfies you and you don't leave any comment for improvement. You should reconsider which answer helps and satisfies you best and accept it. Accepting is simply clicking the check mark button below the score of any answer.
– kiss my armpit
Nov 16 '13 at 7:04
Please see your questions. None has an accepted answer. It is not good practically to leave too many questions with no accepted answers as if no answer satisfies you and you don't leave any comment for improvement. You should reconsider which answer helps and satisfies you best and accept it. Accepting is simply clicking the check mark button below the score of any answer.
– kiss my armpit
Nov 16 '13 at 7:04
Thanks, I was not aware of this. I have accepted those responses that were satisfactory and will continue to do this.
– per
Nov 17 '13 at 4:18
Thanks, I was not aware of this. I have accepted those responses that were satisfactory and will continue to do this.
– per
Nov 17 '13 at 4:18
add a comment |
2 Answers
2
active
oldest
votes
Objectives and constraints
- Extracting all EPS images imported in the main input file without modifying the main input file heavily.
- Converting each of imported EPS images to PDF one and save it with its original file name.
Assumption
For the sake of best practice, I assume that you put all of your EPS images in a sub directory called
Images. It means that the directory structure is defined as follows.
other parents/project/Images/
other parents/project/main.tex
other parents/project/myextractor.sty
You have to follow this convention as the remaining code uses this structure. Of course you can change this directory structure but you also need to modify the code a bit (not much).
main.texandmyextractor.stywill be discussed shortly.
You are using Windows. If you are non-Windows users, please disabled the cleaning code mentioned in
myextractor.sty.
You know that you must compile the
main.texwith
latex -shell-escape main
dvips main
ps2pdf -dAutoRotatePages#/None main.ps
Notes: For non-Windows users, replace # with =.
Step 1
Create a package called myextractor.sty as follows. Save it as mentioned in the directory structure above.
% myextractor.sty
NeedsTeXFormat{LaTeX2e}[1994/06/01]
ProvidesPackage{myextractor}[2013/10/09 v0.01 LaTeX package for my own purpose]
RequirePackage{filecontents}
begin{filecontents*}{template.tex}
documentclass[preview,border=0pt,graphics]{standalone}
usepackage{graphicx}
graphicspath{{Images/}}
% Active the following code (between makeatletter and makeatother)
% if you want to cancel the effect of
% width, height and/or scale defined in includegraphics
%makeatletter
%define@key{Gin}{width}{}
%define@key{Gin}{scale}{}
%define@key{Gin}{height}{}
%makeatother
leteaexpandafter
begin{document}
%edefz{noexpandincludegraphics[varone]{vartwo}}z
eaincludegraphicsea[varone]{vartwo}
end{document}
end{filecontents*}
RequirePackage{graphicx}
RequirePackage{pgffor}
lettempincludegraphics
renewcommandincludegraphics[2]{%
temp[#1]{#2}%
immediatewrite18{latex -jobname=#2 -output-directory=Images unexpanded{"defvarone{#1} defvartwo{#2} input{template}"} && cd Images && dvips #2 && ps2pdf -dAutoRotatePages=/None #2.ps}%
% disable the following if you are not Windows users.
foreach ext in {dvi, ps, log, aux}{immediatewrite18{cd Images && cmd /c del #2.ext}}%
}
endinput
Read the comments given in the code carefully. They are as follows.
% Active the following code (between makeatletter and makeatother)
% if you want to cancel the effect of
% width, height and/or scale defined in includegraphics
%makeatletter
%define@key{Gin}{width}{}
%define@key{Gin}{scale}{}
%define@key{Gin}{height}{}
%makeatother
and
% disable the following if you are not Windows users.
foreach ext in {dvi, ps, log, aux}{immediatewrite18{cd Images && cmd /c del #2.ext}}%
Step 2
Modify your main.tex as follows
% main.tex
documentclass{book}
%usepackage{graphicx}
usepackage{myextractor}% automatically load graphicx
graphicspath{{Images/}}
begin{document}
chapter{A}
begin{figure}[hbtp]
centering
includegraphics[scale=.5]{A}
caption{A}
label{fig:A}
end{figure}
A ldots
chapter{B}
begin{figure}[hbtp]
centering
includegraphics[scale=.75]{B}
caption{B}
label{fig:B}
end{figure}
B ldots
chapter{B}
begin{figure}[hbtp]
centering
includegraphics[scale=1]{C}
caption{C}
label{fig:C}
end{figure}
C ldots
end{document}
The important notes are
%usepackage{graphicx}
usepackage{myextractor}% automatically load graphicx
graphicspath{{Images/}}
- Load
myextractorpackage beforegraphicxto preventgraphicxoverridesmyextractordefinition. Asmyextractorloadsgraphicxinternally, you actually can disablegraphicxinmain.tex.
graphicspathmust be specified as given above.
Step 3
Compile main.tex with latex-dvips-ps2pdf explained above. Afterwards, check Images folder, you will find a PDF version for each EPS image. Done!
Thanks. I am looking for a way to run latex on the original to generate all the graphics in the document and save each in a filename.pdf file where filename is the name of the original eps file. Then I can include these pdf files in the original by deleting the eps extension. This way I do not have to run latex on each individual graphics. auto-pst-pdf does something like this but stores all pdf files in a single pdf file. Maybe a modification of it to store the graphics in individual pdf's is possible (or maybe already exists)
– per
Nov 15 '13 at 15:21
I have a latex file (root of a book) with each chapter input'd and each chapter has many eps files with different names, many of them with psfrag fragments. Say the name of .eps files are 1.eps, 2.eps,.., 600.eps. Is there a way that I can generate 1.pdf, 2.pdf,...600.pdf easily, short of running lated+dvips+ps2pdf 600 times on each figure?
– per
Nov 15 '13 at 18:34
I tried it, it puts all the three pdf graphics in a single file not in three different files. What I want here are three files example-image-a.pdf, example-image-b.pdf and example-image-c.pdf. The way that your suggestion works is very similar to using auto-pst-pdf. I want each graphic to be saved in one pdf file.
– per
Nov 16 '13 at 16:39
@per: If you are using legacy Windows (older than Windows 7), use#instead of=. What is your OS? Answer has been edited.
– kiss my armpit
Nov 17 '13 at 8:06
It did not work as suggested, but after I removed the -dAutoRotatePages=/None option in ps2pdf, it works. But the main problem still remains. This technique generated pdf files for each .eps file but does not include the psfrag substitutions in the resulting pdf file. The alternative solution should read includegraphics contents as well as all psfrag contents that come between the corresponding begin{figure} and end{figure} and generate the pdf file accordingly. Then, in the final run, to generate main.pdf with pdflatex, all psfrag commands should be removed.
– per
Nov 17 '13 at 8:42
|
show 4 more comments
I don't know if you intend to write LaTex on a huge amount of pictures, but I'm using Inkscape to do that. Basically when saving an image into .pdf format, there is a box to tick which allows for extracting all the texts and creates an ancillary tex file which places it automatically in the right place. In your .tex files, you replace includegraphics{mypix.pdf} by input{mypix.pdf_tex} (the file created by Inkscape).
Since it is just an open-and-save operation, I guess it may be possible to write some scripts to do it automatically on all files of a given folder
I don't know how this solves the problem. Could you show some example?
– Christian Hupfer
Dec 12 '14 at 15:37
@ChristianHupfer Assume you have a .pdf you intend to write latex on, you open your image with Inkspace, specify "load text as text". Then Inkspace recognises text fields. When you save your file again, you tick the box "pdf+Latex" and it creates a pdf without text and a tex files with all text fields, placed with commands such :put(0.09714286,0.14448413){rotatebox{90}{makebox(0,0)[lb]{smash{"the content of the text field"}}}}%Here Latex compiles the text, and you can modify it to put math... some more help here : [tug.ctan.org/tex-archive/info/svg-inkscape]
– clemlaflemme
Dec 15 '14 at 8:54
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f145130%2fpsfrag-substitute-when-using-pdflatex%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Objectives and constraints
- Extracting all EPS images imported in the main input file without modifying the main input file heavily.
- Converting each of imported EPS images to PDF one and save it with its original file name.
Assumption
For the sake of best practice, I assume that you put all of your EPS images in a sub directory called
Images. It means that the directory structure is defined as follows.
other parents/project/Images/
other parents/project/main.tex
other parents/project/myextractor.sty
You have to follow this convention as the remaining code uses this structure. Of course you can change this directory structure but you also need to modify the code a bit (not much).
main.texandmyextractor.stywill be discussed shortly.
You are using Windows. If you are non-Windows users, please disabled the cleaning code mentioned in
myextractor.sty.
You know that you must compile the
main.texwith
latex -shell-escape main
dvips main
ps2pdf -dAutoRotatePages#/None main.ps
Notes: For non-Windows users, replace # with =.
Step 1
Create a package called myextractor.sty as follows. Save it as mentioned in the directory structure above.
% myextractor.sty
NeedsTeXFormat{LaTeX2e}[1994/06/01]
ProvidesPackage{myextractor}[2013/10/09 v0.01 LaTeX package for my own purpose]
RequirePackage{filecontents}
begin{filecontents*}{template.tex}
documentclass[preview,border=0pt,graphics]{standalone}
usepackage{graphicx}
graphicspath{{Images/}}
% Active the following code (between makeatletter and makeatother)
% if you want to cancel the effect of
% width, height and/or scale defined in includegraphics
%makeatletter
%define@key{Gin}{width}{}
%define@key{Gin}{scale}{}
%define@key{Gin}{height}{}
%makeatother
leteaexpandafter
begin{document}
%edefz{noexpandincludegraphics[varone]{vartwo}}z
eaincludegraphicsea[varone]{vartwo}
end{document}
end{filecontents*}
RequirePackage{graphicx}
RequirePackage{pgffor}
lettempincludegraphics
renewcommandincludegraphics[2]{%
temp[#1]{#2}%
immediatewrite18{latex -jobname=#2 -output-directory=Images unexpanded{"defvarone{#1} defvartwo{#2} input{template}"} && cd Images && dvips #2 && ps2pdf -dAutoRotatePages=/None #2.ps}%
% disable the following if you are not Windows users.
foreach ext in {dvi, ps, log, aux}{immediatewrite18{cd Images && cmd /c del #2.ext}}%
}
endinput
Read the comments given in the code carefully. They are as follows.
% Active the following code (between makeatletter and makeatother)
% if you want to cancel the effect of
% width, height and/or scale defined in includegraphics
%makeatletter
%define@key{Gin}{width}{}
%define@key{Gin}{scale}{}
%define@key{Gin}{height}{}
%makeatother
and
% disable the following if you are not Windows users.
foreach ext in {dvi, ps, log, aux}{immediatewrite18{cd Images && cmd /c del #2.ext}}%
Step 2
Modify your main.tex as follows
% main.tex
documentclass{book}
%usepackage{graphicx}
usepackage{myextractor}% automatically load graphicx
graphicspath{{Images/}}
begin{document}
chapter{A}
begin{figure}[hbtp]
centering
includegraphics[scale=.5]{A}
caption{A}
label{fig:A}
end{figure}
A ldots
chapter{B}
begin{figure}[hbtp]
centering
includegraphics[scale=.75]{B}
caption{B}
label{fig:B}
end{figure}
B ldots
chapter{B}
begin{figure}[hbtp]
centering
includegraphics[scale=1]{C}
caption{C}
label{fig:C}
end{figure}
C ldots
end{document}
The important notes are
%usepackage{graphicx}
usepackage{myextractor}% automatically load graphicx
graphicspath{{Images/}}
- Load
myextractorpackage beforegraphicxto preventgraphicxoverridesmyextractordefinition. Asmyextractorloadsgraphicxinternally, you actually can disablegraphicxinmain.tex.
graphicspathmust be specified as given above.
Step 3
Compile main.tex with latex-dvips-ps2pdf explained above. Afterwards, check Images folder, you will find a PDF version for each EPS image. Done!
Thanks. I am looking for a way to run latex on the original to generate all the graphics in the document and save each in a filename.pdf file where filename is the name of the original eps file. Then I can include these pdf files in the original by deleting the eps extension. This way I do not have to run latex on each individual graphics. auto-pst-pdf does something like this but stores all pdf files in a single pdf file. Maybe a modification of it to store the graphics in individual pdf's is possible (or maybe already exists)
– per
Nov 15 '13 at 15:21
I have a latex file (root of a book) with each chapter input'd and each chapter has many eps files with different names, many of them with psfrag fragments. Say the name of .eps files are 1.eps, 2.eps,.., 600.eps. Is there a way that I can generate 1.pdf, 2.pdf,...600.pdf easily, short of running lated+dvips+ps2pdf 600 times on each figure?
– per
Nov 15 '13 at 18:34
I tried it, it puts all the three pdf graphics in a single file not in three different files. What I want here are three files example-image-a.pdf, example-image-b.pdf and example-image-c.pdf. The way that your suggestion works is very similar to using auto-pst-pdf. I want each graphic to be saved in one pdf file.
– per
Nov 16 '13 at 16:39
@per: If you are using legacy Windows (older than Windows 7), use#instead of=. What is your OS? Answer has been edited.
– kiss my armpit
Nov 17 '13 at 8:06
It did not work as suggested, but after I removed the -dAutoRotatePages=/None option in ps2pdf, it works. But the main problem still remains. This technique generated pdf files for each .eps file but does not include the psfrag substitutions in the resulting pdf file. The alternative solution should read includegraphics contents as well as all psfrag contents that come between the corresponding begin{figure} and end{figure} and generate the pdf file accordingly. Then, in the final run, to generate main.pdf with pdflatex, all psfrag commands should be removed.
– per
Nov 17 '13 at 8:42
|
show 4 more comments
Objectives and constraints
- Extracting all EPS images imported in the main input file without modifying the main input file heavily.
- Converting each of imported EPS images to PDF one and save it with its original file name.
Assumption
For the sake of best practice, I assume that you put all of your EPS images in a sub directory called
Images. It means that the directory structure is defined as follows.
other parents/project/Images/
other parents/project/main.tex
other parents/project/myextractor.sty
You have to follow this convention as the remaining code uses this structure. Of course you can change this directory structure but you also need to modify the code a bit (not much).
main.texandmyextractor.stywill be discussed shortly.
You are using Windows. If you are non-Windows users, please disabled the cleaning code mentioned in
myextractor.sty.
You know that you must compile the
main.texwith
latex -shell-escape main
dvips main
ps2pdf -dAutoRotatePages#/None main.ps
Notes: For non-Windows users, replace # with =.
Step 1
Create a package called myextractor.sty as follows. Save it as mentioned in the directory structure above.
% myextractor.sty
NeedsTeXFormat{LaTeX2e}[1994/06/01]
ProvidesPackage{myextractor}[2013/10/09 v0.01 LaTeX package for my own purpose]
RequirePackage{filecontents}
begin{filecontents*}{template.tex}
documentclass[preview,border=0pt,graphics]{standalone}
usepackage{graphicx}
graphicspath{{Images/}}
% Active the following code (between makeatletter and makeatother)
% if you want to cancel the effect of
% width, height and/or scale defined in includegraphics
%makeatletter
%define@key{Gin}{width}{}
%define@key{Gin}{scale}{}
%define@key{Gin}{height}{}
%makeatother
leteaexpandafter
begin{document}
%edefz{noexpandincludegraphics[varone]{vartwo}}z
eaincludegraphicsea[varone]{vartwo}
end{document}
end{filecontents*}
RequirePackage{graphicx}
RequirePackage{pgffor}
lettempincludegraphics
renewcommandincludegraphics[2]{%
temp[#1]{#2}%
immediatewrite18{latex -jobname=#2 -output-directory=Images unexpanded{"defvarone{#1} defvartwo{#2} input{template}"} && cd Images && dvips #2 && ps2pdf -dAutoRotatePages=/None #2.ps}%
% disable the following if you are not Windows users.
foreach ext in {dvi, ps, log, aux}{immediatewrite18{cd Images && cmd /c del #2.ext}}%
}
endinput
Read the comments given in the code carefully. They are as follows.
% Active the following code (between makeatletter and makeatother)
% if you want to cancel the effect of
% width, height and/or scale defined in includegraphics
%makeatletter
%define@key{Gin}{width}{}
%define@key{Gin}{scale}{}
%define@key{Gin}{height}{}
%makeatother
and
% disable the following if you are not Windows users.
foreach ext in {dvi, ps, log, aux}{immediatewrite18{cd Images && cmd /c del #2.ext}}%
Step 2
Modify your main.tex as follows
% main.tex
documentclass{book}
%usepackage{graphicx}
usepackage{myextractor}% automatically load graphicx
graphicspath{{Images/}}
begin{document}
chapter{A}
begin{figure}[hbtp]
centering
includegraphics[scale=.5]{A}
caption{A}
label{fig:A}
end{figure}
A ldots
chapter{B}
begin{figure}[hbtp]
centering
includegraphics[scale=.75]{B}
caption{B}
label{fig:B}
end{figure}
B ldots
chapter{B}
begin{figure}[hbtp]
centering
includegraphics[scale=1]{C}
caption{C}
label{fig:C}
end{figure}
C ldots
end{document}
The important notes are
%usepackage{graphicx}
usepackage{myextractor}% automatically load graphicx
graphicspath{{Images/}}
- Load
myextractorpackage beforegraphicxto preventgraphicxoverridesmyextractordefinition. Asmyextractorloadsgraphicxinternally, you actually can disablegraphicxinmain.tex.
graphicspathmust be specified as given above.
Step 3
Compile main.tex with latex-dvips-ps2pdf explained above. Afterwards, check Images folder, you will find a PDF version for each EPS image. Done!
Thanks. I am looking for a way to run latex on the original to generate all the graphics in the document and save each in a filename.pdf file where filename is the name of the original eps file. Then I can include these pdf files in the original by deleting the eps extension. This way I do not have to run latex on each individual graphics. auto-pst-pdf does something like this but stores all pdf files in a single pdf file. Maybe a modification of it to store the graphics in individual pdf's is possible (or maybe already exists)
– per
Nov 15 '13 at 15:21
I have a latex file (root of a book) with each chapter input'd and each chapter has many eps files with different names, many of them with psfrag fragments. Say the name of .eps files are 1.eps, 2.eps,.., 600.eps. Is there a way that I can generate 1.pdf, 2.pdf,...600.pdf easily, short of running lated+dvips+ps2pdf 600 times on each figure?
– per
Nov 15 '13 at 18:34
I tried it, it puts all the three pdf graphics in a single file not in three different files. What I want here are three files example-image-a.pdf, example-image-b.pdf and example-image-c.pdf. The way that your suggestion works is very similar to using auto-pst-pdf. I want each graphic to be saved in one pdf file.
– per
Nov 16 '13 at 16:39
@per: If you are using legacy Windows (older than Windows 7), use#instead of=. What is your OS? Answer has been edited.
– kiss my armpit
Nov 17 '13 at 8:06
It did not work as suggested, but after I removed the -dAutoRotatePages=/None option in ps2pdf, it works. But the main problem still remains. This technique generated pdf files for each .eps file but does not include the psfrag substitutions in the resulting pdf file. The alternative solution should read includegraphics contents as well as all psfrag contents that come between the corresponding begin{figure} and end{figure} and generate the pdf file accordingly. Then, in the final run, to generate main.pdf with pdflatex, all psfrag commands should be removed.
– per
Nov 17 '13 at 8:42
|
show 4 more comments
Objectives and constraints
- Extracting all EPS images imported in the main input file without modifying the main input file heavily.
- Converting each of imported EPS images to PDF one and save it with its original file name.
Assumption
For the sake of best practice, I assume that you put all of your EPS images in a sub directory called
Images. It means that the directory structure is defined as follows.
other parents/project/Images/
other parents/project/main.tex
other parents/project/myextractor.sty
You have to follow this convention as the remaining code uses this structure. Of course you can change this directory structure but you also need to modify the code a bit (not much).
main.texandmyextractor.stywill be discussed shortly.
You are using Windows. If you are non-Windows users, please disabled the cleaning code mentioned in
myextractor.sty.
You know that you must compile the
main.texwith
latex -shell-escape main
dvips main
ps2pdf -dAutoRotatePages#/None main.ps
Notes: For non-Windows users, replace # with =.
Step 1
Create a package called myextractor.sty as follows. Save it as mentioned in the directory structure above.
% myextractor.sty
NeedsTeXFormat{LaTeX2e}[1994/06/01]
ProvidesPackage{myextractor}[2013/10/09 v0.01 LaTeX package for my own purpose]
RequirePackage{filecontents}
begin{filecontents*}{template.tex}
documentclass[preview,border=0pt,graphics]{standalone}
usepackage{graphicx}
graphicspath{{Images/}}
% Active the following code (between makeatletter and makeatother)
% if you want to cancel the effect of
% width, height and/or scale defined in includegraphics
%makeatletter
%define@key{Gin}{width}{}
%define@key{Gin}{scale}{}
%define@key{Gin}{height}{}
%makeatother
leteaexpandafter
begin{document}
%edefz{noexpandincludegraphics[varone]{vartwo}}z
eaincludegraphicsea[varone]{vartwo}
end{document}
end{filecontents*}
RequirePackage{graphicx}
RequirePackage{pgffor}
lettempincludegraphics
renewcommandincludegraphics[2]{%
temp[#1]{#2}%
immediatewrite18{latex -jobname=#2 -output-directory=Images unexpanded{"defvarone{#1} defvartwo{#2} input{template}"} && cd Images && dvips #2 && ps2pdf -dAutoRotatePages=/None #2.ps}%
% disable the following if you are not Windows users.
foreach ext in {dvi, ps, log, aux}{immediatewrite18{cd Images && cmd /c del #2.ext}}%
}
endinput
Read the comments given in the code carefully. They are as follows.
% Active the following code (between makeatletter and makeatother)
% if you want to cancel the effect of
% width, height and/or scale defined in includegraphics
%makeatletter
%define@key{Gin}{width}{}
%define@key{Gin}{scale}{}
%define@key{Gin}{height}{}
%makeatother
and
% disable the following if you are not Windows users.
foreach ext in {dvi, ps, log, aux}{immediatewrite18{cd Images && cmd /c del #2.ext}}%
Step 2
Modify your main.tex as follows
% main.tex
documentclass{book}
%usepackage{graphicx}
usepackage{myextractor}% automatically load graphicx
graphicspath{{Images/}}
begin{document}
chapter{A}
begin{figure}[hbtp]
centering
includegraphics[scale=.5]{A}
caption{A}
label{fig:A}
end{figure}
A ldots
chapter{B}
begin{figure}[hbtp]
centering
includegraphics[scale=.75]{B}
caption{B}
label{fig:B}
end{figure}
B ldots
chapter{B}
begin{figure}[hbtp]
centering
includegraphics[scale=1]{C}
caption{C}
label{fig:C}
end{figure}
C ldots
end{document}
The important notes are
%usepackage{graphicx}
usepackage{myextractor}% automatically load graphicx
graphicspath{{Images/}}
- Load
myextractorpackage beforegraphicxto preventgraphicxoverridesmyextractordefinition. Asmyextractorloadsgraphicxinternally, you actually can disablegraphicxinmain.tex.
graphicspathmust be specified as given above.
Step 3
Compile main.tex with latex-dvips-ps2pdf explained above. Afterwards, check Images folder, you will find a PDF version for each EPS image. Done!
Objectives and constraints
- Extracting all EPS images imported in the main input file without modifying the main input file heavily.
- Converting each of imported EPS images to PDF one and save it with its original file name.
Assumption
For the sake of best practice, I assume that you put all of your EPS images in a sub directory called
Images. It means that the directory structure is defined as follows.
other parents/project/Images/
other parents/project/main.tex
other parents/project/myextractor.sty
You have to follow this convention as the remaining code uses this structure. Of course you can change this directory structure but you also need to modify the code a bit (not much).
main.texandmyextractor.stywill be discussed shortly.
You are using Windows. If you are non-Windows users, please disabled the cleaning code mentioned in
myextractor.sty.
You know that you must compile the
main.texwith
latex -shell-escape main
dvips main
ps2pdf -dAutoRotatePages#/None main.ps
Notes: For non-Windows users, replace # with =.
Step 1
Create a package called myextractor.sty as follows. Save it as mentioned in the directory structure above.
% myextractor.sty
NeedsTeXFormat{LaTeX2e}[1994/06/01]
ProvidesPackage{myextractor}[2013/10/09 v0.01 LaTeX package for my own purpose]
RequirePackage{filecontents}
begin{filecontents*}{template.tex}
documentclass[preview,border=0pt,graphics]{standalone}
usepackage{graphicx}
graphicspath{{Images/}}
% Active the following code (between makeatletter and makeatother)
% if you want to cancel the effect of
% width, height and/or scale defined in includegraphics
%makeatletter
%define@key{Gin}{width}{}
%define@key{Gin}{scale}{}
%define@key{Gin}{height}{}
%makeatother
leteaexpandafter
begin{document}
%edefz{noexpandincludegraphics[varone]{vartwo}}z
eaincludegraphicsea[varone]{vartwo}
end{document}
end{filecontents*}
RequirePackage{graphicx}
RequirePackage{pgffor}
lettempincludegraphics
renewcommandincludegraphics[2]{%
temp[#1]{#2}%
immediatewrite18{latex -jobname=#2 -output-directory=Images unexpanded{"defvarone{#1} defvartwo{#2} input{template}"} && cd Images && dvips #2 && ps2pdf -dAutoRotatePages=/None #2.ps}%
% disable the following if you are not Windows users.
foreach ext in {dvi, ps, log, aux}{immediatewrite18{cd Images && cmd /c del #2.ext}}%
}
endinput
Read the comments given in the code carefully. They are as follows.
% Active the following code (between makeatletter and makeatother)
% if you want to cancel the effect of
% width, height and/or scale defined in includegraphics
%makeatletter
%define@key{Gin}{width}{}
%define@key{Gin}{scale}{}
%define@key{Gin}{height}{}
%makeatother
and
% disable the following if you are not Windows users.
foreach ext in {dvi, ps, log, aux}{immediatewrite18{cd Images && cmd /c del #2.ext}}%
Step 2
Modify your main.tex as follows
% main.tex
documentclass{book}
%usepackage{graphicx}
usepackage{myextractor}% automatically load graphicx
graphicspath{{Images/}}
begin{document}
chapter{A}
begin{figure}[hbtp]
centering
includegraphics[scale=.5]{A}
caption{A}
label{fig:A}
end{figure}
A ldots
chapter{B}
begin{figure}[hbtp]
centering
includegraphics[scale=.75]{B}
caption{B}
label{fig:B}
end{figure}
B ldots
chapter{B}
begin{figure}[hbtp]
centering
includegraphics[scale=1]{C}
caption{C}
label{fig:C}
end{figure}
C ldots
end{document}
The important notes are
%usepackage{graphicx}
usepackage{myextractor}% automatically load graphicx
graphicspath{{Images/}}
- Load
myextractorpackage beforegraphicxto preventgraphicxoverridesmyextractordefinition. Asmyextractorloadsgraphicxinternally, you actually can disablegraphicxinmain.tex.
graphicspathmust be specified as given above.
Step 3
Compile main.tex with latex-dvips-ps2pdf explained above. Afterwards, check Images folder, you will find a PDF version for each EPS image. Done!
edited Nov 17 '13 at 8:05
answered Nov 15 '13 at 7:55
kiss my armpitkiss my armpit
12.9k20172404
12.9k20172404
Thanks. I am looking for a way to run latex on the original to generate all the graphics in the document and save each in a filename.pdf file where filename is the name of the original eps file. Then I can include these pdf files in the original by deleting the eps extension. This way I do not have to run latex on each individual graphics. auto-pst-pdf does something like this but stores all pdf files in a single pdf file. Maybe a modification of it to store the graphics in individual pdf's is possible (or maybe already exists)
– per
Nov 15 '13 at 15:21
I have a latex file (root of a book) with each chapter input'd and each chapter has many eps files with different names, many of them with psfrag fragments. Say the name of .eps files are 1.eps, 2.eps,.., 600.eps. Is there a way that I can generate 1.pdf, 2.pdf,...600.pdf easily, short of running lated+dvips+ps2pdf 600 times on each figure?
– per
Nov 15 '13 at 18:34
I tried it, it puts all the three pdf graphics in a single file not in three different files. What I want here are three files example-image-a.pdf, example-image-b.pdf and example-image-c.pdf. The way that your suggestion works is very similar to using auto-pst-pdf. I want each graphic to be saved in one pdf file.
– per
Nov 16 '13 at 16:39
@per: If you are using legacy Windows (older than Windows 7), use#instead of=. What is your OS? Answer has been edited.
– kiss my armpit
Nov 17 '13 at 8:06
It did not work as suggested, but after I removed the -dAutoRotatePages=/None option in ps2pdf, it works. But the main problem still remains. This technique generated pdf files for each .eps file but does not include the psfrag substitutions in the resulting pdf file. The alternative solution should read includegraphics contents as well as all psfrag contents that come between the corresponding begin{figure} and end{figure} and generate the pdf file accordingly. Then, in the final run, to generate main.pdf with pdflatex, all psfrag commands should be removed.
– per
Nov 17 '13 at 8:42
|
show 4 more comments
Thanks. I am looking for a way to run latex on the original to generate all the graphics in the document and save each in a filename.pdf file where filename is the name of the original eps file. Then I can include these pdf files in the original by deleting the eps extension. This way I do not have to run latex on each individual graphics. auto-pst-pdf does something like this but stores all pdf files in a single pdf file. Maybe a modification of it to store the graphics in individual pdf's is possible (or maybe already exists)
– per
Nov 15 '13 at 15:21
I have a latex file (root of a book) with each chapter input'd and each chapter has many eps files with different names, many of them with psfrag fragments. Say the name of .eps files are 1.eps, 2.eps,.., 600.eps. Is there a way that I can generate 1.pdf, 2.pdf,...600.pdf easily, short of running lated+dvips+ps2pdf 600 times on each figure?
– per
Nov 15 '13 at 18:34
I tried it, it puts all the three pdf graphics in a single file not in three different files. What I want here are three files example-image-a.pdf, example-image-b.pdf and example-image-c.pdf. The way that your suggestion works is very similar to using auto-pst-pdf. I want each graphic to be saved in one pdf file.
– per
Nov 16 '13 at 16:39
@per: If you are using legacy Windows (older than Windows 7), use#instead of=. What is your OS? Answer has been edited.
– kiss my armpit
Nov 17 '13 at 8:06
It did not work as suggested, but after I removed the -dAutoRotatePages=/None option in ps2pdf, it works. But the main problem still remains. This technique generated pdf files for each .eps file but does not include the psfrag substitutions in the resulting pdf file. The alternative solution should read includegraphics contents as well as all psfrag contents that come between the corresponding begin{figure} and end{figure} and generate the pdf file accordingly. Then, in the final run, to generate main.pdf with pdflatex, all psfrag commands should be removed.
– per
Nov 17 '13 at 8:42
Thanks. I am looking for a way to run latex on the original to generate all the graphics in the document and save each in a filename.pdf file where filename is the name of the original eps file. Then I can include these pdf files in the original by deleting the eps extension. This way I do not have to run latex on each individual graphics. auto-pst-pdf does something like this but stores all pdf files in a single pdf file. Maybe a modification of it to store the graphics in individual pdf's is possible (or maybe already exists)
– per
Nov 15 '13 at 15:21
Thanks. I am looking for a way to run latex on the original to generate all the graphics in the document and save each in a filename.pdf file where filename is the name of the original eps file. Then I can include these pdf files in the original by deleting the eps extension. This way I do not have to run latex on each individual graphics. auto-pst-pdf does something like this but stores all pdf files in a single pdf file. Maybe a modification of it to store the graphics in individual pdf's is possible (or maybe already exists)
– per
Nov 15 '13 at 15:21
I have a latex file (root of a book) with each chapter input'd and each chapter has many eps files with different names, many of them with psfrag fragments. Say the name of .eps files are 1.eps, 2.eps,.., 600.eps. Is there a way that I can generate 1.pdf, 2.pdf,...600.pdf easily, short of running lated+dvips+ps2pdf 600 times on each figure?
– per
Nov 15 '13 at 18:34
I have a latex file (root of a book) with each chapter input'd and each chapter has many eps files with different names, many of them with psfrag fragments. Say the name of .eps files are 1.eps, 2.eps,.., 600.eps. Is there a way that I can generate 1.pdf, 2.pdf,...600.pdf easily, short of running lated+dvips+ps2pdf 600 times on each figure?
– per
Nov 15 '13 at 18:34
I tried it, it puts all the three pdf graphics in a single file not in three different files. What I want here are three files example-image-a.pdf, example-image-b.pdf and example-image-c.pdf. The way that your suggestion works is very similar to using auto-pst-pdf. I want each graphic to be saved in one pdf file.
– per
Nov 16 '13 at 16:39
I tried it, it puts all the three pdf graphics in a single file not in three different files. What I want here are three files example-image-a.pdf, example-image-b.pdf and example-image-c.pdf. The way that your suggestion works is very similar to using auto-pst-pdf. I want each graphic to be saved in one pdf file.
– per
Nov 16 '13 at 16:39
@per: If you are using legacy Windows (older than Windows 7), use
# instead of =. What is your OS? Answer has been edited.– kiss my armpit
Nov 17 '13 at 8:06
@per: If you are using legacy Windows (older than Windows 7), use
# instead of =. What is your OS? Answer has been edited.– kiss my armpit
Nov 17 '13 at 8:06
It did not work as suggested, but after I removed the -dAutoRotatePages=/None option in ps2pdf, it works. But the main problem still remains. This technique generated pdf files for each .eps file but does not include the psfrag substitutions in the resulting pdf file. The alternative solution should read includegraphics contents as well as all psfrag contents that come between the corresponding begin{figure} and end{figure} and generate the pdf file accordingly. Then, in the final run, to generate main.pdf with pdflatex, all psfrag commands should be removed.
– per
Nov 17 '13 at 8:42
It did not work as suggested, but after I removed the -dAutoRotatePages=/None option in ps2pdf, it works. But the main problem still remains. This technique generated pdf files for each .eps file but does not include the psfrag substitutions in the resulting pdf file. The alternative solution should read includegraphics contents as well as all psfrag contents that come between the corresponding begin{figure} and end{figure} and generate the pdf file accordingly. Then, in the final run, to generate main.pdf with pdflatex, all psfrag commands should be removed.
– per
Nov 17 '13 at 8:42
|
show 4 more comments
I don't know if you intend to write LaTex on a huge amount of pictures, but I'm using Inkscape to do that. Basically when saving an image into .pdf format, there is a box to tick which allows for extracting all the texts and creates an ancillary tex file which places it automatically in the right place. In your .tex files, you replace includegraphics{mypix.pdf} by input{mypix.pdf_tex} (the file created by Inkscape).
Since it is just an open-and-save operation, I guess it may be possible to write some scripts to do it automatically on all files of a given folder
I don't know how this solves the problem. Could you show some example?
– Christian Hupfer
Dec 12 '14 at 15:37
@ChristianHupfer Assume you have a .pdf you intend to write latex on, you open your image with Inkspace, specify "load text as text". Then Inkspace recognises text fields. When you save your file again, you tick the box "pdf+Latex" and it creates a pdf without text and a tex files with all text fields, placed with commands such :put(0.09714286,0.14448413){rotatebox{90}{makebox(0,0)[lb]{smash{"the content of the text field"}}}}%Here Latex compiles the text, and you can modify it to put math... some more help here : [tug.ctan.org/tex-archive/info/svg-inkscape]
– clemlaflemme
Dec 15 '14 at 8:54
add a comment |
I don't know if you intend to write LaTex on a huge amount of pictures, but I'm using Inkscape to do that. Basically when saving an image into .pdf format, there is a box to tick which allows for extracting all the texts and creates an ancillary tex file which places it automatically in the right place. In your .tex files, you replace includegraphics{mypix.pdf} by input{mypix.pdf_tex} (the file created by Inkscape).
Since it is just an open-and-save operation, I guess it may be possible to write some scripts to do it automatically on all files of a given folder
I don't know how this solves the problem. Could you show some example?
– Christian Hupfer
Dec 12 '14 at 15:37
@ChristianHupfer Assume you have a .pdf you intend to write latex on, you open your image with Inkspace, specify "load text as text". Then Inkspace recognises text fields. When you save your file again, you tick the box "pdf+Latex" and it creates a pdf without text and a tex files with all text fields, placed with commands such :put(0.09714286,0.14448413){rotatebox{90}{makebox(0,0)[lb]{smash{"the content of the text field"}}}}%Here Latex compiles the text, and you can modify it to put math... some more help here : [tug.ctan.org/tex-archive/info/svg-inkscape]
– clemlaflemme
Dec 15 '14 at 8:54
add a comment |
I don't know if you intend to write LaTex on a huge amount of pictures, but I'm using Inkscape to do that. Basically when saving an image into .pdf format, there is a box to tick which allows for extracting all the texts and creates an ancillary tex file which places it automatically in the right place. In your .tex files, you replace includegraphics{mypix.pdf} by input{mypix.pdf_tex} (the file created by Inkscape).
Since it is just an open-and-save operation, I guess it may be possible to write some scripts to do it automatically on all files of a given folder
I don't know if you intend to write LaTex on a huge amount of pictures, but I'm using Inkscape to do that. Basically when saving an image into .pdf format, there is a box to tick which allows for extracting all the texts and creates an ancillary tex file which places it automatically in the right place. In your .tex files, you replace includegraphics{mypix.pdf} by input{mypix.pdf_tex} (the file created by Inkscape).
Since it is just an open-and-save operation, I guess it may be possible to write some scripts to do it automatically on all files of a given folder
answered Dec 12 '14 at 15:18
clemlaflemmeclemlaflemme
35349
35349
I don't know how this solves the problem. Could you show some example?
– Christian Hupfer
Dec 12 '14 at 15:37
@ChristianHupfer Assume you have a .pdf you intend to write latex on, you open your image with Inkspace, specify "load text as text". Then Inkspace recognises text fields. When you save your file again, you tick the box "pdf+Latex" and it creates a pdf without text and a tex files with all text fields, placed with commands such :put(0.09714286,0.14448413){rotatebox{90}{makebox(0,0)[lb]{smash{"the content of the text field"}}}}%Here Latex compiles the text, and you can modify it to put math... some more help here : [tug.ctan.org/tex-archive/info/svg-inkscape]
– clemlaflemme
Dec 15 '14 at 8:54
add a comment |
I don't know how this solves the problem. Could you show some example?
– Christian Hupfer
Dec 12 '14 at 15:37
@ChristianHupfer Assume you have a .pdf you intend to write latex on, you open your image with Inkspace, specify "load text as text". Then Inkspace recognises text fields. When you save your file again, you tick the box "pdf+Latex" and it creates a pdf without text and a tex files with all text fields, placed with commands such :put(0.09714286,0.14448413){rotatebox{90}{makebox(0,0)[lb]{smash{"the content of the text field"}}}}%Here Latex compiles the text, and you can modify it to put math... some more help here : [tug.ctan.org/tex-archive/info/svg-inkscape]
– clemlaflemme
Dec 15 '14 at 8:54
I don't know how this solves the problem. Could you show some example?
– Christian Hupfer
Dec 12 '14 at 15:37
I don't know how this solves the problem. Could you show some example?
– Christian Hupfer
Dec 12 '14 at 15:37
@ChristianHupfer Assume you have a .pdf you intend to write latex on, you open your image with Inkspace, specify "load text as text". Then Inkspace recognises text fields. When you save your file again, you tick the box "pdf+Latex" and it creates a pdf without text and a tex files with all text fields, placed with commands such :
put(0.09714286,0.14448413){rotatebox{90}{makebox(0,0)[lb]{smash{"the content of the text field"}}}}% Here Latex compiles the text, and you can modify it to put math... some more help here : [tug.ctan.org/tex-archive/info/svg-inkscape]– clemlaflemme
Dec 15 '14 at 8:54
@ChristianHupfer Assume you have a .pdf you intend to write latex on, you open your image with Inkspace, specify "load text as text". Then Inkspace recognises text fields. When you save your file again, you tick the box "pdf+Latex" and it creates a pdf without text and a tex files with all text fields, placed with commands such :
put(0.09714286,0.14448413){rotatebox{90}{makebox(0,0)[lb]{smash{"the content of the text field"}}}}% Here Latex compiles the text, and you can modify it to put math... some more help here : [tug.ctan.org/tex-archive/info/svg-inkscape]– clemlaflemme
Dec 15 '14 at 8:54
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f145130%2fpsfrag-substitute-when-using-pdflatex%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
auto-pst-pdf is more recommended for running PSTricks with
pdflatexand pstool is better recommended for psfrag withpdflatex. See Will Robertson's answer, author for both packages.– texenthusiast
Nov 15 '13 at 14:37
Please see your questions. None has an accepted answer. It is not good practically to leave too many questions with no accepted answers as if no answer satisfies you and you don't leave any comment for improvement. You should reconsider which answer helps and satisfies you best and accept it. Accepting is simply clicking the check mark button below the score of any answer.
– kiss my armpit
Nov 16 '13 at 7:04
Thanks, I was not aware of this. I have accepted those responses that were satisfactory and will continue to do this.
– per
Nov 17 '13 at 4:18