GNU TeXmacsUser manualReferenceAboutEnglish
Document parts and part views

The word part is used for two different features. In-buffer parts let the user show only some of the principal sections of a long document, or only its preamble. Part views are documents of the TeXmacs file system, tmfs://part/…, which present a file of a multi-file document together with the context of its master, and in which the inclusions are expanded and editable.

1.In-buffer parts and the preamble mode

In-buffer parts are implemented entirely in Scheme, in

generic/document-part.scm

, as rewritings of the top level document of the buffer. The comment at the head of the file gives the representations of the four part modes:

:preamble

(document (show-preamble preamble) (ignore body)): only the preamble (the macro definitions of the document) is visible and editable.

:one, :several

(document [(hide-preamble preamble)] parts…), where each part is (show-part id body alt-body) or (hide-part id body alt-body).

:all

(document [(hide-preamble preamble)] body…): the ordinary form.

The macros are defined in

packages/standard/std-fold.ts

. show-part typesets its body inside set-part (which extends the variable current-part and resets auto-nr,

std-automatic.ts

); hide-part does the same inside hidden, choosing the body or the alt-body according to sectional-short-style. Hidden parts are still evaluated, so that counters and labels remain correct, and hide-part is declared with hidden child 1 in its DRD properties. hide-preamble shows nothing but still executes the definitions, through filter-style.

The parts are created by buffer-make-parts, which calls principal-sections-to-document-parts (

text/text-structure.scm

): the paragraphs are split at each principal section (chapters in a book, sections in an article), the pieces are numbered "1", "2", … as identifiers, and the alt-body is the section heading alone. Parts are referred to in the menus by the title of their first section (document-part-name, buffer-parts-list). buffer-flatten-parts undoes the splitting.

The main entry points are buffer-set-part-mode (with a check mark for the current mode), buffer-show-part (mode :one), buffer-toggle-part (mode :several), buffer-go-to-part, toggle-preamble-mode and buffer-make-preamble. They make up the Document\(\rightarrow\)Part menu (document-part-menu). When the cursor ends up inside a hidden part, for instance after a search, cursor-show-hidden (

utils/edit/variants.scm

) calls the tree-show-hidden overload of

document-part.scm

, which shows the part.

2.Part views

2.1.Names

A part view is named

tmfs://part/master
tmfs://part/master/file

where master is the URL of the master (as a TeXmacs file system string) and file is either a name relative to the master, prefixed with here/, or an absolute one. part-url, part-master, part-file and part-open-name (

part/part-tmfs.scm

) build and decompose such names; the split is made at the first occurrence of .tm/, so the second form only works for masters with the suffix .tm (and in directories whose names do not contain .tm/). In a master with inclusions, Document\(\rightarrow\)Part lists the included files (document-master-menu,

part/part-menu.scm

), and choosing one opens (part-url master file).

The handlers registered for the part protocol are documented in general in the TeXmacs file system. The master handler returns the real file, so that links and relative names in the view are resolved as in the file; the title is master - file.

2.2.Loading

The load handler reads the file and the master and builds a document with part-expand:

2.3.Saving

The save handler performs the inverse transformation (part-compress): it removes the outer shared wrapper, turns each remaining shared back into an include with a name relative to the file, stores only the differences between the edited initial environment and the inherited one, and takes the style, references and auxiliary sections from the file as it is on disk. The result is written to the real file, which is then marked as saved (or modified, if writing failed).

2.4.Synchronization of shared material

The shared macro (

std-automatic.ts

) wraps its body in a locus with the identifier name and an observer which calls the Scheme function mirror-notify (

part/part-shared.scm

) on each modification. The same machinery serves the mirror tag of

packages/utilities/relate.ts

(live copies of a piece of document, made with make-mirror) and several comment tags. The general link and observer mechanism is described in the link kernel; here is what happens on top of it:

  1. When the body of a shared tag is modified, mirror-notify calls buffer-initialize-shared. If a buffer with the included file's name is open, it attaches a notifier to that buffer (buffer-attach-notifier, see buffers) and marks it for an initial copy.

  2. The modification is queued for that buffer (buffer-notify-shared) and, at the next idle moment, buffer-treat-pending applies the queued modifications to the buffer body with modification-apply!. If one of them does not apply, the buffer body is replaced by a copy of the shared tree (buffer-restore).

  3. Conversely, modifications of the open file buffer reach buffer-notify through its notifier and are queued, with mirror-list-notify, for the other trees carrying the same identifier, that is, for the shared tags in the open part views.

  4. Between copies of a mirror or shared body, the same queue is used (mirror-treat-pending). Copies which fall out of step are put on a black list, separated by giving them new unique identifiers if needed (mirror-separate) and resynchronized by copying (mirror-synchronize). All these changes are made under a dedicated author (mirror-author), with mirror-idle? set to false so that they are not echoed back.

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