TeX - LaTeX Asked on January 5, 2021
My purpose is to use the endfloat
package to extract all figures (with their captions) in a separate pdf
file. I want to do it with a script combining bash command line and emacs-lisp.
I want to do that because, in my copy editor work, I need to compare the figures (and their captions) of the accepted version with the formatted version ones. I know this is not the perfect solution (but I think it should works in most cases) so different/better ideas are welcome.
This is my MWE (the mydoc.tex
file):
documentclass[11pt]{article}
pagestyle{empty}
usepackage{graphicx}
usepackage{blindtext}
usepackage[colorlinks=true,
,citecolor=blue
,linkcolor=blue]{hyperref}
begin{document}
section{Section 1}
label{section1}
blindtext
begin{figure}[t]
centering
includegraphics[width=.49columnwidth]{example-image-a}
caption{Dummy caption cite{1} (see figure~ref{fig3} in
section~ref{section3}).label{fig1}}
end{figure}
section{Section 2}
label{section2}
blindtext
begin{figure}[t]
centering
includegraphics[width=.49columnwidth]{example-image-b}
caption{Dummy caption cite{2} (see figure~ref{fig1} in
section~ref{section1}).label{fig2}}
end{figure}
section{Section 3}
label{section3}
blindtext
blindtext
begin{figure}[t]
centering
includegraphics[width=.49columnwidth]{example-image-c}
caption{Dummy caption cite{3} (see figure~ref{fig2}
section~ref{section2}).label{fig3}}
end{figure}
begin{thebibliography}{9}
bibitem{1}
Dummy bibibtem
bibitem{2}
Dummy bibibtem
bibitem{3}
Dummy bibibtem
end{thebibliography}
end{document}
First of all I want to generate and backup the .aux
file. I’ll compile with:
latexmk -pdf mydoc.tex; cp mydoc.aux mydoc-bk.aux
Then I’ll compile with:
pdflatex "nofiles"
"AtBeginDocument{usepackage[figuresonly,nolists]{endfloat}}"
"nonstopmode"
"input{mydoc.tex}"
to generate the mydoc.fff
file that contains:
begin{figure}[t]
centering
includegraphics[width=.49columnwidth]{example-image-a}
caption{Dummy caption cite{1} (see figure~ref{fig3} in
section~ref{section3}).label{fig1}}
end{figure}
efloatseparator
begin{figure}[t]
centering
includegraphics[width=.49columnwidth]{example-image-b}
caption{Dummy caption cite{2} (see figure~ref{fig1} in
section~ref{section1}).label{fig2}}
end{figure}
efloatseparator
begin{figure}[t]
centering
includegraphics[width=.49columnwidth]{example-image-c}
caption{Dummy caption cite{3} (see figure~ref{fig2}
section~ref{section2}).label{fig3}}
end{figure}
efloatseparator
Now I create a new file: mynewdoc.tex
(this is meant to be a temporary solution):
documentclass[11pt]{article}
pagestyle{empty}
usepackage{graphicx}
usepackage{blindtext}
usepackage[colorlinks=true,
,citecolor=blue
,linkcolor=blue]{hyperref}
defefloatseparator{clearpage}
begin{document}
input{mydoc.fff}
end{document}
That I’ll compile with:
pdflatex mynewdoc.tex
My question is: can I force (pdf)latex to compile using the backup .aux
file so to get the correct refs (obviously without working links) in my final pdf?
I think that should be disabled the writing of the .aux
file in some way because some of the labels
are already defined in the external .aux
file.
My solution. I resolved by renaming the
.aux
I want to be read inmynewdoc.aux
and puttingnofiles
in the preamble.
Alternative solution. I also found this alternative solution using the xcomment
package. After generating the correct .aux
file I will compile with:
pdflatex -jobname=mydoc
"RequirePackage{xcomment} xcomment{figure}"
"nofiles"
"AtBeginDocument{letoldendfigureendfigure"
"defendfigure{oldendfigureclearpage}}"
"input{mydoc.tex}"
I’ll have a warning becouse the nofiles
command does not take effect (can anybody help me with that?) but the generated pdf
file will be ok.
Ok, I wrote two Bash scripts that do the same thing.
Using the endfloat
package (I named it ExtractFiguresEndfloat.sh):
#!/bin/bash
TexFile=$1
latexmk -pdf $TexFile
pdflatex "nofiles"
"AtBeginDocument{usepackage[figuresonly,nolists]{endfloat}}"
"nonstopmode"
"input{$TexFile}"
pdflatex "defefloatseparator{clearpage}"
"nofiles"
"letolddocumentdocument"
"renewcommand{document}{olddocumentinput{jobname.fff}enddocument}"
"nonstopmodeinput{$TexFile}"
usage:
ExtractFiguresEndfloat.sh file.tex
Using the xcomment
package (I named it ExtractFiguresXcomment.sh):
#!/bin/bash
TexFile=$1
PREPRINT_ID=`basename $TexFile .tex`
latexmk -pdf $TexFile
pdflatex -jobname=$PREPRINT_ID
"RequirePackage{xcomment} xcomment{figure}"
"nofiles"
"AtBeginDocument{letoldendfigureendfigure"
"defendfigure{oldendfigureclearpage}}"
"nonstopmode"
"input{$TexFile}"
usage:
ExtractFiguresXcomment.sh file.tex
I tested on a few files and they work (the first one has a limitation because endfloat
wants the end{figure}
string to be placed at line beginning...).
I get:
Answered by Gabriele Nicolardi on January 5, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP