# Automatically replace/render axis ticks with Psfrag

Me and a friend are using psfrag to include and edit eps figures in our reports. However, when including MatLab plots, the fonts of the text that is not replaced is the font exported by MatLab. This has as a result that the values on the axis are not rendered in the LaTeX font.

Is there a way to do this automatically? Doing it by hand would be a real hassle that we don't want to go through.

-
psfrag relies on the EPS handling the text in a fairly simple way. Modern PS drivers can compress, subset and otherwise obfuscate the Postscript such that psfrag does not find the text. If you look at the EPS file in a text editor can you see anything that looks like your original text as a PostScript string in (..) brackets? –  David Carlisle Jun 8 '12 at 10:44
Thank you for your reply. The problem is not that psfrag doesn't work; it works well. However, the thing is that we don't want to write a line for every single number we want to replace. In some way we want to replace the blue bordered numbers with the standard LaTeX font. See here (I can't include images): i.imgur.com/l0Qdu.png If we look in a text editor, indeed we see the brackets. –  Simon van Veen Jun 8 '12 at 11:00
OK so you mean if you went \psfrag{-0.2}{$-0.2$} then that label (only) would use the latex setting, and you want an easy way to do them all? –  David Carlisle Jun 8 '12 at 11:25
Indeed! If it is possible without typing any number. –  Simon van Veen Jun 8 '12 at 11:38

I think you need to type some numbers, but the following would mean you just have to do

\psfragloop{-10}{10}{2}
\psfragloop{-150}{150}{50}


to specify (*10) the start and end values and the step size along each axis.

As posted it just types out but if you comment that and uncomment %\x the it should execute the replacements. I get

macro:->\psfrag {-1}{$-1$}
macro:->\psfrag {-0.8}{$-0.8$}
macro:->\psfrag {-0.6}{$-0.6$}
macro:->\psfrag {-0.4}{$-0.4$}
macro:->\psfrag {-0.2}{$-0.2$}
macro:->\psfrag {0}{$0$}
macro:->\psfrag {0.2}{$0.2$}
macro:->\psfrag {0.4}{$0.4$}
macro:->\psfrag {0.6}{$0.6$}
macro:->\psfrag {0.8}{$0.8$}
macro:->\psfrag {1}{$1$}
macro:->\psfrag {-15}{$-15$}
macro:->\psfrag {-10}{$-10$}
macro:->\psfrag {-5}{$-5$}
macro:->\psfrag {0}{$0$}
macro:->\psfrag {5}{$5$}
macro:->\psfrag {10}{$10$}
macro:->\psfrag {15}{$15$}


From running this:

\makeatletter

\def\tenth{%
\ifnum\count@<\z@-\fi
\expandafter\xtentha\number\ifnum\count@<\z@-\fi\count@\relax}

\def\xtentha#1#2{%
\ifx\relax#2%
0\ifx0#1\else.#1\fi
\else
#1\expandafter\xtenth\expandafter#2%
\fi}

\def\xtenth#1#2{%
\ifx\relax#2%
\ifx0#1\else.#1\fi
\else
#1\expandafter\xtenth\expandafter#2%
\fi}

\def\psfragloop#1#2#3{%
\count@#1
\loop
\edef\x{\noexpand\psfrag{\tenth}{$\tenth$}}%
%\x
\typeout{\meaning\x}%
\ifnum\count@<#2