![]() |
Collaboration, the TeXmacs server and versioning | ![]() |
TeXmacs contains a small client/server system which allows several users to store documents on a shared server, to exchange messages, to share resources and to edit “live” documents together. The same TeXmacs binary plays both roles: an instance started in server mode listens on a TCP port and answers requests, while ordinary instances connect to one or more servers as clients. Independently of the server, TeXmacs also provides tools for comparing two versions of a document and a thin integration with the external version control systems Subversion and Git.
This chapter describes how these facilities are implemented. It is aimed at developers who want to understand, debug or extend them. For the user point of view, see the user manual chapters Setting up a TeXmacs server and Remote tools and collaborative editing.
A TeXmacs server is a normal TeXmacs process (usually started with the -server command line option, possibly together with -headless) in which the Scheme modules under
progs/server/
have been loaded. A client is any TeXmacs process in which the modules under
progs/client/
are loaded; they are loaded lazily, the first time the user opens a remote menu or a remote tmfs URL (see the lazy-define, lazy-menu and lazy-tmfs-handler declarations in
init-texmacs.scm
). One process may simultaneously be a server and a client of other servers (or of itself).
The work is split between C++ and Scheme as follows:
C++ (directory
src/src/System/Link/
, src/src/Plugins/Qt/QTMSockets.* and
src/src/Plugins/Gnutls/
) implements the sockets, the optional TLS layer, the legacy encryption layer and the framing of messages into packets. Only raw strings cross this layer. The Qt and Qtwk builds (QTTEXMACS) use QTMSockets (on QSocketNotifier); the other ports (Vue, SDL, X11, Cocoa) use the GUI independent
tm_sockets.cpp
, so that the sockets exist in every build.
Scheme implements everything else: serialization of messages as S-expressions, dispatching of requests to services, continuations for asynchronous answers, user accounts, access rights, the remote file system, synchronization, chat rooms, notifications and live documents.
The server keeps its persistent state in a TeXmacs database ($TEXMACS_HOME_PATH/server/global.tmdb, implemented in
src/src/Plugins/Database/
and wrapped in
progs/database/
) together with a few Scheme files and a directory tree which stores the contents of files. Clients keep their own state (accounts, synchronization records) in per-user databases.
Live editing relies on the C++ patch algebra of
src/src/Data/History/
(modifications, patches, inversion and commutation), which is also the basis of the undo/redo system.
System/Link/client_server.hpp
,
texmacs_server.cpp
,
texmacs_client.cpp
,
tm_link.cpp
(packet framing and legacy encryption),
tm_contact.hpp
, socket_contact.*, Plugins/Qt/QTMSockets.* (non blocking sockets driven by QSocketNotifier), Plugins/Gnutls/gnutls.* (TLS contacts, certificates, PBKDF2). The Scheme glue is declared in
Scheme/Glue/build-glue-basic.scm
.
server/server-base.scm
(dispatcher, accounts, login),
server-authentication.scm
(preferences, logs, password encodings),
server-tmfs.scm
(remote file system and server side versions),
server-db.scm
(remote database access),
server-sync.scm
and
server-db-sync.scm
(synchronization),
server-live.scm
,
server-chat.scm
,
server-notifications.scm
,
server-cache.scm
(tree cache),
server-backup.scm
,
server-widgets.scm
and
server-menu.scm
(user interface), plus the regression tests server-*-test.scm and
server-fixtures.scm
. The file
server/todo.tm
contains the original design notes.
client/client-base.scm
(dispatcher, connections, accounts, login),
client-authentication.scm
,
client-tmfs.scm
(remote file browser and tmfs handlers),
client-db.scm
,
client-sync.scm
,
client-db-sync.scm
,
client-live.scm
,
client-chat.scm
,
client-notifications.scm
,
client-remote-config.scm
(remote administration of server preferences),
client-widgets.scm
,
client-menu.scm
and
client-markup.scm
.
utils/relate/live-document.scm
(states and histories),
live-connection.scm
(remote peers and conversion between patches and lists of modifications),
live-view.scm
(views of a live document inside ordinary buffers), and the markup in
packages/utilities/live.ts
and
packages/miscellaneous/live-document.ts
.
version/version-tmfs.scm
(dispatch to back-ends, tmfs handlers for histories and revisions),
version-svn.scm
,
version-git.scm
,
version-compare.scm
(structural diff),
version-edit.scm
and
version-drd.scm
(editing of differences),
version-menu.scm
and
version-kbd.scm
. The markup for differences is defined in
packages/standard/std-fold.ts
.
Kernel/Types/modification.hpp
, Data/History/patch.*,
commute.cpp
, archiver.*, and
kernel/library/patch.scm
on the Scheme side.
The code base has been developed over a long period (initial design in 2007 and 2013, TLS and authentication in 2022, accounts, notifications, tree cache and backups in 2025–2026), and its parts have different levels of maturity:
Stable and used: the connection layer (legacy and TLS), accounts and password login, the remote file system with server side versions, sharing through chat messages and permissions, chat rooms and mail boxes, the structural comparison of documents and the Subversion/Git integration.
Recent: push/pull notifications, account deletion plans, the tree cache (protocol version 1) and periodic backups. These parts come with regression tests (regtest-server-notifications, regtest-server-backup, regtest-server-cache, run from
progs/check/check-master.scm
).
Experimental: live documents (the code contains several FIXME notes, prints debugging output on conflicts and only persists live documents when a client disconnects), file and database synchronization (only the database kind "bib" is currently synchronized), and remote evaluation of commands.
The individual sections indicate more precisely what is implemented.