1

How could I insert a image in plain TeX, having a good control over its positions and scale, using no additional library (supposedly, a lot of ps commands as argument of \special)? I am intend to work with pdftex and using a png file. No problem in using tex -> dvips -> ps2pdf.

Thanks in advance.

PS: I want to understand in a low level how TeX operates for this kind of problem.

11
  • 2
    check the pdftex documentation, texdoc pdftex-a, it describes the low-level commands. Or study the latex graphicx driver pdftex.def. Jun 17 '21 at 11:38
  • 4
    See also tex.stackexchange.com/q/63789/82917 (in particular Henri Menke's answer).
    – campa
    Jun 17 '21 at 11:39
  • Campa, tex.stackexchange.com/q/63789/82917 - this question is different from mine. Jun 17 '21 at 11:46
  • Ulrike - good suggestion. Thank you! Jun 17 '21 at 11:48
  • 1
    Plain TeX has no graphics capability whatsoever. Instead one would use \special{...} to pass image files directly to the DVI where hopefully the viewer would convert and display them. Jun 17 '21 at 12:49
3

The Plain format does not provide any graphics facilities; those are provided by the engine or the DVI driver.

Since you mention that you mean to use PDFTeX, I suggest to you to grab the manual and read sections 7.9 and 8. The same approach should work, to the best of my knowledge, with LuaTeX, though the engine is far bigger and more complex. XeTeX also supports different graphics formats; read section 6 of the XeTeX Reference Guide.

Since dvips does not support png/jpg graphics, the way to include graphics in those formats via DVI files is by using the dvipdf[m[x]] driver; see section 8 of the manual for further details.

If, however, you still want to mess with including PostScript files or instructions directly, via \specials, and then process them with dvips, read sections 5.1 and 5.3 of the dvips manual.

The graphics-pln package extends the Plain format to support LaTeX style graphics inclusion via miniltx; you may learn something by reading the source code.

1

OPmac are macros for plain TeX, they provide a macro \inspic which inserts the graphics using \pdfximage and \pdfrefximage primitives. You can use OPmac macros or read the implementation of the \inspic macro and inspire. The implemetation is only four lines of code (unlike 200 lines of graphicx). OPTeX is LuaTeX+PlainTeX+OPmac, the \inspic macro including its implementation is documented at page 136 of the OpTeX manual.

5
  • \inspic works in XeTeX too, see opmac-xetex.tex. IMHO, it is better to do simple things with single engine (like OpTeX) than solve problems much more complicated way for various engines or output devices. Of course, there is no standard way to deal graphics in TeX, but if we select one engine, we can do very straightforward macros.
    – wipet
    Jun 19 '21 at 6:37
  • When user use \input opmac and \inspic then \inspic works in pdfTeX with PDF output, luaTeX and XeTeX. What primitives are used is typically not important for users. So, the notice "\inspic is supported only in PDFTeX" is at least inaccurate.
    – wipet
    Jun 21 '21 at 12:47
  • Yes, this specific "user" wants primitive solution. I give the answer: you can see the primitive solution from opmac.tex macro file, see four related lines here. Of course, if somebody needs a general solution for all back-ends, then there is no simple four lines, but user needs to create many branches of his macros. But user asks for simplicity, which is not to take account all backends nor reading and inspiring from graphics.sty (600 lines of code plus reads trig.sty: 100 lines plus graphics.cfg: 60 lines plus pdftex.def: 680 lines) nor graphicsx.sty (200 lines plus the same input files).
    – wipet
    Jun 22 '21 at 11:26
  • 2
    The "general case" is impossible because there is no standard of including graphics in TeX. Imagine various \specials for HP, Inkjet languages, more more languages of various historical devices, PostScript, dvi-to-something drivers etc., etc. My answer selects one most typically used backend and illustrates that things can be simple.
    – wipet
    Jun 22 '21 at 17:15
  • If you fear that I have "hatred for LaTeX" then your fearings are unfounded. But this is off topic, OP didn't asked for LaTeX solution and I show non-LaTeX solution. May be, your fearing blinds you more often than not... :).
    – wipet
    Jun 22 '21 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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