Skip to content

Commit 659653c

Browse files
akiyksJonathan Corbet
authored andcommitted
docs: pdfdocs: Refactor config for CJK document
To make generated LaTeX code portable across systems with different sets of available fonts, convert font-availability check in python code to LaTeX code by using a conditional command provided by the "fontspec" package. This will help those who run Sphinx on one machine/container and run latexmk on other machines/containers. Remove import of check_output as it is unused any more. Signed-off-by: Akira Yokosawa <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jonathan Corbet <[email protected]>
1 parent bed4ed3 commit 659653c

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

Documentation/conf.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
import os
1717
import sphinx
1818

19-
from subprocess import check_output
20-
2119
# Get Sphinx version
2220
major, minor, patch = sphinx.version_info[:3]
2321

@@ -355,29 +353,27 @@
355353
''',
356354
}
357355

358-
# At least one book (translations) may have Asian characters
359-
# with are only displayed if xeCJK is used
356+
# Translations have Asian (CJK) characters which are only displayed if
357+
# xeCJK is used
360358

361-
cjk_cmd = check_output(['fc-list', '--format="%{family[0]}\n"']).decode('utf-8', 'ignore')
362-
if cjk_cmd.find("Noto Sans CJK SC") >= 0:
363-
latex_elements['preamble'] += '''
359+
latex_elements['preamble'] += '''
360+
\\IfFontExistsTF{Noto Sans CJK SC}{
364361
% This is needed for translations
365-
\\usepackage{xeCJK}
366-
\\setCJKmainfont{Noto Sans CJK SC}
362+
\\usepackage{xeCJK}
363+
\\setCJKmainfont{Noto Sans CJK SC}
367364
% Define custom macros to on/off CJK
368365
\\newcommand{\\kerneldocCJKon}{\\makexeCJKactive}
369366
\\newcommand{\\kerneldocCJKoff}{\\makexeCJKinactive}
370367
% To customize \sphinxtableofcontents
371368
\\usepackage{etoolbox}
372369
% Inactivate CJK after tableofcontents
373370
\\apptocmd{\\sphinxtableofcontents}{\\kerneldocCJKoff}{}{}
374-
'''
375-
else:
376-
latex_elements['preamble'] += '''
371+
}{ % No CJK font found
377372
% Custom macros to on/off CJK (Dummy)
378373
\\newcommand{\\kerneldocCJKon}{}
379374
\\newcommand{\\kerneldocCJKoff}{}
380-
'''
375+
}
376+
'''
381377

382378
# Fix reference escape troubles with Sphinx 1.4.x
383379
if major == 1:

0 commit comments

Comments
 (0)