GNU TeXmacsUser manualReferenceAboutEnglish
Paths, directories and settings at boot time

The order of the boot steps is described in the main program and crash handling. This page describes what the steps which concern the system layer do: finding the installation, setting the environment variables which all search paths are built from, creating the user directories, managing temporary directories, and keeping the settings file. The code is in

System/Boot/init_texmacs.cpp

,

init_upgrade.cpp

,

Texmacs/Texmacs/texmacs.cpp

and the entry points of the platform layers.

1.Finding the installation

$TEXMACS_PATH is the directory with the Scheme code, styles, fonts and documentation of the installation (in the source tree,

src/TeXmacs

). It is determined in two places:

  1. The main functions of

    Plugins/Unix

    and

    Plugins/Windows64

    call setup_texmacs_path. If TEXMACS_PATH is set and valid, it is kept. Otherwise the function tries directories relative to the executable (texmacs_get_application_directory): on macOS ../Resources/share/TeXmacs inside a bundle, then TeXmacs next to the executable, the parent directory, and (on Unix) usr/share/TeXmacs, usr/local/share/TeXmacs, ../usr/share/TeXmacs, /usr/share/TeXmacs and /usr/local/share/TeXmacs. The first valid one becomes TEXMACS_PATH. A directory is valid for test_texmacs_path if it contains doc, fonts, progs, styles and a file SVNREV whose contents equal ALTERNATIVE_VERSION (the version series, such as 2.1., read from src/TeXmacs/SVNREV at build time). This prevents an executable from silently running with the files of another TeXmacs version.

  2. TeXmacs_init_paths in

    texmacs.cpp

    then handles bundles: on macOS it sets TEXMACS_PATH to ../Resources/share/TeXmacs if it is still unset, adds the bundle's Plugins, Frameworks and Resources/lib directories to the Qt plug-in path and the dynamic library paths, and appends the PATH of a login shell (obtained by running $SHELL -l -c 'echo $PATH') and the bundle's bin directory to PATH; on Windows it uses the parent of the executable's directory and sets PWD if it is missing or comes from a Unix environment (Wine); on Haiku it uses ../data/TeXmacs. If TEXMACS_PATH still does not exist, the program exits.

The shell script misc/scripts/texmacs used by Unix installations sets TEXMACS_PATH and TEXMACS_BIN_PATH before starting texmacs.bin, and puts $TEXMACS_BIN_PATH/bin and $TEXMACS_BIN_PATH/lib in front of the search paths.

$TEXMACS_HOME_PATH is the user's directory: it defaults to ~/.TeXmacs, to %APPDATA%\TeXmacs on Windows and to ~/config/settings/TeXmacs on Haiku, and is set by immediate_options if it is not set in the environment (init_main_paths repeats the test later). The server certificates directory TEXMACS_SERVER_CERT_DIR defaults to $TEXMACS_HOME_PATH/server.

2.Environment variables and search paths

Most search paths of TeXmacs are environment variables, so that they can be overridden from outside and are inherited by plug-ins. init_guile and init_env_vars set them, keeping the value given in the environment where noted. Each path includes the corresponding directory of every installed plug-in, as computed by plugin_path (sub), which searches $TEXMACS_HOME_PATH, /etc/TeXmacs, $TEXMACS_PATH and /usr/share/TeXmacs for plugins/*/sub.

GUILE_LOAD_PATH

$TEXMACS_PATH/progs, the previous value, $TEXMACS_HOME_PATH/progs and the progs directories of plug-ins.

init-texmacs.scm

must be found in the first two, or the boot fails.

PATH, LD_LIBRARY_PATH

The previous value followed by the plug-ins' bin and lib directories; on Windows and macOS also $TEXMACS_PATH/bin; the manual path preference is put in front.

TEXMACS_STYLE_ROOT, TEXMACS_PACKAGE_ROOT, TEXMACS_STYLE_PATH

The roots for style files and packages (user directory, installation, plug-ins), and all their subdirectories. Kept if set.

TEXMACS_TEXT_ROOT, TEXMACS_TEXT_PATH

The same for the texts directories. Kept if set.

TEXMACS_FILE_PATH

The text and style paths. Kept if set.

TEXMACS_DOC_PATH

The previous value followed by $TEXMACS_HOME_PATH/doc, $TEXMACS_PATH/doc and the plug-ins' doc directories.

TEXMACS_SECURE_PATH

The previous value followed by $TEXMACS_PATH and $TEXMACS_HOME_PATH; see is_secure in URLs.

TEXMACS_PATTERN_PATH, TEXMACS_PIXMAP_PATH, TEXMACS_DIC_PATH, TEXMACS_THEME_PATH

Background patterns, icons, dictionaries and themes. Kept if set.

TEXMACS_SOURCE_PATH

The source directory given at build time (empty on Windows).

Because URLs expand environment variables when they are constructed (URLs), code which builds search paths must run after init_env_vars. init_misc finally checks whether the shell command which works (use_which), which resolve_in_path relies on.

3.User directories

init_user_dirs creates the directory tree of $TEXMACS_HOME_PATH if needed: bin, doc, fonts (with subdirectories for the various font formats and for fonts that failed to load), langs, misc, packages, plugins, progs, server, styles, system (with bib, cache, certificates, database, make and tmp), texts (with backup and scratch) and users. The directories server, system and users are made accessible to the user only (mode 0700). The other files in system include settings.scm (below), preferences.scm (see preferences) and the boot lock.

4.Temporary directories

Each process uses its own temporary directory, $TEXMACS_HOME_PATH/system/tmp/pid, returned by url_temp_dir. At the end of init_user_dirs, clean_temp_dirs removes the directories of processes which are no longer running: for every numeric entry of system/tmp, it runs ps -p pid and deletes the directory with rm -rf unless the output mentions both texmacs and the process number (process_running). On 32-bit Windows the directories are named after the start time instead, and are removed after seven days. Other entries of system/tmp, such as tree_cache (the cache of the remote file system) or the previews of the print dialog, are left alone.

5.Settings and upgrades

$TEXMACS_HOME_PATH/system/settings.scm holds the tuple texmacs_settings of pairs (variable, value), read and written with get_setting and set_setting. Its only systematic entry is VERSION. init_plugins (called from TeXmacs_main) reads it:

The boot lock, system/boot_lock, is created by acquire_boot_lock during init_texmacs and removed by release_boot_lock just before the event loop starts. If it is found at startup, the previous run crashed while booting, and the settings, the setup file, the caches and the font error files are removed.

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