# How to include a .bmp image in XeTex using plain TeX source file

Using XeTeX, I would like to insert a bitmap image file which is in .bmp format, or alternatively, the same image in a .jpg format. I am using plain TeX, not LaTeX.

Using PCTeX version 6,

\special{bmp:nhsealBW.bmp x=1in y=1in}


puts the .bmp image at the current location.

With pdfTeX I was using a set of pdfTeX special commands which are not available in XeTeX:

\newbox\stateseal

\setbox\stateseal\hbox{\pdfximage height 1in width 1in {nhsealbw.jpg}
\pdfrefximage\pdflastximage}


Puts the .jpg image into the box and

\copy\stateseal


inserts it at the current location.

How do I do that in XeTeX?

• Please use 4 spaces to indent code blocks and back ticks for inline code. For blocks, you can highlight them and then click the {} button or ctrl+k.
– cfr
May 1 '16 at 23:54
• Have you looked at PGF/TikZ? Although it recommends graphicx where that's an option (obviously not here), it also have image inclusion capabilities. You just have to declare the image first, if I remember rightly.
– cfr
May 2 '16 at 0:08
• What would that look like in plain TeX source file? And where does PGF/TikZ come from? Thank you.
– GAS4
May 2 '16 at 0:30
• What do you mean where does it come from? It is part of all standard TeX distributions, like other packages.
– cfr
May 2 '16 at 0:44
• See section 105 of the manual. Actually, it won't help as you are using XeTeX. If pdfTeX is an option, you can use PGF image declaration and inclusion with plain TeX. Otherwise, it only works with the LaTeX format, apparently.
– cfr
May 2 '16 at 0:55

The simplest way is to:

1. Convert image_01.bmp to image_01.eps [the imagemagik suite will do this.

2. Use the following PSTRICKS command \centerline{\epsfysize = 5.0truecm\epsfbox{image_01.eps}}

[see do-it-yourself-tex on CTAN for the import PSTRICKS commands, etc]

• Thank you. I will give it a try. Is imagemagik suite on any TL distributions or do I get it from imagemagick.org?
– GAS4
Mar 31 '19 at 22:03

It is possible to use the XeTeX primitives to query the image size and specify the image inclusion to xdvipdfmx driver, but even in plain TeX using system-specific \special is painful and makes switching tex engines or drivers more complicated than need be.

You can use the same driver independent image inclusion macros as latex, which are already set up to do the right thing for bmp files with xetex.

from the plain xetex file

\input graphicx

a work of art:

\includegraphics{man.bmp}

\bye


where man.bmp is

• But is it a your picture with your hands:-)? +1. Aug 25 '18 at 21:27
• I need to query the image size so I can position the image without trial & error. Using Xetex primitives, can you demonstrate with your example please? Thank you.
– GAS4
Sep 12 '18 at 10:44
• @GAS4 easiest is to use \box0\hbox{\includegraphics{man}} then use \ht0 and \wd0 for the height and width. and finally \box0 to use the image Sep 12 '18 at 12:06
• @GAS4 I guess you figured it out, but for any future readers, my comment above should start \setbox0 not \box0 Sep 12 '18 at 18:01

Old question, but it should be pointed out that you can just do

\XeTeXpicfile <filename> [scaled <int> width <dimen> height <dimen>]


with XeTeX.

More options can be found in the reference document.

graphviz is available for many platforms (in particular it is on most LINUX distributions); see: https://graphviz.org/download/ it may already be there; you want the "convert" command: You can test via:

convert picture.bmp picture.eps


There are probably other convertors for your system; probably based on graphviz.

• Actually convert does not belong to Graphviz, but to ImageMagick, which is a dependency of Graphviz (see apt-cache rdepends graphviz) and is installed too. Apr 13 '19 at 1:43
• Sorry about writing "graphviz" instead of "imagemagick"; thank you Phelype for correcting me. I had been using the former all day and I inadvertently typed "graphviz". The best place for determining where to obtain a version of imagemagick for your system is: en.wikipedia.org/wiki/ImageMagick Apr 14 '19 at 15:39