Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I used the OzTeX implementation of TeX, also I used to typeset my docs in plain TeX, not LaTeX for me, so I had no problem to insert an image using the OzTeX, now I'm back to TeX docs, am using the TeXWorks frontend, but I can't insert an .eps image file, it seems the \includegraphics macro its only for LaTeX, so I can't use it, any idea on how to insert an image when using plain TeX?

share|improve this question

4 Answers 4

You can use the simple epsf package which is designed for plain TeX:

\input epsf
%optional \epsfxsize=dimen or \epsfysize=dimen
\epsfbox{filename.eps}
share|improve this answer

By far the easiest approach here is to use miniltx to allow you to use LaTeX's graphics package with plain TeX:

\input miniltx %
\input graphicx.sty %
\includegraphics{<filename>}
\bye

or

\input graphicx.tex %
\includegraphics{<filename>}
\bye

(See comments for the minor differences here.)

The only thing you will need to watch is that TeXworks is designed around a PDF-based workflow. Thus you will need to convert your .eps files to .pdf format using epstopdf and then use pdfTeX in TeXworks. (In LaTeX, there is now automatic conversion method from .eps to .pdf files, but this does not apply to plain TeX.)

share|improve this answer
    
Is there a difference between this and simply \input graphicx.tex (no miniltx)? –  Alan Munn Jul 18 '12 at 18:27
    
@AlanMunn I've simply gone with 'what I know'. A quick look at graphicx.tex shows it loads miniltx, adds a default driver line (dvips) and tidies up the catcode of @ using \resetatcatcode. The last point might make it very slightly preferable, but it's not a bit difference. –  Joseph Wright Jul 18 '12 at 18:32
1  
@JosephWright Also the automatic conversion from EPS to PDF for pdfTeX will work, if package epstopdf-base is loaded after graphicx: \input miniltx \def\Gin@driver{pdftex.def} \input graphicx.sty \input epstopdf-base \resetatcatcode –  Heiko Oberdiek Dec 25 '14 at 16:36

For pdftex users the \pdfximage approach might seem appealing. The \pdfximage command creates an image object. The dimensions can be controlled in a similar way to a rule, i.e.

\pdfximage width ... height ... depth ... <general text>

where <general text> is the file name. (\pdfximage has many more parameters which can be looked up in the pdftex manual. For advanced things such as adjusting the bounding box also consult the manual.)

Still, \pdfximage only creates an object but does not insert anything yet. Therefore \pdfrefximage has to be used. The command

\pdfrefximage <integer>

places a whatsit including the image stored in the object referred to by <integer> in the output at shipout. In principle one could output the number corresponding to each image object, write them down and then later do, e.g. \pdfrefximage3. This is tedious and error prone, though. That's why there is \pdflastximage which is a count register always containing the number of the last \pdfximage, so including an image can be boiled down the following code

\pdfximage width 3cm {example-image-a.pdf}
\pdfrefximage\pdflastximage
\bye

TL;DR: See the code right above this line

share|improve this answer

The \inspic macro is provided by opmac.tex. You can set \picwidth register or \picheight register (or both, but the aspect is probably deformed in such case) and you can type \inspic file.jpg or \inspic file.pdf etc.

\input opmac

\picwidth=3cm \inspic file.png
\bye

You can look into opmac.tex to get the ispiration how this macro is defined at primitive level:

\def\inspic #1 {\hbox{%
    \pdfximage \ifdim\picwidth=0pt \else width\picwidth\fi 
               \ifdim\picheight=0pt \else height\picheight\fi {\picdir#1}%
    \pdfrefximage\pdflastximage}}

This works in pdfTeX. When XeTeX is used then the additional opmac-xetex.tex macro file is loaded and the \inspic macro is redefined:

\def\inspic #1 {\hbox{\def\tmp##1.pdf##2\relax{%
   \ifnum\strcmp{##2}{.pdf}=0 \XeTeXpdffile \else \XeTeXpicfile \fi}%
   \lowercase{\tmp #1}.pdf\relax \picdir#1
       \ifdim\picwidth=0pt \else width\picwidth\fi
       \ifdim\picheight=0pt \else height\picheight\fi}}

The main complication of this code is the fact that XeTeX needs to use different primitive for PDF including (\XeTeXpdffile) and different for another bitmap images (\XeTeXpicfile`).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.