![]() |
From the menu to the file | ![]() |
There are two ways from Scheme to PDF:
File\(\rightarrow\)Export\(\rightarrow\)Pdf, File\(\rightarrow\)Export\(\rightarrow\)Postscript and the Export as Pdf entries call wrapped-print-to-file (
tm-print.scm:94
). For a document with screens (slides), it first copies the buffer and expands the slides into pages (dynamic-make-slides); then it calls print-to-file, the glue of edit_main_rep::print_to_file. wrapped-print-to-pdf-embeded-with-tm does the same and attaches the TeXmacs source to the result (see PDF attachments). The Print to file entries of the File menu call print-to-file directly and do not expand slides.
export-buffer with a .pdf or .ps target, which the command line option -c uses, ends in buffer_export (
new_buffer.cpp:551
), which calls print_to_file on the most recent view of the buffer directly. This path does not expand slides.
print_doc (
edit_main.cpp:241
) typesets the document anew, independently of the screen:
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.
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).
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).
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.
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
).
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.
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).
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.
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.
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.
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.
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:
Use the native renderers (default on); otherwise convert with Ghostscript.
The PDF version: default (1.4), 1.5, 1.6 or 1.7.
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.
Run included PDF images through Ghostscript first.
Check the exported file with Ghostscript.