Skip to main content

The PreTeXt Guide

Subsection 4.14.6 Copies of Images

Sometimes you want to use the same image more than once. Putting it in a <figure> and then making a cross-reference (<xref>) can work well in HTML output since it will be available as a knowl. However in a static format (PDF, print) the reader will need to chase the cross-reference.
For a raster image, you can just point to the file again with the @source attribute. You are free to wrap it in a figure and thus change the caption. It will get a new number as a new figure, and you will need to assign a new unique @xml:id attribute. Maybe appending -copy-2, or similar, to the @xml:id will be helpful.
If you have a figure generated from source code (such as in TikZ) you really do not want to edit and maintain two copies that may not stay in sync. Instead, you can place the code into a file and xinclude it twice. Study Section 4.35 carefully, and note that this is an excellent place to take advantage of setting the @parse attribute to text (no need to escape problematic XML characters). Notice that when you generate images, you will have two image files with identical contents, but different names. This is no place for false optimization. Bits are cheap and your time is valuable. It is far more important to only maintain a single copy of the source, than to be caught up with the “waste” of having two copies of the same file (and which are managed for you). We demonstrate this with the sample book, since it is all set up with the xinclude mechanism. See the two plots of the 8-th roots of unity in the complex numbers section of the chapter on cyclic groups.