[XeTeX] Inlined images?

Heiko Oberdiek heiko.oberdiek at googlemail.com
Tue Apr 12 20:37:47 CEST 2011


On Tue, Apr 12, 2011 at 11:01:57AM -0700, Mike Pomax Kamermans wrote:

> On 4/12/2011 6:31 AM, Jérôme Etévé wrote:
> >I'm using LaTeX (XeTeX) to produce documents programmatically and some
> >of them include images gathered from a database, so I'm looking for a
> >way to embed those images in my document without having to write them
> >to temporary files whilst I'm processing my LaTeX.
> 
> To follow up on Heiko's comment, a question: whether you are writing
> the images to temp files yourself, and pointing to those images in
> your LaTeX source, or whether you include them as some binary data
> in the .tex file, which is then decoded and written to temporary
> files by LaTeX so that it can include them, the intermediate result
> is the same: temporary files are going to be written to disk.
> 
> From an editorial point of view it would be much safer to stay the
> course you are on now, making sure your code generates the .tex
> source as well as writing the images as temporary files, with a
> cleanup once LaTeX is done compiling to get rid of all the temporary
> files that were necessary during the run. LaTeX is going to generate
> quite a number of temporary files anyway (.aux, .log, .toc, etc.
> etc.) that need to be cleaned up after the compilation run, and your
> system is clearly capable of writing to disk, so I don't quite
> understand why writing the images to temp files is undesirable.

Images are usually binary files. But TeX can only write text files,
especially it adds a new line marker at the line end (\write).
Also it depends on the TeX executable and its option settings,
how non-printable characters are put into the file.
(You don't want to have a notation like ^^@, ^^A, ... in the
file).

> Is there a benefit to only writing a single .tex file and calling
> TeX over writing a .tex file + image files, calling TeX and then
> performing cleanup when it completes without errors?

You can include the base64/hex/... images in the TeX file,
different methods are available, e.g.:
* Enviroment/package `filecontents'
* docstrip

Then the encoded text image files are converted to the
binary image files. It can be done by TeX only if the
TeX engine knows the `shell escape' feature and if this
feature is enabled.
  Cleanup: TeX can't delete files. Thus again the
`shell escape' feature is needed. But depending on the
driver the image files must not be deleted. For example,
DVI driver usually only embed the image file name references,
but not the images.

Yours sincerely
  Heiko Oberdiek


More information about the XeTeX mailing list