1

I try to put a graphics file inside a pspicture, like this:

\documentclass{article} 

\usepackage[crop=off]{pstricks}
\usepackage{auto-pst-pdf}
\usepackage{graphicx}
\psset{unit=1mm}

\begin{document}

\begin{pspicture}(100,100)
    \psframe[fillcolor=green,fillstyle=solid](0,0)(70,70)
    \rput(10,10){
        \includegraphics[width=50mm,height=50mm]{graphics.jpg}
    }
\end{pspicture}

\end{document}

The PDF file shows only a green square, and I get an error message:

Error: /undefined in Operand stack: Execution stack: %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1977 1 3 %oparray_pop 1976 1 3 %oparray_pop 1960 1 3 %oparray_pop 1852 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- Dictionary stack: --dict:1199/1684(ro)(G)-- --dict:0/20(G)-- --dict:120/200(L)-- --dict:96/300(L)-- --dict:46/200(L)-- Current allocation mode is local Last OS error: No such file or directory Current file position is 88848 GPL Ghostscript 9.18: Unrecoverable error, exit code 1

system returned with code 256

When I put the "includegraphics" line outside the "pspicture", I do not get the error message, but the graphics is shown separately from the green square.

How can I make includegraphics work inside pspicture?

2 Answers 2

2

The well known method is as follows. Compile it with xetex.

\documentclass[pstricks,preview,margin=10mm]{standalone} 
\usepackage{graphicx}
\newbox\temp
\savebox\temp{\includegraphics[scale=.5]{bobo.jpg}}

\psset
{
    xunit=\dimexpr\wd\temp/10\relax,
    yunit=\dimexpr\ht\temp/10\relax
}

\begin{document}
\begin{pspicture}[showgrid=top](-5,-5)(5,5)
    \rput(0,0){\usebox\temp}
    \psframe[linecolor=red](-5,-5)(5,5)
\end{pspicture}
\end{document}

enter image description here

1
1

After some reading and googling, I found the following solution:

  • Convert the image to eps format (e.g. using gimp)
  • Use "epsfig" instead of "includegraphics".

Here is the edited example, with the modified lines marked:

\documentclass{article} 

\usepackage[crop=off]{pstricks}
\usepackage{auto-pst-pdf}
\usepackage{epsfig}   %%%%%%%%%%%%%%
\psset{unit=1mm}

\begin{document}


\begin{pspicture}(100,100)
\psframe[fillcolor=green,fillstyle=solid](0,0)(70,70)
\rput[bl](10,10){
   \epsfig{file=graphics.eps,width=50mm,height=50mm}%%%%%%%%%%%%%%

}
\end{pspicture}

\end{document}
3
  • 2
    You should be able to do this with regular \includegraphics and a converted EPS rather than using (the obsolete) epsfig.
    – Werner
    Commented Jan 8, 2017 at 8:08
  • 2
    please don't use epsfig, it was written in 1993 to emulate an old package of that name that was popular in the 1980s, using it in a new document in 2017 is very odd (and it just re-arranges the arguments and then calls \includegraphics internally) Commented Jan 8, 2017 at 11:41
  • \rput[lb](x,y){\includegraphics[...]{...}}
    – user2478
    Commented Jan 8, 2017 at 21:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .