changeset 181:dcbc66f851eb

A style file for (Lua)LaTeX that loads the required fonts. Also defined character substitutions for characters that are not in the wished font.
author Franz Glasner <fzglas.hg@dom66.de>
date Tue, 12 May 2026 14:58:14 +0200
parents 63b52570795f
children b0426a788cf5
files docs/_latex/my-doc-fonts.sty docs/conf.py
diffstat 2 files changed, 74 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/_latex/my-doc-fonts.sty	Tue May 12 14:58:14 2026 +0200
@@ -0,0 +1,70 @@
+% -*- coding: utf-8 -*-
+%
+% Some font hacks for my Sphinx PDF documents
+%
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{my-doc-fonts}[%
+  2026/05/12 v0.1 (Franz Glasner) Fonts for Sphinx generated PDFs]
+\RequirePackage{xkeyval}
+\RequirePackage{fontspec}
+\IfFileExists{xcolor.sty}{%
+% Should Sphinx load xcolor with its dvipsnames and svgnames options?
+    \RequirePackage{xcolor}
+}{%
+    \RequirePackage{color}
+}
+
+\newif\if@mdf@WithDejaVuSansMono
+\newif\if@mdf@WithPlexMono
+
+\def\@mdf@reset@font@options{\@mdf@WithDejaVuSansMonofalse\@mdf@WithPlexMonofalse}
+
+\DeclareOptionX{dejavusansmono}[true]{\@mdf@reset@font@options\csname @mdf@WithDejaVuSansMono#1\endcsname}
+\DeclareOptionX{plexmono}[true]{\@mdf@reset@font@options\csname @mdf@WithPlexMono#1\endcsname}
+
+%
+% By default use the safe option dejavusansmono because is contains
+% all characters without any hacks.
+%
+\ExecuteOptionsX{dejavusansmono}
+\ProcessOptionsX*\relax
+
+\if@mdf@WithDejaVuSansMono
+  \RequirePackage[DefaultFeatures={Scale=0.92},mono=false]{plex-otf}
+  \RequirePackage[mono=true,serif=false,sans=false,math=false]{dejavu-otf}  % all symbols are available
+\fi
+%
+%
+\if@mdf@WithPlexMono
+  \RequirePackage{newunicodechar}
+  \RequirePackage[DefaultFeatures={Scale=0.92}]{plex-otf}
+  \newfontfamily\DejaVuSansMono{DejaVu Sans Mono}[%
+    UprightFont = *,
+    BoldFont = * Bold,
+    ItalicFont = * Oblique,
+    BoldItalicFont = * Bold Oblique,
+    Scale=MatchLowercase,
+  ]
+  \newunicodechar{▷}{{\DejaVuSansMono ▷}}% U+25B7
+  \newunicodechar{∶}{{\DejaVuSansMono ∶}}% U+2236
+  \newunicodechar{◆}{{\DejaVuSansMono ◆}}% U+25C6
+  \newunicodechar{▪}{{\DejaVuSansMono ▪}}% U+25AA
+  \newunicodechar{⟵}{{\DejaVuSansMono ⟵}}% U+27F5
+  \newunicodechar{⟶}{{\DejaVuSansMono ⟶}}% U+27F6
+  \newunicodechar{⟷}{{\DejaVuSansMono ⟷}}% U+27F7
+  \newunicodechar{⇒}{{\DejaVuSansMono ⇒}}% U+21D2
+  \newunicodechar{⇔}{{\DejaVuSansMono ⇔}}% U+21D4
+  \newunicodechar{≟}{{\DejaVuSansMono ≟}}% U+225F
+  \newunicodechar{∈}{{\DejaVuSansMono ∈}}% U+2208
+  \newunicodechar{∌}{{\DejaVuSansMono ∌}}% U+220C
+  %\newunicodechar{␣}{{\DejaVuSansMono ␣}}% U+2423  Missing!
+  %\newunicodechar{^^^^2423}{{\DejaVuSansMono^^^^2423}}% U+2423
+  %\newunicodechar{␣}{\textvisiblespace}% U+2423
+  %\catcode`^^^^2423\active\protected\def^^^^2423{\textvisiblespace}
+
+  \PassOptionsToPackage{%
+    verbatimvisiblespace={\textcolor{red}{{\DejaVuSansMono^^^^2423}}},%
+    verbatimcontinued={\textcolor{red}{{\DejaVuSansMono^^^^21aa}}}}%
+    {sphinx}
+\fi
+\endinput
--- a/docs/conf.py	Tue May 12 13:48:00 2026 +0200
+++ b/docs/conf.py	Tue May 12 14:58:14 2026 +0200
@@ -134,10 +134,7 @@
 latex_elements = {
     "papersize": "a4paper",
     "babel": r"\usepackage{babel}",
-    "fontpkg": r"""
-\usepackage[DefaultFeatures={Scale=0.92},mono=false]{plex-otf}
-\usepackage[mono=true,serif=false,sans=false,math=false]{dejavu-otf}  % all symbols are available
-""",
+    "fontpkg": r"\usepackage[plexmono]{my-doc-fonts}",
     "releasename": "Version",
 }
 latex_theme = "manual"
@@ -147,7 +144,9 @@
 latex_documents = [
     ("index-latex", "PygmentsPseudocodeLexer.tex", "The Pygments Pseudocode Lexer", "Franz Glasner", "manual", True),
 ]
-
+latex_additional_files = [
+    "_latex/my-doc-fonts.sty"
+]    
 
 def setup(app):
     #