GNU TeXmacsUser manualReferenceAboutEnglish
Images in documents

1.The image primitive

An image is included with

<image|file|width|height|x-offset|y-offset>

(see graphics primitives for the user level description). It is typeset by concater_rep::typeset_image in

Typeset/Concat/concat_active.cpp

, which requires exactly five arguments and proceeds as follows.

The file.
If the first argument evaluates to a string, it is the name of the file, in Cork encoding, relative to the document (env->base_file_name). It is converted to UTF-8 and resolved; a name without suffix is also tried with the suffixes .eps and .pdf, and a file which cannot be found is replaced by $TEXMACS_PATH/misc/pixmaps/unknown.ps. An empty name gives the error “no image”.

If the first argument is a tuple (tuple (raw-data bytes) name), the image is embedded in the document. It is then designated by a ramdisc URL (url_ramdisc,

System/Classes/url.cpp

) whose root holds the bytes themselves, followed by the file name image.name, so that the suffix of the original file determines the format. The file functions (load_string, exists, …) recognize such URLs, and the converters which need a real file materialize them into temporary files.

The size.
The original size is obtained with image_size (see image files), converted from points to logical units at the resolution env->dpi. While the width and height arguments are evaluated, the environment variables w-length and h-length are set to the original width and height, so that the length units w and h, and percentages, refer to the size of the image: a width of 50% is half the original width. An empty width or height is computed from the other dimension so as to keep the aspect ratio; if both are empty, the original size is used. A non positive result is replaced by a quarter of the original size.
The offset.
The offsets are evaluated in the same way, with w-length and h-length now set to the final size, and the image box is shifted accordingly with move_box.
The box.
image_box (ip, u, w, h, alpha, pixel) (
Typeset/Boxes/Basic/basic_boxes.cpp

) creates an image_box_rep, which holds a scalable obtained from load_scalable_image (u, w, h, "", pixel) and the current opacity. Its extents are those of the scalable image, and its display method calls ren->draw_scalable. Nothing is loaded or rasterized at typesetting time: only the size of the file is needed. The animation boxes (

Typeset/Boxes/Animate/animate_boxes.cpp

) use image_box too.

Other ways of including images in a document, which are not covered here, are the images inside pictures of the graphics editor (see the graphics editor), and images used as backgrounds (next section).

2.Background patterns

The background of a box, a page or a table cell may be a pattern, a tree (pattern url width height [effect]) stored in a pattern brush. Patterns are drawn by renderer_rep::clear_pattern (

Graphics/Renderer/renderer.cpp

):

  1. the original size of the image is computed with image_size, at 600 dots per inch;

  2. the size of one tile is the original size when the width or height is empty, an integer number of logical units, a percentage of the area to be filled, or, with the @ suffix, a percentage of the other dimension multiplied or divided by the aspect ratio of the image; it is rounded up to whole pixels;

  3. a scalable image of the tile size, with the effect of the pattern, is created, and every tile which meets both the area and the clipping rectangle is drawn with draw_scalable.

The Scheme side of patterns (the pattern and gradient selectors of the format menus) is in

generic/pattern-selector.scm

and

generic/pattern-tools.scm

. The PDF renderer does not use clear_pattern: it turns patterns into PDF tiling patterns (see images in PDF output).

3.Inserting images

The Insert\(\rightarrow\)Image menu (

generic/insert-menu.scm

) offers Link image and Insert image, which call make-link-image and make-inline-image (

generic/generic-edit.scm

) through the file chooser. Both call the editor routine edit_text_rep::make_image (file, link, w, h, x, y) (

Edit/Modify/edit_text.cpp

), with the name made relative to the current buffer:

Linked images

The image tag contains the file name. Local absolute names are rerooted to file:, and the name is converted to Cork encoding.

Embedded images

The file is read into memory and the tag contains (tuple (raw-data bytes) name), where name is the last component of the file name. A missing file or a file without suffix is refused with a message in the footer.

The width and height proposed by the file chooser come from qt_pretty_image_size. When files are dropped on a document, the image names of the dropped content are made relative to the document if possible (relativize in

Edit/Interface/edit_mouse.cpp

).

4.Exporting selections as images

The editor can typeset a fragment and save it as an image: edit_main_rep::print_snippet produces EPS or PDF through a printer renderer, or a bitmap through a picture renderer (see renderers at work, section “printing and export”). Its Scheme wrapper is print-snippet, which returns the extents and the baseline of the typeset fragment.

$TEXMACS_PATH/progs/convert/images/tmimage.scm uses it for two commands:

export-selection-as-graphics

Export the selection to a file whose format is given by its suffix, or by the preference texmacs->image:format when the name has none (SVG if a PDF to SVG converter exists, PDF otherwise). The selection is wrapped in a minimal table or a document-at so that the image has the width of the material and, for single lines, a known baseline; mathematics keeps its inline or display style. For SVG, the TeXmacs source of the selection is embedded in the image so that it can be edited again from Inkscape (refactor-svg); for PDF, it is attached as a TeXmacs document (embbed-tm-selection-in-pdf, see PDF attachments).

clipboard-copy-image

Export the selection to a temporary file in the preferred format and put it on the clipboard (Qt only).

5.Pitfalls

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".