$ show latex3/fontspec
fontspec is a mature LaTeX package that provides an automatic and unified interface for font selection in XeLaTeX and LuaLaTeX. It allows users to load OpenType, AAT, and Graphite fonts by name or filename, with full control over features such as ligatures, small caps, numerals, script/language selection, colour, scaling, and more. The architecture is modular: a core LaTeX3 (expl3) implementation wraps engine-specific code (XeTeX primitives or luaotfload) behind a consistent key-value interface, and provides both user commands (`\setmainfont`, `\fontspec`) and a programmable API (`\fontspec_*` conditionals) for other packages. The codebase is structured as literate `.dtx` files, generating both the package `.sty` files and comprehensive documentation. It includes an extensive test suite with over 100 test files that run on both XeTeX and LuaTeX, a fully automated CI/CD pipeline (testing, documentation, release), and is distributed on CTAN under the LPPL 1.3c license. The package is actively maintained by the LaTeX3 Project team, tracking OpenType specification updates and TeX engine changes, though its dual-engine support and large static data tables (language/script mappings) introduce some maintenance overhead.
The LLM identified 4 files worth highlighting for reuse:
Defines reusable LaTeX3 conditionals for querying font properties (e.g., `\fontspec_if_feature:nTF`, `\fontspec_if_small_caps:TF`, `\fontspec_font_if_exist:nTF`) and font family management functions (`\fontspec_gset_family:Nnn`, `\fontspec_gset_fontface:NNnn`). These functions are self-contained, do not rely on internal package state beyond documented interfaces, and can be used by other LaTeX packages to interact with font features without reimplementing engine-specific logic.
Provides a small Lua module (`fontspec.lua`) that exposes `check_ot_script`, `check_ot_lang`, and `check_ot_feat` functions for querying OpenType feature availability in the LuaTeX engine. This module is independent of the main TeX code and can be reused by any LuaLaTeX package needing low-level font feature introspection, using the `luaotfload` API.
Implements the definition and aliasing of OpenType font features (e.g., Ligatures, Numbers, Letters, VerticalPosition) using LaTeX3 key-value groups. Each feature group has on/off/reset handling, aliasing (`\aliasfontfeature`, `\aliasfontfeatureoption`), and integration with the core font loading pipeline. This pattern is a robust example of building a user-friendly, extensible feature system on top of low-level engine tags, and could be extracted as a generic key-value configuration framework.
Declares all package-level variables (property lists, sequences, integer counters) used throughout fontspec, including `\g_@@_all_opentype_feature_names_prop`, `\g_@@_family_int_prop`, and `\g_@@_fontid_family_prop`. The clean separation of variable declarations from logic is a good pattern for maintainable LaTeX package development, and the property list design for feature/language/script mappings facilitates easy expansion.