![]() |
Multi-file documents: projects, inclusions and document parts | ![]() |
Long documents such as books are rarely kept in a single file. TeXmacs offers three mechanisms for working with documents which consist of several pieces, and they are often used together:
The include tag inserts the body of another file into a document. The master file of a book typically consists of a preamble and one include per chapter.
A chapter file can be attached to a master file. When the chapter is edited on its own, it then uses the references, auxiliary data, chapter and page numbers of the master, so that cross references between chapters work.
A single document can be split into parts (usually at its principal sections) of which only some are shown, and a document with inclusions can be opened as a part view tmfs://part/… in which the included files are expanded and can be edited in place.
This chapter describes how these mechanisms are implemented. It assumes familiarity with the buffer data (new_data_rep) and the prj field of buffers, described in buffers, with the reference and auxiliary tables of links, loci and references, and with the generation of automatic content in structured editing, search and automatic content.
The three mechanisms live at different levels:
Inclusions are a typesetting feature. In the standard styles include is a macro (
std-automatic.ts
) which records some information about the included file with the macro part-info and expands to the primitive include*. The primitive is evaluated like a macro: the typesetter loads the included file through a global cache (load_inclusion) and typesets its body as if it were part of the master. The included material is not part of the edit tree of the master.
Projects are a buffer feature. A buffer whose data declare a project has its prj field set to the buffer of the master, which is loaded in the background. The typesetting environment of the chapter reads labels and auxiliary data first from the chapter and then from the master, and init_update copies chapter and page numbers recorded by the master into the initial environment of the chapter.
Document parts are a Scheme feature. In-buffer parts are ordinary markup (show-part, hide-part, show-preamble, hide-preamble) manipulated by
generic/document-part.scm
. Part views are documents of the TeXmacs file system, produced and saved by the handlers of
part/part-tmfs.scm
; the expanded inclusions are wrapped in shared tags, whose modifications are forwarded to the corresponding buffers by
part/part-shared.scm
.
The following picture summarizes the data flow for a book book.tm with a chapter ch1.tm:
book.tm (master, project-flag = true)
<include|ch1.tm>
part-info: label part:ch1.tm, write parts (chapter-nr, …)
include*: load_inclusion (ch1.tm), typeset as part of book.tm
ch1.tm (project = "book.tm")
buffer->prj = buffer of book.tm (loaded in the background)
labels = own table first, then the table of book.tm
init_update : chapter-nr, page-first, … from book.tm
tmfs://part/…/book.tm (part view)
includes expanded into <shared|uid|ch1.tm|body>
edits of body forwarded to the buffer ch1.tm when it is open |
Paths are relative to
src/src/
for C++ files and to
src/TeXmacs/
for the others.
Texmacs/Data/new_project.cpp
Attaching a project to the current buffer, implicit projects, project_get.
Texmacs/Data/new_buffer.cpp
Loading the project buffer in set_buffer_tree; the inclusion cache (load_inclusion, reset_inclusions, reset_inclusion).
Edit/Editor/edit_typeset.cpp
Binding of the reference and auxiliary tables of the master (edit_typeset_rep constructor), init_update, clear_local_info.
Typeset/Env/env_exec.cpp,
Typeset/Bridge/bridge_rewrite.cpp
Evaluation and typesetting of include*.
Typeset/Concat/concat_macro.cpp
Typesetting of the include primitive (typeset_include).
Data/Convert/Texmacs/fromtm.cpp
extract_document, which turns an included file into a body.
Texmacs/Server/tm_server.cpp
inclusions_gc.
packages/standard/std-automatic.ts
The macros include, part-info and shared.
packages/standard/std-fold.ts
The macros show-part, hide-part, show-preamble and hide-preamble.
progs/generic/document-part.scm
Preamble mode, in-buffer document parts, the list of inclusions, expanding inclusions, the Document\(\rightarrow\)Part and project management menus.
progs/generic/document-menu.scm
The Document\(\rightarrow\)Project menu and the update commands.
progs/part/part-tmfs.scm
The part handlers of the TeXmacs file system.
progs/part/part-shared.scm
Synchronization of shared and mirror tags with each other and with whole buffers.
progs/part/part-menu.scm
The menus which open the included files as part views.