docs: Activate xeCJK only in CJK chapters
Subsystems (5)
Akira Yokosawa
reviewerPATCH 1/1 docs: Activate xeCJK only in CJK chapters
Activating xeCJK in English or Italian-translation documents results in sub-optimal typesetting with wide-looking apostrophes and quotation marks.
The xeCJK package provides macros for enabling and disabling its effect in the middle of a document, namely \makexeCJKactive and \makexeCJKinactive.
So the goal of this change is to activate xeCJK in the relevant chapters in translations.
To do this:
o Define custom macros in the preamble depending on the availability of the "Noto Sans CJK" font so that those macros can be embedded in translations.tex after the fact. By default, xeCJK is inactive.
o Add a script retouch-translations.sh to embed the on/off macros in translations.tex where necessary.
The patterns in the script are ad-hoc by nature, and will need updates when the chapter organization changes.
o Invoke the script at the final step of target "latexdocs".
---
Hi Mauro,
Good news.
xeCJK can be activated/deactivated inside a document. Which means we can activate xeCJK only in the CJK chapters of the translations document.
This patch is an attempt to do so.
I think there still is ad-hoc aspect in this approach, but it also fixed the build error of s390.pdf I encountered yesterday (with the CJK font installed).
"make pdfdocs" now completes successfully both with and without the CJK font installed.
Can you try this?
Any feedback is welcome!
Thanks, Akira
--
Documentation/Makefile | 2 ++ Documentation/conf.py | 11 ++++++++ Documentation/sphinx/retouch-translations.sh | 29 ++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100755 Documentation/sphinx/retouch-translations.sh
Documentation/Makefile +2 -0
@@ -96,6 +96,8 @@ linkcheckdocs: latexdocs: @$(srctree)/scripts/sphinx-pre-install --version-check @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,latex,$(var),latex,$(var))) + @find $(BUILDDIR) -name translations.tex -exec \ + sh $(srctree)/Documentation/sphinx/retouch-translations.sh \{\} \; ifeq ($(HAVE_PDFLATEX),0)
Documentation/conf.py +11 -0
@@ -371,6 +371,17 @@ if cjk_cmd.find("Noto Sans CJK SC") >= 0: % This is needed for translations \\usepackage{xeCJK} \\setCJKmainfont{Noto Sans CJK SC} + % Define custom macro to on/off CJK + \\newcommand{\\kerneldocCJKon}{\\makexeCJKactive} + \\newcommand{\\kerneldocCJKoff}{\\makexeCJKinactive} + % CJK off by default + \\kerneldocCJKoff + ''' +else: + latex_elements['preamble'] += ''' + % Dummy custom macro to on/off CJK + \\newcommand{\\kerneldocCJKon}{} + \\newcommand{\\kerneldocCJKoff}{} ''' # Fix reference escape troubles with Sphinx 1.4.x
Documentation/sphinx/retouch-translations.sh new file +29 -0
@@ -0,0 +1,29 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# Copyright 2021 Akira Yokosawa <[email protected]> +# +# Retouch translations.tex to add CJK on/off macros. +# The substitution rules need updates when there is some change in +# the ordering of chapters. +# +# Path of the file to be retouched is passed in command argument $1 +# from docs Makefile. +# If there is no need of retouch, do nothing. + +retouch=$1 + +if [ -e $retouch ]; then + if grep -q 'kerneldocCJKon\\chapter' $retouch ; then + exit 0 + fi + sed -i -e 's/\(\\sphinxtableofcontents\)/\\kerneldocCJKon\1/' \ + -e 's/\(\\chapter{中文\)/\\kerneldocCJKon\1/' \ + -e 's/\(\\chapter{Traduzione[^}]*}\)/\1\\kerneldocCJKoff/' \ + -e 's/\(\\chapter{한국어\)/\\kerneldocCJKon\1/' \ + -e 's/\(\\chapter{Disclaimer[^}]*}\)/\1\\kerneldocCJKoff/' \ + $retouch + echo "$retouch retouched." + exit 0 +else + exit 0 +fi
Signature · 1 line
2.17.1
Quoted 23 lines · Akira Yokosawa
Activating xeCJK in English or Italian-translation documents results in sub-optimal typesetting with wide-looking apostrophes and quotation marks.
The xeCJK package provides macros for enabling and disabling its effect in the middle of a document, namely \makexeCJKactive and \makexeCJKinactive.
So the goal of this change is to activate xeCJK in the relevant chapters in translations.
To do this:
o Define custom macros in the preamble depending on the availability of the "Noto Sans CJK" font so that those macros can be embedded in translations.tex after the fact. By default, xeCJK is inactive.
o Add a script
retouch-translations.shto embed the on/off macros in translations.tex where necessary.
The patterns in the script are ad-hoc by nature, and will need updates when the chapter organization changes.
Quoted 5 lines
o Invoke the script at the final step of target "latexdocs".
Signed-off-by Akira Yokosawa <[email protected]>---
Hi Akira,
Test this patch with Noto Sans SC font, worked well. “” use right font in western language docs now.
Thanks,
Wu X.C.
Akira Yokosawa
reviewerQuoted 27 lines · Wu X.C.
Quoted 26 lines · Akira Yokosawa
Activating xeCJK in English or Italian-translation documents results in sub-optimal typesetting with wide-looking apostrophes and quotation marks.
The xeCJK package provides macros for enabling and disabling its effect in the middle of a document, namely \makexeCJKactive and \makexeCJKinactive.
So the goal of this change is to activate xeCJK in the relevant chapters in translations.
To do this:
o Define custom macros in the preamble depending on the availability of the "Noto Sans CJK" font so that those macros can be embedded in translations.tex after the fact. By default, xeCJK is inactive.
o Add a script
retouch-translations.shto embed the on/off macros in translations.tex where necessary.
The patterns in the script are ad-hoc by nature, and will need updates when the chapter organization changes.o Invoke the script at the final step of target "latexdocs".
Quoted 8 lines
Quoted 2 lines
Signed-off-by Akira Yokosawa <[email protected]>---
Hi Akira,
Test this patch with Noto Sans SC font, worked well. “” use right font in western language docs now.>
Tested-by Wu XiangCheng <[email protected]>
Thank you for testing!
As Mauro has a simpler and better idea to do this, I need to do a respin. I'll add you in the CC list.
Thanks, Akira
Quoted 4 lines
Thanks,
Wu X.C.
Mauro Carvalho Chehab
maintainerEm Sat, 22 May 2021 16:28:55 +0900
Akira Yokosawa <[email protected]> escreveu:
Quoted 18 lines
Activating xeCJK in English or Italian-translation documents results in sub-optimal typesetting with wide-looking apostrophes and quotation marks.
The xeCJK package provides macros for enabling and disabling its effect in the middle of a document, namely \makexeCJKactive and \makexeCJKinactive.
So the goal of this change is to activate xeCJK in the relevant chapters in translations.
To do this:
o Define custom macros in the preamble depending on the availability of the "Noto Sans CJK" font so that those macros can be embedded in translations.tex after the fact. By default, xeCJK is inactive.
Quoted 6 lines
o Add a script
retouch-translations.shto embed the on/off macros in translations.tex where necessary.
The patterns in the script are ad-hoc by nature, and will need updates when the chapter organization changes.o Invoke the script at the final step of target "latexdocs".
Interesting solution, but there are probably an easy/better way of doing something similar to it.
There is an extension called:
Documentation/sphinx/load_config.py
Which allows using a per-document conf.py file. While it can also be used to have a "nitpick" version where extra warnings are enabled, the main usage were to have separated PDF documents.
We ended finding a better solution, so most conf.py got removed on this patch: 9fc3a18a942f ("docs: remove extra conf.py files").
Anyway, perhaps we could simply add a Documentation/translations/conf.py that would add the CJK font only there.
Even better, we could even improve it in a way that each translation would generate a separated book, and then use CJK only for the non-Latin translations.
Regards,
Mauro
Akira Yokosawa
reviewerQuoted 39 lines · Mauro Carvalho Chehab
Em Sat, 22 May 2021 16:28:55 +0900
Akira Yokosawa <[email protected]> escreveu:Quoted 18 lines
Activating xeCJK in English or Italian-translation documents results in sub-optimal typesetting with wide-looking apostrophes and quotation marks.
The xeCJK package provides macros for enabling and disabling its effect in the middle of a document, namely \makexeCJKactive and \makexeCJKinactive.
So the goal of this change is to activate xeCJK in the relevant chapters in translations.
To do this:
o Define custom macros in the preamble depending on the availability of the "Noto Sans CJK" font so that those macros can be embedded in translations.tex after the fact. By default, xeCJK is inactive.
Quoted 6 lines
o Add a script
retouch-translations.shto embed the on/off macros in translations.tex where necessary.
The patterns in the script are ad-hoc by nature, and will need updates when the chapter organization changes.o Invoke the script at the final step of target "latexdocs".
Interesting solution, but there are probably an easy/better way of doing something similar to it.
There is an extension called:
Documentation/sphinx/load_config.pyWhich allows using a per-document
conf.pyfile. While it can also be used to have a "nitpick" version where extra warnings are enabled, the main usage were to have separated PDF documents.
Quoted 5 lines
We ended finding a better solution, so most
conf.pygot removed on this patch:9fc3a18a942f("docs: remove extraconf.pyfiles").Anyway, perhaps we could simply add a
Documentation/translations/conf.pythat would add the CJK font only there.
Ah, that sounds like the way to go!
But I have no idea how I can load that extra conf.py for translations.
Simply putting the following as Documentation/translations/conf.py doesn't work.
----
# -*- coding: utf-8; mode: python -*-
# translations have Asian 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:
print ("translations: enabling CJK for LaTeX builder")
latex_elements['preamble'] += '''
% This is needed for translations
\\usepackage{xeCJK}
\\setCJKmainfont{Noto Sans CJK SC}
'''----
What am I missing?
Note: I'm not good at python.
Thanks, Akira
Quoted 8 lines
Even better, we could even improve it in a way that each translation would generate a separated book, and then use CJK only for the non-Latin translations.
Regards,
Mauro
Akira Yokosawa
reviewerPATCH v2 1/1 docs: Activate exCJK only in CJK chapters
In reply to Akira YokosawaActivating xeCJK in English and Italian-translation documents results in sub-optimal typesetting with wide-looking apostrophes and quotation marks.
The xeCJK package provides macros for enabling and disabling its effect in the middle of a document, namely \makexeCJKactive and \makexeCJKinactive.
So the goal of this change is to activate xeCJK in the relevant chapters in translations.
To do this:
o Define custom macros in the preamble depending on the availability of the "Noto Sans CJK" font so that those macros can be used regardless of the use of xeCJK package.
o Patch \sphinxtableofcontents so that xeCJK is inactivated after table of contents.
o Embed those custom macros in each language's index.rst file as a ".. raw:: latex" construct.
Note: A CJK chapter needs \kerneldocCJKon in front of its chapter heading, while a non-CJK chapter should have \kerneldocCJKoff below its chapter heading.
This is to make sure the CJK font is available to CJK chapter's heading and ending page's footer.
---
Hi all,
I'm still unable to manage the per-directory conf.py idea to work, but as far as activation/inactivation of xeCJK is concerned, the custom LaTeX macros can be embedded in each language's index.rst.
Also note that the on/off macros added here are still useful when the xeCJK related settings are moved into per-directory conf.py, because of the Disclaimer in English.
I think per-directory conf.py can be tried as a follow-up change after this patch is applied.
Thoughts?
Thanks, Akira
--
Documentation/conf.py | 13 +++++++++++++ Documentation/translations/index.rst | 4 ++++ Documentation/translations/it_IT/index.rst | 4 ++++ Documentation/translations/ja_JP/index.rst | 5 +++-- Documentation/translations/ko_KR/index.rst | 5 +++-- Documentation/translations/zh_CN/index.rst | 1 + 6 files changed, 28 insertions(+), 4 deletions(-)
Documentation/conf.py +13 -0
@@ -371,6 +371,19 @@ if cjk_cmd.find("Noto Sans CJK SC") >= 0: % This is needed for translations \\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'] += ''' + % Custom macros to on/off CJK (Dummy) + \\newcommand{\\kerneldocCJKon}{} + \\newcommand{\\kerneldocCJKoff}{} ''' # Fix reference escape troubles with Sphinx 1.4.x
Documentation/translations/index.rst +4 -0
@@ -18,6 +18,10 @@ Translations Disclaimer ---------- +.. raw:: latex + + \kerneldocCJKoff + Translation's purpose is to ease reading and understanding in languages other than English. Its aim is to help people who do not understand English or have doubts about its interpretation. Additionally, some people prefer to read
Documentation/translations/it_IT/index.rst +4 -0
@@ -4,6 +4,10 @@ Traduzione italiana =================== +.. raw:: latex + + \kerneldocCJKoff + :manutentore: Federico Vaga <[email protected]> .. _it_disclaimer:
Documentation/translations/ja_JP/index.rst +3 -2
@@ -1,7 +1,8 @@ .. raw:: latex - \renewcommand\thesection* - \renewcommand\thesubsection* + \renewcommand\thesection* + \renewcommand\thesubsection* + \kerneldocCJKon Japanese translations =====================
Documentation/translations/ko_KR/index.rst +3 -2
@@ -1,7 +1,8 @@ .. raw:: latex - \renewcommand\thesection* - \renewcommand\thesubsection* + \renewcommand\thesection* + \renewcommand\thesubsection* + \kerneldocCJKon 한국어 번역 ===========
Documentation/translations/zh_CN/index.rst +1 -0
@@ -4,6 +4,7 @@ \renewcommand\thesection* \renewcommand\thesubsection* + \kerneldocCJKon .. _linux_doc_zh:
Signature · 1 line
2.17.1
Re: [PATCH v2] docs: Activate exCJK only in CJK chapters
Quoted 23 lines · Akira Yokosawa
Activating xeCJK in English and Italian-translation documents results in sub-optimal typesetting with wide-looking apostrophes and quotation marks.
The xeCJK package provides macros for enabling and disabling its effect in the middle of a document, namely \makexeCJKactive and \makexeCJKinactive.
So the goal of this change is to activate xeCJK in the relevant chapters in translations.
To do this:
o Define custom macros in the preamble depending on the availability of the "Noto Sans CJK" font so that those macros can be used regardless of the use of xeCJK package.
o Patch \sphinxtableofcontents so that xeCJK is inactivated after table of contents.
o Embed those custom macros in each language's
index.rstfile as a ".. raw:: latex" construct.
Quoted 8 lines
Note: A CJK chapter needs \kerneldocCJKon in front of its chapter heading, while a non-CJK chapter should have \kerneldocCJKoff below its chapter heading.
This is to make sure the CJK font is available to CJK chapter's heading and ending page's footer.
Signed-off-by Akira Yokosawa <[email protected]>
Test it, worked well.
And one warning when am patch:
.git/rebase-apply/patch:62: trailing whitespace.
\kerneldocCJKoff
Quoted 2 lines
I think per-directory
conf.pycan be tried as a follow-up change after this patch is applied.
Agree, I think it's enough for this problem.
If we need more complex customization, per-directory conf.py then worth.
Quoted 18 lines
Documentation/translations/index.rst +4
-0@@ -18,6 +18,10 @@ Translations Disclaimer ---------- +.. raw:: latex + + \kerneldocCJKoff + Translation's purpose is to ease reading and understanding in languages other than English. Its aim is to help people who do not understand English or have doubts about its interpretation. Additionally, some people prefer to readDocumentation/translations/it_IT/index.rst +0
-0
Documentation/translations/it_IT/index.rst line 13
Quoted 10 lines
Documentation/translations/it_IT/index.rst +4
-0@@ -4,6 +4,10 @@ Traduzione italiana =================== +.. raw:: latex + + \kerneldocCJKoff + :manutentore: Federico Vaga <[email protected]> .. _it_disclaimer:
And for above two, maybe better to put "raw:: latex" block above the title, more beautiful, and CJKoff will be done before enter "Italiana" chapter.
Thanks,
Wu X.C.
Akira Yokosawa
reviewerRe: [PATCH v2] docs: Activate exCJK only in CJK chapters
Quoted 28 lines · Wu X.C.
Quoted 27 lines · Akira Yokosawa
Activating xeCJK in English and Italian-translation documents results in sub-optimal typesetting with wide-looking apostrophes and quotation marks.
The xeCJK package provides macros for enabling and disabling its effect in the middle of a document, namely \makexeCJKactive and \makexeCJKinactive.
So the goal of this change is to activate xeCJK in the relevant chapters in translations.
To do this:
o Define custom macros in the preamble depending on the availability of the "Noto Sans CJK" font so that those macros can be used regardless of the use of xeCJK package.
o Patch \sphinxtableofcontents so that xeCJK is inactivated after table of contents.
o Embed those custom macros in each language's
index.rstfile as a ".. raw:: latex" construct.Note: A CJK chapter needs \kerneldocCJKon in front of its chapter heading, while a non-CJK chapter should have \kerneldocCJKoff below its chapter heading.
Quoted 8 lines
Quoted 4 lines
This is to make sure the CJK font is available to CJK chapter's heading and ending page's footer.
Signed-off-by Akira Yokosawa <[email protected]>Test it, worked well.
Tested-by Wu XiangCheng <[email protected]>
Thanks!
Quoted 5 lines
And one warning when am patch:
.git/rebase-apply/patch:62: trailing whitespace.
\kerneldocCJKoff
Oops, will fix and post v3 soon, with your Tested-by: appended
Quoted 35 lines
Quoted 4 lines
I think per-directory
conf.pycan be tried as a follow-up change after this patch is applied.Agree, I think it's enough for this problem.
If we need more complex customization, per-directoryconf.pythen worth.Quoted 27 lines
Documentation/translations/index.rst +4
-0@@ -18,6 +18,10 @@ Translations Disclaimer ---------- +.. raw:: latex + + \kerneldocCJKoff + Translation's purpose is to ease reading and understanding in languages other than English. Its aim is to help people who do not understand English or have doubts about its interpretation. Additionally, some people prefer to readDocumentation/translations/it_IT/index.rst +4
-0@@ -4,6 +4,10 @@ Traduzione italiana =================== +.. raw:: latex + + \kerneldocCJKoff + :manutentore: Federico Vaga <[email protected]>
Quoted 5 lines
Documentation/translations/it_IT/index.rst line 13
Quoted 1 line
Documentation/translations/it_IT/index.rst +0
-0.. _it_disclaimer:And for above two, maybe better to put "raw:: latex" block above the title, more beautiful, and CJKoff will be done before enter "Italiana" chapter.
These two are placed there intentionally.
As mentioned in the change log:
Quoted 6 lines
Quoted 6 lines
Note: A CJK chapter needs \kerneldocCJKon in front of its chapter heading, while a non-CJK chapter should have \kerneldocCJKoff below its chapter heading.
This is to make sure the CJK font is available to CJK chapter's heading and ending page's footer.
If they are put above chapter titles in the .rst files, Chinese translation's final page's footer won't be rendered properly.
Thanks, Akira
Quoted 4 lines
Thanks,
Wu X.C.
Mauro Carvalho Chehab
Reviewed-byRe: [PATCH v2] docs: Activate exCJK only in CJK chapters
Em Tue, 25 May 2021 21:55:53 +0900
Akira Yokosawa <[email protected]> escreveu:
Quoted 41 lines · Wu X.C.
Quoted 28 lines · Akira Yokosawa
Quoted 27 lines
Activating xeCJK in English and Italian-translation documents results in sub-optimal typesetting with wide-looking apostrophes and quotation marks.
The xeCJK package provides macros for enabling and disabling its effect in the middle of a document, namely \makexeCJKactive and \makexeCJKinactive.
So the goal of this change is to activate xeCJK in the relevant chapters in translations.
To do this:
o Define custom macros in the preamble depending on the availability of the "Noto Sans CJK" font so that those macros can be used regardless of the use of xeCJK package.
o Patch \sphinxtableofcontents so that xeCJK is inactivated after table of contents.
o Embed those custom macros in each language's
index.rstfile as a ".. raw:: latex" construct.Note: A CJK chapter needs \kerneldocCJKon in front of its chapter heading, while a non-CJK chapter should have \kerneldocCJKoff below its chapter heading.
Quoted 8 lines
Quoted 4 lines
This is to make sure the CJK font is available to CJK chapter's heading and ending page's footer.
Signed-off-by Akira Yokosawa <[email protected]>Test it, worked well.
Tested-by Wu XiangCheng <[email protected]>Thanks!
Quoted 1 line
Quoted 6 lines
Quoted 4 lines
And one warning when am patch:
.git/rebase-apply/patch:62: trailing whitespace.
\kerneldocCJKoffOops, will fix and post v3 soon, with your Tested-by: appended
You can also add:
(but see below)
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
I think per-directory
conf.pycan be tried as a follow-up change after this patch is applied.Agree, I think it's enough for this problem.
If we need more complex customization, per-directoryconf.pythen worth.
Well, this change seems good enough to me and it avoids the need of adding a separate conf.py.
The only thing that concerns me is if this logic works with all Sphinx versions. I guess it should, but there were some changes in the past with the LaTeX output module which broke on newer versions, as different versions of Sphinx use different .
So, this patch needs to be tested against the minimal version recommended for PDF output (2.4.4) and against the latest one, to be 100% sure that it won't cause any breakages.
You can test it with something like:
$ /usr/bin/python3 -m venv sphinx_foo $ . sphinx_foo/bin/activate $ pip install docutils Sphinx==2.4.4 sphinx_rtd_theme $ make pdfdocs ... # Should install Latest version, e. g. currently, Sphinx 4.0.2 $ pip uninstall Sphinx $ pip install docutils Sphinx sphinx_rtd_theme $ make pdfdocs
(That's said, I didn't test version 4.0 yet... not sure if everything would work fine, even without this change)
Regards,
Mauro
Quoted 42 lines
Quoted 28 lines
Quoted 28 lines
Documentation/translations/index.rst +4
-0@@ -18,6 +18,10 @@ Translations Disclaimer ---------- +.. raw:: latex + + \kerneldocCJKoff + Translation's purpose is to ease reading and understanding in languages other than English. Its aim is to help people who do not understand English or have doubts about its interpretation. Additionally, some people prefer to readDocumentation/translations/it_IT/index.rst +4
-0@@ -4,6 +4,10 @@ Traduzione italiana =================== +.. raw:: latex + + \kerneldocCJKoff + :manutentore: Federico Vaga <[email protected]>Quoted 5 lines
Documentation/translations/it_IT/index.rst line 13
Quoted 1 line
Documentation/translations/it_IT/index.rst +0
-0.. _it_disclaimer:And for above two, maybe better to put "raw:: latex" block above the title, more beautiful, and CJKoff will be done before enter "Italiana" chapter.
These two are placed there intentionally.
As mentioned in the change log:
Quoted 4 lines
Quoted 4 lines
Note: A CJK chapter needs \kerneldocCJKon in front of its chapter heading, while a non-CJK chapter should have \kerneldocCJKoff below its chapter heading.
Quoted 12 lines
Quoted 2 lines
Quoted 2 lines
This is to make sure the CJK font is available to CJK chapter's heading and ending page's footer.
If they are put above chapter titles in the .rst files, Chinese translation's final page's footer won't be rendered properly.
Thanks, Akira
Quoted 4 lines
Thanks,
Wu X.C.
Thanks,
Mauro
Akira Yokosawa
reviewerPATCH v3 1/1 docs: Activate exCJK only in CJK chapters
In reply to Akira YokosawaActivating xeCJK in English and Italian-translation documents results in sub-optimal typesetting with wide-looking apostrophes and quotation marks.
The xeCJK package provides macros for enabling and disabling its effect in the middle of a document, namely \makexeCJKactive and \makexeCJKinactive.
So the goal of this change is to activate xeCJK in the relevant chapters in translations.
To do this:
o Define custom macros in the preamble depending on the availability of the "Noto Sans CJK" font so that those macros can be used regardless of the use of xeCJK package.
o Patch \sphinxtableofcontents so that xeCJK is inactivated after table of contents.
o Embed those custom macros in each language's index.rst file as a ".. raw:: latex" construct.
Note: A CJK chapter needs \kerneldocCJKon in front of its chapter heading, while a non-CJK chapter should have \kerneldocCJKoff below its chapter heading.
This is to make sure the CJK font is available to CJK chapter's heading and ending page's footer.
---
v2 -> v3:
o Fixed trailing white space
o Added Tested-By from Wu XiangCheng
--
Documentation/conf.py | 13 +++++++++++++ Documentation/translations/index.rst | 4 ++++ Documentation/translations/it_IT/index.rst | 4 ++++ Documentation/translations/ja_JP/index.rst | 5 +++-- Documentation/translations/ko_KR/index.rst | 5 +++-- Documentation/translations/zh_CN/index.rst | 1 + 6 files changed, 28 insertions(+), 4 deletions(-)
Documentation/conf.py +13 -0
@@ -371,6 +371,19 @@ if cjk_cmd.find("Noto Sans CJK SC") >= 0: % This is needed for translations \\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'] += ''' + % Custom macros to on/off CJK (Dummy) + \\newcommand{\\kerneldocCJKon}{} + \\newcommand{\\kerneldocCJKoff}{} ''' # Fix reference escape troubles with Sphinx 1.4.x
Documentation/translations/index.rst +4 -0
@@ -18,6 +18,10 @@ Translations Disclaimer ---------- +.. raw:: latex + + \kerneldocCJKoff + Translation's purpose is to ease reading and understanding in languages other than English. Its aim is to help people who do not understand English or have doubts about its interpretation. Additionally, some people prefer to read
Documentation/translations/it_IT/index.rst +4 -0
@@ -4,6 +4,10 @@ Traduzione italiana =================== +.. raw:: latex + + \kerneldocCJKoff + :manutentore: Federico Vaga <[email protected]> .. _it_disclaimer:
Documentation/translations/ja_JP/index.rst +3 -2
@@ -1,7 +1,8 @@ .. raw:: latex - \renewcommand\thesection* - \renewcommand\thesubsection* + \renewcommand\thesection* + \renewcommand\thesubsection* + \kerneldocCJKon Japanese translations =====================
Documentation/translations/ko_KR/index.rst +3 -2
@@ -1,7 +1,8 @@ .. raw:: latex - \renewcommand\thesection* - \renewcommand\thesubsection* + \renewcommand\thesection* + \renewcommand\thesubsection* + \kerneldocCJKon 한국어 번역 ===========
Documentation/translations/zh_CN/index.rst +1 -0
@@ -4,6 +4,7 @@ \renewcommand\thesection* \renewcommand\thesubsection* + \kerneldocCJKon .. _linux_doc_zh:
Signature · 1 line
2.17.1
Akira Yokosawa
reviewerPATCH v4 1/1 docs: Activate exCJK only in CJK chapters
In reply to Akira YokosawaActivating xeCJK in English and Italian-translation documents results in sub-optimal typesetting with wide-looking apostrophes and quotation marks.
The xeCJK package provides macros for enabling and disabling its effect in the middle of a document, namely \makexeCJKactive and \makexeCJKinactive.
So the goal of this change is to activate xeCJK in the relevant chapters in translations.
To do this:
o Define custom macros in the preamble depending on the availability of the "Noto Sans CJK" font so that those macros can be used regardless of the use of xeCJK package.
o Patch \sphinxtableofcontents so that xeCJK is inactivated after table of contents.
o Embed those custom macros in each language's index.rst file as a ".. raw:: latex" construct.
Note: A CJK chapter needs \kerneldocCJKon in front of its chapter heading, while a non-CJK chapter should have \kerneldocCJKoff below its chapter heading.
This is to make sure the CJK font is available to CJK chapter's heading and ending page's footer.
Tested against Sphinx versions 2.4.4 and 4.0.2.
---
v3 -> v4: (Change log update)
o Added Reviewed-by from Mauro
o Added note on Sphinx versions (2.4.4 and 4.0.2) tested against
v2 -> v3:
o Fixed trailing white space
o Added Tested-By from Wu XiangCheng
--
Documentation/conf.py | 13 +++++++++++++ Documentation/translations/index.rst | 4 ++++ Documentation/translations/it_IT/index.rst | 4 ++++ Documentation/translations/ja_JP/index.rst | 5 +++-- Documentation/translations/ko_KR/index.rst | 5 +++-- Documentation/translations/zh_CN/index.rst | 1 + 6 files changed, 28 insertions(+), 4 deletions(-)
Documentation/conf.py +13 -0
@@ -371,6 +371,19 @@ if cjk_cmd.find("Noto Sans CJK SC") >= 0: % This is needed for translations \\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'] += ''' + % Custom macros to on/off CJK (Dummy) + \\newcommand{\\kerneldocCJKon}{} + \\newcommand{\\kerneldocCJKoff}{} ''' # Fix reference escape troubles with Sphinx 1.4.x
Documentation/translations/index.rst +4 -0
@@ -18,6 +18,10 @@ Translations Disclaimer ---------- +.. raw:: latex + + \kerneldocCJKoff + Translation's purpose is to ease reading and understanding in languages other than English. Its aim is to help people who do not understand English or have doubts about its interpretation. Additionally, some people prefer to read
Documentation/translations/it_IT/index.rst +4 -0
@@ -4,6 +4,10 @@ Traduzione italiana =================== +.. raw:: latex + + \kerneldocCJKoff + :manutentore: Federico Vaga <[email protected]> .. _it_disclaimer:
Documentation/translations/ja_JP/index.rst +3 -2
@@ -1,7 +1,8 @@ .. raw:: latex - \renewcommand\thesection* - \renewcommand\thesubsection* + \renewcommand\thesection* + \renewcommand\thesubsection* + \kerneldocCJKon Japanese translations =====================
Documentation/translations/ko_KR/index.rst +3 -2
@@ -1,7 +1,8 @@ .. raw:: latex - \renewcommand\thesection* - \renewcommand\thesubsection* + \renewcommand\thesection* + \renewcommand\thesubsection* + \kerneldocCJKon 한국어 번역 ===========
Documentation/translations/zh_CN/index.rst +1 -0
@@ -4,6 +4,7 @@ \renewcommand\thesection* \renewcommand\thesubsection* + \kerneldocCJKon .. _linux_doc_zh:
Signature · 1 line
2.17.1
Re: [PATCH v4] docs: Activate exCJK only in CJK chapters
Quoted 30 lines · Akira Yokosawa
Activating xeCJK in English and Italian-translation documents results in sub-optimal typesetting with wide-looking apostrophes and quotation marks.
The xeCJK package provides macros for enabling and disabling its effect in the middle of a document, namely \makexeCJKactive and \makexeCJKinactive.
So the goal of this change is to activate xeCJK in the relevant chapters in translations.
To do this:
o Define custom macros in the preamble depending on the availability of the "Noto Sans CJK" font so that those macros can be used regardless of the use of xeCJK package.
o Patch \sphinxtableofcontents so that xeCJK is inactivated after table of contents.
o Embed those custom macros in each language's
index.rstfile as a ".. raw:: latex" construct.Note: A CJK chapter needs \kerneldocCJKon in front of its chapter heading, while a non-CJK chapter should have \kerneldocCJKoff below its chapter heading.
This is to make sure the CJK font is available to CJK chapter's heading and ending page's footer.
Quoted 6 lines
Tested against Sphinx versions 2.4.4 and 4.0.2.
Signed-off-by Akira Yokosawa <[email protected]>Tested-by Wu XiangCheng <[email protected]>Reviewed-by Mauro Carvalho Chehab <[email protected]>
I've applied this, thanks.
jon