Documentation / sphinx / kerneldoc-preamble.sty


Based on kernel version 6.8. Page generated on 2024-03-11 21:26 EST.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
% -*- coding: utf-8 -*-
% SPDX-License-Identifier: GPL-2.0
%
% LaTeX preamble for "make latexdocs" or "make pdfdocs" including:
%   - TOC width settings
%   - Setting of tabulary (\tymin)
%   - Headheight setting for fancyhdr
%   - Fontfamily settings for CJK (Chinese, Japanese, and Korean) translations
%
% Note on the suffix of .sty:
%   This is not implemented as a LaTeX style file, but as a file containing
%   plain LaTeX code to be included into preamble.
%   ".sty" is chosen because ".tex" would cause the build scripts to confuse
%   this file with a LaTeX main file.
%
% Copyright (C) 2022  Akira Yokosawa

% Custom width parameters for TOC
%  - Redefine low-level commands defined in report.cls.
%  - Indent of 2 chars is preserved for ease of comparison.
% Summary of changes from default params:
%   Width of page number (\@pnumwidth): 1.55em -> 2.7em
%   Width of chapter number:            1.5em  -> 2.4em
%   Indent of section number:           1.5em  -> 2.4em
%   Width of section number:            2.6em  -> 3.2em
%   Indent of subsection number:        4.1em  -> 5.6em
%   Width of subsection number:         3.5em  -> 4.3em
%
% These params can have 4 digit page counts, 3 digit chapter counts,
% section counts of 4 digits + 1 period (e.g., 18.10), and subsection counts
% of 5 digits + 2 periods (e.g., 18.7.13).
\makeatletter
%% Redefine \@pnumwidth (page number width)
\renewcommand*\@pnumwidth{2.7em}
%% Redefine \l@chapter (chapter list entry)
\renewcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{2.4em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\hfil
      \nobreak\hb@xt@\@pnumwidth{\hss #2%
                                 \kern-\p@\kern\p@}\par
      \penalty\@highpenalty
    \endgroup
  \fi}
%% Redefine \l@section and \l@subsection
\renewcommand*\l@section{\@dottedtocline{1}{2.4em}{3.2em}}
\renewcommand*\l@subsection{\@dottedtocline{2}{5.6em}{4.3em}}
\makeatother
%% Sphinx < 1.8 doesn't have \sphinxtableofcontentshook
\providecommand{\sphinxtableofcontentshook}{}
%% Undefine it for compatibility with Sphinx 1.7.9
\renewcommand{\sphinxtableofcontentshook}{} % Empty the hook

% Prevent column squeezing of tabulary.  \tymin is set by Sphinx as:
%   \setlength{\tymin}{3\fontcharwd\font`0 }
% , which is too short.
\setlength{\tymin}{20em}

% Adjust \headheight for fancyhdr
\addtolength{\headheight}{1.6pt}
\addtolength{\topmargin}{-1.6pt}

% Translations have Asian (CJK) characters which are only displayed if
% xeCJK is used
\usepackage{ifthen}
\newboolean{enablecjk}
\setboolean{enablecjk}{false}
\IfFontExistsTF{Noto Sans CJK SC}{
    \IfFileExists{xeCJK.sty}{
	\setboolean{enablecjk}{true}
    }{}
}{}
\ifthenelse{\boolean{enablecjk}}{
    % Load xeCJK when both the Noto Sans CJK font and xeCJK.sty are available.
    \usepackage{xeCJK}
    % Noto CJK fonts don't provide slant shape. [AutoFakeSlant] permits
    % its emulation.
    % Select KR variant at the beginning of each document so that quotation
    % and apostorph symbols of half-width is used in TOC of Latin documents.
    \IfFontExistsTF{Noto Serif CJK KR}{
	\setCJKmainfont{Noto Serif CJK KR}[AutoFakeSlant]
    }{
	\setCJKmainfont{Noto Sans CJK KR}[AutoFakeSlant]
    }
    \setCJKsansfont{Noto Sans CJK KR}[AutoFakeSlant]
    \setCJKmonofont{Noto Sans Mono CJK KR}[AutoFakeSlant]
    % Teach xeCJK of half-width symbols
    \xeCJKDeclareCharClass{HalfLeft}{`“,`‘}
    \xeCJKDeclareCharClass{HalfRight}{`”,`’}
    % CJK Language-specific font choices
    %% for Simplified Chinese
    \IfFontExistsTF{Noto Serif CJK SC}{
	\newCJKfontfamily[SCmain]\scmain{Noto Serif CJK SC}[AutoFakeSlant]
	\newCJKfontfamily[SCserif]\scserif{Noto Serif CJK SC}[AutoFakeSlant]
    }{
	\newCJKfontfamily[SCmain]\scmain{Noto Sans CJK SC}[AutoFakeSlant]
	\newCJKfontfamily[SCserif]\scserif{Noto Sans CJK SC}[AutoFakeSlant]
    }
    \newCJKfontfamily[SCsans]\scsans{Noto Sans CJK SC}[AutoFakeSlant]
    \newCJKfontfamily[SCmono]\scmono{Noto Sans Mono CJK SC}[AutoFakeSlant]
    %% for Traditional Chinese
    \IfFontExistsTF{Noto Serif CJK TC}{
	\newCJKfontfamily[TCmain]\tcmain{Noto Serif CJK TC}[AutoFakeSlant]
	\newCJKfontfamily[TCserif]\tcserif{Noto Serif CJK TC}[AutoFakeSlant]
    }{
	\newCJKfontfamily[TCmain]\tcmain{Noto Sans CJK TC}[AutoFakeSlant]
	\newCJKfontfamily[TCserif]\tcserif{Noto Sans CJK TC}[AutoFakeSlant]
    }
    \newCJKfontfamily[TCsans]\tcsans{Noto Sans CJK TC}[AutoFakeSlant]
    \newCJKfontfamily[TCmono]\tcmono{Noto Sans Mono CJK TC}[AutoFakeSlant]
    %% for Korean
    \IfFontExistsTF{Noto Serif CJK KR}{
	\newCJKfontfamily[KRmain]\krmain{Noto Serif CJK KR}[AutoFakeSlant]
	\newCJKfontfamily[KRserif]\krserif{Noto Serif CJK KR}[AutoFakeSlant]
    }{
	\newCJKfontfamily[KRmain]\krmain{Noto Sans CJK KR}[AutoFakeSlant]
	\newCJKfontfamily[KRserif]\krserif{Noto Sans CJK KR}[AutoFakeSlant]
    }
    \newCJKfontfamily[KRsans]\krsans{Noto Sans CJK KR}[AutoFakeSlant]
    \newCJKfontfamily[KRmono]\krmono{Noto Sans Mono CJK KR}[AutoFakeSlant]
    %% for Japanese
    \IfFontExistsTF{Noto Serif CJK JP}{
	\newCJKfontfamily[JPmain]\jpmain{Noto Serif CJK JP}[AutoFakeSlant]
	\newCJKfontfamily[JPserif]\jpserif{Noto Serif CJK JP}[AutoFakeSlant]
    }{
	\newCJKfontfamily[JPmain]\jpmain{Noto Sans CJK JP}[AutoFakeSlant]
	\newCJKfontfamily[JPserif]\jpserif{Noto Sans CJK JP}[AutoFakeSlant]
    }
    \newCJKfontfamily[JPsans]\jpsans{Noto Sans CJK JP}[AutoFakeSlant]
    \newCJKfontfamily[JPmono]\jpmono{Noto Sans Mono CJK JP}[AutoFakeSlant]
    % Dummy commands for Sphinx < 2.3 (no 'extrapackages' support)
    \providecommand{\onehalfspacing}{}
    \providecommand{\singlespacing}{}
    % Define custom macros to on/off CJK
    %% One and half spacing for CJK contents
    \newcommand{\kerneldocCJKon}{\makexeCJKactive\onehalfspacing}
    \newcommand{\kerneldocCJKoff}{\makexeCJKinactive\singlespacing}
    % Define custom macros for switching CJK font setting
    %% for Simplified Chinese
    \newcommand{\kerneldocBeginSC}{%
	\begingroup%
	\scmain%
	\xeCJKDeclareCharClass{FullLeft}{`“,`‘}% Full-width in SC
	\xeCJKDeclareCharClass{FullRight}{`”,`’}% Full-width in SC
	\renewcommand{\CJKrmdefault}{SCserif}%
	\renewcommand{\CJKsfdefault}{SCsans}%
	\renewcommand{\CJKttdefault}{SCmono}%
	\xeCJKsetup{CJKspace = false}% gobble white spaces by ' '
	% For CJK ascii-art alignment
	\setmonofont{Noto Sans Mono CJK SC}[AutoFakeSlant]%
    }
    \newcommand{\kerneldocEndSC}{\endgroup}
    %% for Traditional Chinese
    \newcommand{\kerneldocBeginTC}{%
	\begingroup%
	\tcmain%
	\xeCJKDeclareCharClass{FullLeft}{`“,`‘}% Full-width in TC
	\xeCJKDeclareCharClass{FullRight}{`”,`’}% Full-width in TC
	\renewcommand{\CJKrmdefault}{TCserif}%
	\renewcommand{\CJKsfdefault}{TCsans}%
	\renewcommand{\CJKttdefault}{TCmono}%
	\xeCJKsetup{CJKspace = false}% gobble white spaces by ' '
	% For CJK ascii-art alignment
	\setmonofont{Noto Sans Mono CJK TC}[AutoFakeSlant]%
    }
    \newcommand{\kerneldocEndTC}{\endgroup}
    %% for Korean
    \newcommand{\kerneldocBeginKR}{%
	\begingroup%
	\krmain%
	\renewcommand{\CJKrmdefault}{KRserif}%
	\renewcommand{\CJKsfdefault}{KRsans}%
	\renewcommand{\CJKttdefault}{KRmono}%
	% \xeCJKsetup{CJKspace = true} % true by default
	% For CJK ascii-art alignment (still misaligned for Hangul)
	\setmonofont{Noto Sans Mono CJK KR}[AutoFakeSlant]%
    }
    \newcommand{\kerneldocEndKR}{\endgroup}
    %% for Japanese
    \newcommand{\kerneldocBeginJP}{%
	\begingroup%
	\jpmain%
	\renewcommand{\CJKrmdefault}{JPserif}%
	\renewcommand{\CJKsfdefault}{JPsans}%
	\renewcommand{\CJKttdefault}{JPmono}%
	\xeCJKsetup{CJKspace = false}% gobble white space by ' '
	% For CJK ascii-art alignment
	\setmonofont{Noto Sans Mono CJK JP}[AutoFakeSlant]%
    }
    \newcommand{\kerneldocEndJP}{\endgroup}

    % Single spacing in literal blocks
    \fvset{baselinestretch=1}
    % To customize \sphinxtableofcontents
    \usepackage{etoolbox}
    % Inactivate CJK after tableofcontents
    \apptocmd{\sphinxtableofcontents}{\kerneldocCJKoff}{}{}
    \xeCJKsetup{CJKspace = true}% For inter-phrase space of Korean TOC
}{ % Don't enable CJK
    % Custom macros to on/off CJK and switch CJK fonts (Dummy)
    \newcommand{\kerneldocCJKon}{}
    \newcommand{\kerneldocCJKoff}{}
    %% By defining \kerneldocBegin(SC|TC|KR|JP) as commands with an argument
    %% and ignore the argument (#1) in their definitions, whole contents of
    %% CJK chapters can be ignored.
    \newcommand{\kerneldocBeginSC}[1]{%
	%% Put a note on missing CJK fonts or the xecjk package in place of
	%% zh_CN translation.
	\begin{sphinxadmonition}{note}{Note on missing fonts and a package:}
	    Translations of Simplified Chinese (zh\_CN), Traditional Chinese
	    (zh\_TW), Korean (ko\_KR), and Japanese (ja\_JP) were skipped
	    due to the lack of suitable font families and/or the texlive-xecjk
	    package.

	    If you want them, please install ``Noto Sans CJK'' font families
	    along with the texlive-xecjk package by following instructions from
	    \sphinxcode{./scripts/sphinx-pre-install}.
	    Having optional ``Noto Serif CJK'' font families will improve
	    the looks of those translations.
	\end{sphinxadmonition}}
    \newcommand{\kerneldocEndSC}{}
    \newcommand{\kerneldocBeginTC}[1]{}
    \newcommand{\kerneldocEndTC}{}
    \newcommand{\kerneldocBeginKR}[1]{}
    \newcommand{\kerneldocEndKR}{}
    \newcommand{\kerneldocBeginJP}[1]{}
    \newcommand{\kerneldocEndJP}{}
}