# 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
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.9258159399032593, "perplexity": 2297.0457319797847}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.3, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2015-32/segments/1438043058631.99/warc/CC-MAIN-20150728002418-00265-ip-10-236-191-2.ec2.internal.warc.gz"}