Skip to content

Commit

Permalink
docs: pdfdocs: Refactor config for CJK document
Browse files Browse the repository at this point in the history
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 <akiyks@gmail.com>
Link: https://lore.kernel.org/r/4baf88af-316d-8aee-240f-6ccbc20907d7@gmail.com
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
  • Loading branch information
Akira Yokosawa authored and Jonathan Corbet committed Aug 12, 2021
1 parent bed4ed3 commit 659653c
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions Documentation/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import os
import sphinx

from subprocess import check_output

# Get Sphinx version
major, minor, patch = sphinx.version_info[:3]

Expand Down Expand Up @@ -355,29 +353,27 @@
''',
}

# At least one book (translations) may have Asian characters
# with are only displayed if xeCJK is used
# Translations have Asian (CJK) characters which are only displayed if
# xeCJK is used

cjk_cmd = check_output(['fc-list', '--format="%{family[0]}\n"']).decode('utf-8', 'ignore')
if cjk_cmd.find("Noto Sans CJK SC") >= 0:
latex_elements['preamble'] += '''
latex_elements['preamble'] += '''
\\IfFontExistsTF{Noto Sans CJK SC}{
% This is needed for translations
\\usepackage{xeCJK}
\\setCJKmainfont{Noto Sans CJK SC}
\\usepackage{xeCJK}
\\setCJKmainfont{Noto Sans CJK SC}
% Define custom macros to on/off CJK
\\newcommand{\\kerneldocCJKon}{\\makexeCJKactive}
\\newcommand{\\kerneldocCJKoff}{\\makexeCJKinactive}
% To customize \sphinxtableofcontents
\\usepackage{etoolbox}
% Inactivate CJK after tableofcontents
\\apptocmd{\\sphinxtableofcontents}{\\kerneldocCJKoff}{}{}
'''
else:
latex_elements['preamble'] += '''
}{ % No CJK font found
% Custom macros to on/off CJK (Dummy)
\\newcommand{\\kerneldocCJKon}{}
\\newcommand{\\kerneldocCJKoff}{}
'''
}
'''

# Fix reference escape troubles with Sphinx 1.4.x
if major == 1:
Expand Down

0 comments on commit 659653c

Please sign in to comment.