Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • LaTeX font on eps figures: cannot get writepsfrag package to work

    Hello,

    I cannot get writepsfrag to work. I am trying to have the same fonts on my Stata-produced figures and the rest of my LaTeX document.

    I am running the example from the writepsfrag help file:

    Code:
    * ssc install writepsfrag
    #delimit;
    twoway function y=normalden(x), range(-4 4)
    text(0.125 0 "\textbf{\color{blue}{Normal PDF:}}")
    text(0.090 0 "\(y=\frac{1}{\sigma\sqrt{2\pi}}e^{\frac{-(x-\mu)^2}{2\sigma^2}}\)")
    xlabel(-4 "\(-4\sigma\)" -2 "\(-2\sigma\)" 0 "\(\mu\)" 2 "\(2\sigma\)" 4 "\(4\sigma\)")
    xtitle("All text is set in {\LaTeX} font") ytitle("\(y\)");
    graph export normal.eps, as(eps);
    writepsfrag normal.eps using normal.tex, replace body(figure, caption("Normal Probability Density Function"));
    #delimit cr
    and adding it to Overleaf using the following code:

    Code:
    \documentclass[varwidth=true]{standalone}
    \usepackage[utf8]{inputenc}
    \usepackage{psfrag}
    
    \begin{document}
    
    \begin{figure}[htbp]
    \centering
    \psfrag{\\textbf{\\color{blue}{Normal PDF:}}}[c][c][1][0]{\normalsize \textbf{\color{blue}{Normal PDF:}}}
    \psfrag{\\(y=\\frac{1}{\\sigma\\sqrt{2\\pi}}e^{\\frac{-(x-\\mu)^2}{2\\sigma^2}}\\)}[c][c][1][0]{\normalsize \(y=\frac{1}{\sigma\sqrt{2\pi}}e^{\frac{-(x-\mu)^2}{2\sigma^2}}\)}
    \psfrag{0}[c][c][1][0]{\normalsize 0}
    \psfrag{.1}[c][c][1][0]{\normalsize .1}
    \psfrag{.2}[c][c][1][0]{\normalsize .2}
    \psfrag{.3}[c][c][1][0]{\normalsize .3}
    \psfrag{.4}[c][c][1][0]{\normalsize .4}
    \psfrag{\\(y\\)}[c][c][1][0]{\normalsize \(y\)}
    \psfrag{\\(-4\\sigma\\)}[c][c][1][0]{\normalsize \(-4\sigma\)}
    \psfrag{\\(-2\\sigma\\)}[c][c][1][0]{\normalsize \(-2\sigma\)}
    \psfrag{\\(\\mu\\)}[c][c][1][0]{\normalsize \(\mu\)}
    \psfrag{\\(2\\sigma\\)}[c][c][1][0]{\normalsize \(2\sigma\)}
    \psfrag{\\(4\\sigma\\)}[c][c][1][0]{\normalsize \(4\sigma\)}
    \psfrag{All text is set in {\\LaTeX} font}[c][c][1][0]{\normalsize All text is set in {\LaTeX} font}
    \resizebox{1\linewidth}{!}{\includegraphics{normal.eps}}
    \caption{Normal Probability Density Function}
    \end{figure}
    
    \end{document}
    However, the figure generated does not work the way it should:
    Click image for larger version

Name:	fig.PNG
Views:	1
Size:	33.6 KB
ID:	1549968

    Am I doing something wrong? Is there an alternative way to produce eps files in Stata with a font that corresponds to the LaTeX document? I tried downloading LM Roman 10 and setting it as the Stata graph font. It works within Stata, but when I export graphs as eps, they revert back to the standard font .
Working...
X