![]() |
Projects | ![]() |
A project consists of a master file and a number of chapter files. The master includes the chapters with include (see the next page); each chapter which should be editable on its own is attached to the master. The buffer level routines (project_attach, project_attached, project_get, implicit projects) are described in buffers; this page explains what attaching a project actually changes.
A buffer is a master (an implicit project) if its file name ends in .tp, or if the initial variable project-flag is true. The latter is toggled by Tools\(\rightarrow\)Project\(\rightarrow\)Use as master (buffer-toggle-master in
generic/document-part.scm
, which calls init-env).
Tools\(\rightarrow\)Project\(\rightarrow\)Attach master asks for a file and calls project-attach with its name relative to the current buffer (project-attach*). The C++ routine project_attach (
Texmacs/Data/new_project.cpp
) stores the name in the project field of the buffer data, re-initializes the editors (init_update, notify_change (THE_DECORATIONS)), marks the buffer as modified and loads the master buffer into buf->prj with concrete_buffer_insist. Tools\(\rightarrow\)Project\(\rightarrow\)Detach master (project-detach) calls the same routine with an empty name. The name is saved in the project part of the document.
When a chapter is loaded later, set_buffer_tree (
new_buffer.cpp
) sees the project attribute and loads the master in the background, without any view. The master therefore must exist on disk; unless it is already open, its references are those of its last save.
The typesetting environment of an editor holds two tables of each kind: a local one and a global one. They are bound in the constructor of edit_typeset_rep (
Edit/Editor/edit_typeset.cpp
):
local: buf->data->ref; global: the references of the master (buf->prj->data->ref) if there is a project, otherwise the private table grefs.
local: buf->data->aux; global: the auxiliary data of the master, or the local table again.
likewise, with att.
The two kinds of tables are used asymmetrically:
Writes always go to the local table: labels (
Typeset/Env/env_exec.cpp
), page numbers of labels (
Typeset/Bridge/typesetter.cpp
) and write entries (
Typeset/Concat/concat_active.cpp
).
Reads try the local table first, then the global one: exec_get_binding and exec_has_binding (the primitives behind references) for labels, and the lookup of attachments (
env_exec.cpp
). The global auxiliary table is only read by init_update, for the parts entry described below; automatic content such as the table of contents of a chapter is always taken from the chapter itself.
When the master is typeset, its chapters are typeset as part of it through include, so the master's own table collects the labels of all chapters; saving the master stores them in its references section. When a chapter is typeset on its own, its local table only contains its own labels, and a reference to a label in another chapter is found in the master's table. Consequently, cross references between chapters are only correct after the master has been typeset and saved; updating a chapter does not update the master.
A buffer which has no project but whose initial variable part-flag is true gets a copy of its own references as global table (grefs, set by init_update). This is the case of the part views of the last page, whose references are those of the master.
The include macro of the standard style calls part-info with the name of the included file, which does two things while the master is typeset (
std-automatic.ts
):
it sets the label part:name, whose page number is the page on which the inclusion starts;
it writes an entry (tuple name chapter-nr n section-nr m subsection-nr k) to the auxiliary channel parts, recording the counters before the inclusion.
edit_typeset_rep::init_update uses this information when a chapter is (re)initialized: it computes the name of the chapter relative to the master (delta (prj->buf->name, buf->name)), looks for an entry with that name in the master's parts and copies the recorded counters, as well as the page of part:name (into page-first), to the initial environment of the editor and of the buffer data. As a result, a chapter edited on its own is numbered as in the book.
Conversely, when a chapter is included, extract_document (
Data/Convert/Texmacs/fromtm.cpp
) keeps its initial environment as a with around the body, but drops the page layout variables and, if the included file belongs to a project, its page-first and chapter and section counters, so that the copies stored in the chapter do not override the numbering of the master.
Shown when a project is attached (
texmacs/menus/main-menu.scm
). project-menu (
generic/document-menu.scm
) offers the master and the list of files included by the master (project-file-list, computed by include-list from the master's tree).
project-manage-menu: use as master, expand inclusions, attach and detach the master.
Only shown for a chapter; clear_local_info empties the local reference and auxiliary tables of the buffer, so that only the master's information is used.
The other update commands (update-document) act on the current buffer only. To refresh the cross references of a book, update and save the master, then reopen or re-initialize the chapters.
The master's tables are bound once. The references to the master's tables are taken when the editor is created; attaching or detaching a project in an open view changes buf->prj but not the tables used by the typesetter until the view is recreated (see links pitfalls). If the master buffer were closed while a chapter is open, the chapter's environment would refer to freed tables.
Names must match literally. init_update compares the chapter name computed with delta with the name written by part-info, which is the argument of the include tag as written in the master. An inclusion written as ./ch1.tm, or through another relative path to the same file, is not matched, and the chapter then keeps its own numbering.
The project file list is shallow. include-list only looks at include tags directly in the master's top level document; inclusions inside a with or another tag are not listed in Document\(\rightarrow\)Project. (The similar tm-get-includes of
document-part.scm
does descend into with.)
Chapters write to the buffer data during initialization. init_update stores the counters in buf->data->init, so they are saved with the chapter, even if they were only meant to be inherited from the master.