3

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.

jarnosc
  • 4,266
  • 2
    check the pdftex documentation, texdoc pdftex-a, it describes the low-level commands. Or study the latex graphicx driver pdftex.def. – Ulrike Fischer Jun 17 '21 at 11:38
  • 4
    See also https://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. – Daniel Bandeira Jun 17 '21 at 11:46
  • Ulrike - good suggestion. Thank you! – Daniel Bandeira Jun 17 '21 at 11:48
  • I never claimed it was the same question. I pointed out that that one answer given there might be useful in your case. – campa Jun 17 '21 at 12:17
  • 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. – John Kormylo Jun 17 '21 at 12:49
  • The insbox plain TeX macros package defines \InsertBoxL, \InsertBoxR and \InsertBoxC commands. – Bernard Jun 17 '21 at 13:49
  • @JohnKormylo TeX does not have any graphics capability whatsoever; PDFTeX does. My guess is that the OP still cannot tell the difference between an engine and a format. – jarnosc Jun 18 '21 at 01:58
  • so, my guess is that @campa's comment is right on the spot: the Plain format is oblivious to graphics inclusion: you need either a DVI driver or a suitable engine to do the job. Henri Menke's answer gives the basic clues to include graphics (jpg, png) with the PDFTeX engine; and if the OP wants to go the DVI way, they have to check the manual for dvipdf[m[x]], because dvips cannot handle png/jpg. – jarnosc Jun 18 '21 at 02:18
  • David Carlisle gives a simple example in his answer to this question – jarnosc Jun 21 '21 at 05:26
  • also related (with example code for XeTeX): https://tex.stackexchange.com/q/307370/52679 – jarnosc Jun 22 '21 at 01:23
  • You could look into bm2font. Apparently it converts bitmap images (like GIF, but I don't think it works with PNG so you'd have to convert your PNG to GIF first) to PK fonts which can then be used by plain TeX. – étale-cohomology Apr 14 '22 at 17:09

2 Answers2

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.

jarnosc
  • 4,266
3

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.

wipet
  • 74,238
  • 1
    \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 06:37
  • 1
    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
  • 1
    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
  • 3
    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