GNU TeXmacsUser manualReferenceAboutEnglish
From the menu to the file

1.Entry points

There are two ways from Scheme to PDF:

2.Typesetting for print

print_doc (

edit_main.cpp:241

) typesets the document anew, independently of the screen:

  1. With Ghostscript support (USE_GS), it decides whether the native renderers are used: use_pdf () is the preference native pdf when TeXmacs was built with PDF_RENDERER, and false otherwise. If a PDF file is wanted and use_pdf () is false, the document is printed to a temporary PostScript file which gs_to_pdf converts at the end; the same happens in the other direction for PostScript.

  2. It sets the printing environment: dpi to the printing resolution (the preference printer dpi, 1200 by default), headers and footers on, no screen margins and no page border, and page-medium to paper (except for conform printing, used by export_ps (export-postscript), which keeps the paging of the screen and gives each page the size of its box).

  3. typeset_as_document produces the boxes of all the pages; the page size and orientation are read back from the environment (page_real_width, page_real_height, page_landscape).

  4. printer (name, dpi, pages, …) (

    printer.cpp:1085

    ) returns the PDF renderer when use_pdf () holds and the file has the suffix pdf (or PostScript is not produced natively), and the PostScript renderer otherwise.

  5. The title, author and subject are passed with set_metadata. Each comes from the global-title, … environment variable, from the doc-data of the document (search_metadata), or, failing that, from the file name for the title and, outside Windows and when the commands are available, from finger ‘whoami‘ for the author (

    edit_main.cpp:180

    ).

  6. Each page box is redrawn on the renderer, after clearing the page with the background color when it is not white, and next_page separates the pages. Deleting the renderer finishes the file.

  7. If the preference texmacs->pdf:check is on, gs_check runs Ghostscript on the result and reports errors.

Since the document is typeset again, the positions on paper can differ from those on the screen, and the links of the document are found in two ways at drawing time (see links).

3.The renderer

pdf_hummus_renderer_rep (

pdf_hummus_renderer.cpp

) derives from renderer_rep. Boxes call href, anchor and toc_entry on every renderer, and display_links on every renderer which is not a screen; only the printers implement them (the base class ignores them). is_printer is true, which only affects some decorations.

Construction.
The constructor (
pdf_hummus_renderer.cpp:287

) computes the page size in points from the paper size in centimeters, chooses the PDF version, and starts the file with PDFWriter::StartPDF with compressed streams. The version is 1.4 unless the preference texmacs->pdf:version asks for 1.5, 1.6 or 1.7; this preference is only read in builds with Ghostscript support, since pdf_version lives in

gs_utilities.cpp:195

. It registers a DestinationsWriter, a PDFHummus extender which adds the /Dests and /Outlines entries to the catalog when it is written, and an initial graphics state.

Pages.
begin_page creates a PDFPage with the media box and a content context, saves the graphics state, scales from the printing resolution to 72 points per inch (cm), and moves the origin to the top left corner, so that the renderer can use the coordinates of TeXmacs (in units of pixel at the printing resolution, y going down). end_page closes the text object and the clippings, writes the page with WritePageAndRelease and records its object number in page_id, which destinations and outlines refer to.
Graphics state.
Colors, line widths, clippings and transformations are written as PDF operators when they change (fg, bg, lw cache the current values). Transparency is implemented with one ExtGState per alpha value (alpha_id, select_alpha), which is why the minimum version is 1.4. Images, patterns and pictures are described in images in PDF output.
Destruction.
The destructor (
pdf_hummus_renderer.cpp:367

) ends the last page and writes, in this order, the images, the patterns, the bitmap glyphs, the destinations, the outlines, the Type 3 fonts, the metadata, the transparency states and the link annotations; then EndPDF writes the fonts used through PDFHummus, the catalog, the cross reference table and the trailer, and the temporary image files are removed.

4.The PDFHummus library

PDFHummus (PDF-Writer by Gal Kahana) is vendored in

Plugins/Pdf/PDFWriter

, with the AES implementation it needs for encrypted files in

LibAesgm

. TeXmacs uses it to write objects, content streams, fonts and embedded images, and to read PDF files (sizes of images, merging of included PDF pages, attachments). It relies on FreeType for the fonts, which is why the renderer is only built with FreeType 2.4.8 or later.

The renderer is enabled by default in the autotools build (

misc/m4/hummus.m4

; off with --disable-pdf-renderer), provided that the GUI is Qt and that zlib, libpng and FreeType 2.4.8 or later are found. The CMake build always enables it. Both define PDFHUMMUS_NO_TIFF and PDFHUMMUS_NO_DCT (no TIFF images, no JPEG decoding; JPEG files are embedded as they are).

A few local changes are marked in the sources: UsedFontsRepository::GetFontForFile returns NULL for a corrupted font file instead of stopping the output, so that TeXmacs can fall back to a Type 3 font; and two fixes of 2021 in CharStringType2Flattener::Type2Cntrmask and in CharStringType2Interpreter (which no longer checks mCheckedWidth). One change is not marked: the font descriptor flags of HelveticaNeue.0.ttf on macOS (FontDescriptorWriter::CalculateFlags, savannah bug #66761); the same commit listed this font in

pdf-font-issues.scm

, so it is written as a Type 3 font and the flags are not used. When the library is updated, these changes have to be carried over.

5.Preferences

The section TeXmacs -> Pdf/Postscript of the conversion preferences (pdf-preferences-widget in

preferences-widgets.scm

, and the corresponding submenu of

preferences-menu.scm

, shown when both native PDF and Ghostscript are supported) sets:

native pdf, native postscript

Use the native renderers (default on); otherwise convert with Ghostscript.

texmacs->pdf:version

The PDF version: default (1.4), 1.5, 1.6 or 1.7.

texmacs->pdf:expand slides

Each screen of a presentation becomes a page in any case; with this preference, the overlays and alternatives of each slide are also expanded into separate pages.

texmacs->pdf:distill inclusion

Run included PDF images through Ghostscript first.

texmacs->pdf:check

Check the exported file with Ghostscript.

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".