GNU TeXmacsUser manualReferenceAboutEnglish
Languages, hyphenation and spell checking

1.Introduction

TeXmacs needs to know about natural languages for four rather different purposes:

This chapter describes the C++ classes and the Scheme code behind these tasks. Two closely related subjects are described elsewhere: the mathematical “languages”, which assign operator types to mathematical symbols, are part of mathematical typesetting, and the programming languages, which are mainly used for syntax highlighting, are the subject of syntax highlighting and programming languages. The line breaking algorithm which consumes the hyphenation points is described in the typesetting algorithm.

All C++ file names are relative to

src/src/

, and all Scheme file names to

src/TeXmacs/progs/

, unless stated otherwise.

2.Overview

The central abstraction is the class language_rep (

System/Language/language.hpp

). A language is a named resource: an object which is created once per name and then found again by name. There are three families of languages, selected by the current mode of the typesetter:

Text languages

text_language (name) returns the language for the value of the language environment variable (english, french, chinese, …). It knows how to split strings into words, spaces and punctuation, and how to hyphenate words using TeX hyphenation patterns.

Mathematical languages

math_language (name) for the math-language variable, which assigns operator types, priorities and spacing to mathematical symbols.

Programming languages

prog_language (name) for the prog-language variable, which mainly drives syntax highlighting.

Spell checking is not part of the language objects: it is a separate layer of free functions in

language.cpp

which forwards to one of three external engines (the Aspell library, a Hunspell or Aspell subprocess, or the macOS spell service) and caches the results. On top of it,

Data/Tree/tree_spell.cpp

finds all misspelled words of a tree, and the Scheme modules in

generic/spell-widgets.scm

and

tools/spell/

implement the spell checking and grammar checking tools of the user interface.

Translation of the user interface is done by dictionaries (

System/Language/dictionary.cpp

), which are also resources, loaded from Scheme files of pairs of strings in

src/TeXmacs/langs/natural/dic/

.

3.Source files

System/Language/language.hpp
,
language.cpp

The classes text_property_rep and language_rep, the predefined text properties, the table of successions of mathematical operators, the wrappers hyphenless_language and ad_hoc_language, the colors used for syntax highlighting, and the spell checking front end with its cache.

System/Language/impl_language.hpp

Declarations shared by the implementations: the predefined tp_…_rep properties and the classes of the verbatim and programming languages.

System/Language/text_language.cpp

The text languages: the default Western implementation, French typography, the languages written with Unicode entities (Cyrillic), and the oriental languages (Chinese, Japanese, Korean, Taiwanese); the list of supported languages and the factory text_language.

System/Language/verb_language.cpp

The verbatim language, used for unknown languages and for source code without a specific language.

System/Language/hyphenate.hpp
,
hyphenate.cpp

Loading of TeX hyphenation pattern files and Liang's hyphenation algorithm.

System/Language/dictionary.hpp
,
dictionary.cpp

Translation dictionaries, the input and output languages, and the translation of strings and trees.

System/Language/locale.hpp
,
locale.cpp

Conversions between TeXmacs language names and system locales, detection of the language of the user, and formatting of dates.

System/Language/math_language.cpp
,
prog_language.cpp
, *_language.cpp, packrat_*.cpp

Mathematical and programming languages and the packrat parser; see the chapters mentioned in the introduction.

Plugins/Ispell/ispell.hpp
,
ispell.cpp
,
ispell_exe.cpp

The two implementations of the low level spell checking interface: the Aspell library (when USE_ASPELL is set) and a pipe to a Hunspell or Aspell process.

Plugins/MacOS/mac_spellservice.mm

The same interface on top of the macOS spell checker, used instead of the above when MACOSX_EXTENSIONS is defined.

Data/Tree/tree_spell.cpp

Spell checking of whole trees, with a cache.

Edit/Replace/edit_spell.cpp

The historical, key driven spell checking mode of the editor.

Data/Convert/AI/lantool.cpp
,
compress.cpp

Merging the answers of LanguageTool into documents, and the compressed HTML representation of documents which is sent to LanguageTool (and to AI models).

generic/spell-widgets.scm

The spell checking tool and toolbar.

tools/spell/

Grammar checking: the interface with LanguageTool (

spell-lantool.scm

), the editing of spell-error markup and personal dictionaries (

spell-edit.scm

), the correction tool and toolbar (

correct-widgets.scm

) and the keyboard bindings (

spell-kbd.scm

).

src/plugins/languagetool/

The languagetool plug-in, which only declares the preferences for the server.

language/natural.scm
,
utils/misc/translation-list.scm

Tools for maintaining the translation dictionaries.

src/TeXmacs/langs/natural/

The data:

hyphen/

(hyphenation patterns),

dic/

(translations) and

miss/

(lists of missing translations).

src/TeXmacs/packages/customize/language/

One style package per language, which sets the language variable and language specific typography.

4.Contents of this chapter

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