![Getting psfrag to work in pdflatex](https://writelatex.s3.amazonaws.com/published_ver/29205.jpeg?X-Amz-Expires=14400&X-Amz-Date=20240831T233108Z&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAWJBOALPNFPV7PVH5/20240831/us-east-1/s3/aws4_request&X-Amz-SignedHeaders=host&X-Amz-Signature=19b446923aa6ce0636474dfd90950b836edd9d895f30315eb5e1b99d340a2299)
Getting psfrag to work in pdflatex
Auteur
Overleaf
Last Updated
il y a un an
License
Creative Commons CC BY 4.0
Résumé
An example using the pstool
package to get \psfrag
commands working with .eps images in pdflatex.
![Getting psfrag to work in pdflatex](https://writelatex.s3.amazonaws.com/published_ver/29205.jpeg?X-Amz-Expires=14400&X-Amz-Date=20240831T233108Z&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAWJBOALPNFPV7PVH5/20240831/us-east-1/s3/aws4_request&X-Amz-SignedHeaders=host&X-Amz-Signature=19b446923aa6ce0636474dfd90950b836edd9d895f30315eb5e1b99d340a2299)
An example using the pstool
package to get \psfrag
commands working with .eps images in pdflatex.
\documentclass[12pt,a4paper]{article}
\usepackage[margin=2cm,a4paper]{geometry}
\usepackage{parskip}
\title{Getting psfrag to work in pdflatex }
\usepackage[T1]{fontenc}
\usepackage{ebgaramond}
\usepackage{newtxmath}
\usepackage{graphicx}
\usepackage[process=all]{pstool}
\usepackage{hyperref}
%%%%%
%% NOTE IF LOADING hyperref PACKAGE
%% These lines are required ≥TL2020 due to
%% incompatibility between hyperref and preview
%% (See https://github.com/latex3/hyperref/issues/166#issuecomment-760157370)
\makeatletter
\providecommand\HyPL@Entry[1]{}
\AddToHook{env/document/begin}{%
\@ifpackageloaded{preview}{
\ifPreview
\let\Hy@FirstPageHook\relax
\let\Hy@EveryPageAnchor\relax
\fi}{}}
\makeatother
\begin{document}
You will still need a \texttt{.eps} image file; there is no \texttt{pdffrag} package that works for \texttt{.pdf} files.
If you want to use the \texttt{[process=all]} option for \texttt{pstool}, add a custom \texttt{latexmkrc} file that contains this line:
\begin{verbatim}
$hash_calc_ignore_pattern{'pdf'} = '^/(CreationDate|ModDate|ID) ';
\end{verbatim}
to avoid infinite compiling leading to a timeout on Overleaf.
Alternatively, you may want to work out all the \verb|\psfrag| commands in a separate project with \verb|\usepackage{psfrag}| and the LaTeX+dvipdf engine (see \url{https://www.overleaf.com/latex/examples/psfrag-example/tggxhgzwrzhn}), and once you've finalised that, copy the code into your main project (using pdflatex) and replace with \verb|\usepackage{pstool}| and \verb|\psfragfig| instead.
\begin{figure}[h!]
\centering
\psfragfig[width=0.6\linewidth]{example}{%
\psfrag{p1}{$p_1$}
\psfrag{p2}{$p_2$}
\psfrag{p3}{$p_3$}
\psfrag{\\tex[B][B]\{Plot of \$\\sin(t)\$ and \$\\cos(t)\$\}}{Plot of $\sin(t)$ and $\cos(t)$}
\psfrag{\\tex[t][t]\{\$t\$\}}{$t$}
\psfrag{\\tex[B][B]\{\$\\sin(t)\$, \$\\cos(t)\$\}}{$\sin(t)$, $\cos(t)$}
\psfrag{-1}{-1}
\psfrag{-0.2}{-0.2}
\psfrag{-0.4}{-0.4}
\psfrag{-0.6}{-0.6}
\psfrag{-0.8}{-0.8}
\psfrag{0}{0}
\psfrag{0.2}{0.2}
\psfrag{0.4}{0.4}
\psfrag{0.6}{0.6}
\psfrag{0.8}{0.8}
\psfrag{1}{1}
\psfrag{2}{2}
\psfrag{4}{4}
\psfrag{6}{6}
\psfrag{8}{8}
\psfrag{10}{10}
}
% \includegraphics[width=.6\linewidth]{example}
\caption{The same EPS image with psfragfig}
\end{figure}
\end{document}