![]() |
Writing and validating developer documentation | ![]() |
The general conventions for the documentation (directories, file names, meta information, licenses) are given in contributing to the TeXmacs documentation. For the developer documentation in
doc/devel/source/
, the following conventions have proved useful:
One chapter per subsystem. The chapter consists of an index page topic.en.tm with an Introduction, an Overview, a list of Source files and a traverse to a small number of subpages topic-subtopic.en.tm. A page on pitfalls and known bugs, with file and line references, is often worth adding.
Each chapter is reachable from one of the index pages of about the source code by a branch; pages which are only reached by hlink are not included in compiled books, nor scanned for explain blocks.
Source files are referred to with source-link (see below), which shows the name as written and opens the file when it is clicked. In the shown text, paths of C++ files are given relative to
src/src/
and paths of Scheme files relative to progs/. Links to other documentation are relative hlinks, so that they work in the help browser, in books and on the web site.
Prefer linking to the existing page on a subject over repeating it; when describing behaviour, state what the code does, not what it was meant to do, and mark claims that were not checked.
Never put markup which writes an index entry (menu, tmstyle, tmpackage, tmdtd, name*, indexed, …) in a title or sectioning command. The title is copied into the table of contents, so every regeneration of the table of contents adds automatic labels, all the following auto-n labels are renumbered, and the page numbers of the table of contents and the index of a compiled book never converge.
Labels of description items are unbreakable boxes. When labels are long, for instance lists of several file names, use description-paragraphs instead of description.
Give every page a base name which is unique in the whole documentation: compiled books label each page sec-name after its base name.
Use the markup of the tmdoc style: cpp, scm, verbatim, markup, tmstyle, tmpackage, explain with explain-synopsis, cpp-code and scm-code for blocks.
The pages of the developer documentation only make sense together with the code, so every reference to a source file is a link:
<source-link|Typeset/Env/env_exec.cpp|src/Typeset/Env/env_exec.cpp> <source-link|ai.cpp:815|src/Data/Convert/AI/ai.cpp:815> |
The first argument is the text which is shown, in the verbatim font; the second one is the path of the file relative to the src directory of the repository (the directory which contains src, TeXmacs and plugins), optionally followed by :line. The path may also name a directory, which is opened with the file manager of the system. A click calls open-source-link of
doc/source-links.scm
, which looks for the file in
the directory of the preference developer:source directory, if it is set;
otherwise $TEXMACS_SOURCE_PATH, the source tree TeXmacs was configured from (empty for the Windows builds);
for paths in
TeXmacs/
, finally the installed $TEXMACS_PATH, so that the Scheme files, styles and packages can be opened from any installation.
The file is then opened with the tool chosen in Developer\(\rightarrow\)Open source links with (preference developer:source editor): TeXmacs itself, at the given line; the default application of the system; a predefined editor (Visual Studio Code, Emacs, Xcode, Sublime Text, Zed); or any command line, in which %f is replaced by the quoted file name and %l by the line (1 when no line is given). The same menu sets the source directory, which is needed for binary installations. The Developer menu appears once Tools\(\rightarrow\)Developer tool is checked.
The links are checked by
tests/docs/source-links.py
, which reports every source-link whose file is no longer in the repository, and every verbatim which names exactly one file (or one directory) of the repository and could be a link; with --convert it turns the latter into links. A name is matched by the end of the paths, so Plugins/Qt/qt_gui.cpp and qt_gui.cpp both work; a name starting with src/ is read from the root of the repository. Names without a / are only considered for source files (.cpp, .scm, .m4, …). Names which match several files or directories are left alone (write more of the path), as are generated files, files of other branches and files of the user's home directory, which stay in verbatim.
.tm files are not UTF-8 files: strings are stored in the Cork encoding of TeXmacs, with escapes for everything else. When documentation is written or edited outside TeXmacs, the file should contain only ASCII characters:
quotes are written \P and \Q, special symbols as \<name\> (for instance \<times\>) and other characters as \<#hex\>;
the characters <, >, | and \ are escaped as \<less\>, \<gtr\>, \| and \\;
leading spaces in code blocks are written \ .
A raw UTF-8 character in a .tm file is read as several Cork characters and shows up as garbage. A quick check is to search the file for bytes above 127, for instance with LC_ALL=C grep -nP '[\x80-\xff]' file.
Before committing new pages, it is useful to check that
every tag used is defined. A tag which is not defined by the style is shown in red in the editor and silently passes through conversions. A simple check is to compare the tags used in the new files with those used in the existing documentation;
every relative link points to an existing file, and
tests/docs/source-links.py
reports no broken source links;
every page can be typeset. This can be done without opening windows, by converting each page to PDF in headless mode:
TEXMACS_PATH=worktree/src/TeXmacs \ TEXMACS_HOME_PATH=private-home QT_QPA_PLATFORM=offscreen \ texmacs.bin -headless -c page.en.tm page.pdf -q |
A private TEXMACS_HOME_PATH keeps the test from changing the user's preferences and caches, and allows several conversions to run in parallel;
the whole hierarchy expands: loading tmfs://help/book/… for the root page (as Help\(\rightarrow\)Full manuals does) should give a document which contains the label sec-name of every new page, and the console should show no bad link or file message.
Deep sectioning in books. Sectioning commands inside a page are taken relative to the level of the page (see expansion). In a deep hierarchy this quickly reaches the unnumbered levels: the subsections of a page four levels below the root become paragraphs, and its paragraphs run-in subparagraphs. Keep the hierarchy shallow, or let the root start with parts (tmdoc-book-parts).
Labels from base names. The label of each page in an expansion is sec-name, built from the base name only. Two pages with the same base name in different directories get the same label, and internal links in books may then point to the wrong page.
External links in books. tmdoc-internalize replaces every hyperlink whose target is not part of the book by its text, so links to other parts of the documentation and to web pages disappear from compiled books.
help-link has no English fallback. The macro (
packages/documentation/standard/tmdoc-markup.ts:118
) always appends the suffix of the current language, whereas tmdoc-file and url-resolve-help fall back to .en.tm. With a user interface in a language for which the target has no translation, the link leads to the Broken link. page. For instance,
main/automated/top-help.en.tm
links to main/editing/man-structured-variants, which exists only in English, French and Chinese.
Full text search ignores English pages in other languages. The search of type doc (
progs/doc/docgrep.scm
, handler of tmfs://grep/) only scans the files of the current output language, unlike tmdoc-search, which falls back to English. With a non English interface, pages which have no translation (which includes nearly all developer documentation) are never found.
Caches that are never refreshed. url-exists-in-help? and the file lists of the full text search are cached for the whole session, so pages added while TeXmacs runs are not seen; the documentation of Scheme symbols is collected once per language and only rebuilt when the cache is deleted.
Deleting the API cache does not delete it. doc-delete-cache asks for confirmation to delete the two cache files and then reports them as deleted, but doc-delete-cache* (progs/doc/apidoc-collect.scm:217-229) only prints I WOULD HAVE deleted the cache at … and resets the preferences, so that new cache files are created next time and the old ones remain on disk.
Language of collected API documentation. doctree-lan (apidoc-collect.scm:64-69) reads the language of a page from its initial environment only. Pages which declare their language in the style tuple (as many Chinese pages do) are recorded as English.
Fixed roots for the API documentation. doc-collect-all only scans the hierarchies below a fixed list of root pages, and only follows branch (not continue or extra-branch); explain blocks elsewhere are not collected.
Building PDF manuals. build-manual only knows three manuals, ignores other names without a message, and does not rebuild a PDF file which already exists.
Online resources. The flags of tmdoc-translations are images on www.texmacs.org, and update-help-online downloads the documentation from an ftp address with wget; both fail without network access (and the ftp server may no longer exist).