2021-05-22 07:30:17

by Akira Yokosawa

[permalink] [raw]
Subject: [PATCH] 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".


Signed-off-by: Akira Yokosawa <[email protected]>
---
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

diff --git a/Documentation/Makefile b/Documentation/Makefile
index 9c42dde97671..31ca4d268fa0 100644
--- a/Documentation/Makefile
+++ b/Documentation/Makefile
@@ -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)

diff --git a/Documentation/conf.py b/Documentation/conf.py
index 879e86dbea66..b3ab8b6017af 100644
--- a/Documentation/conf.py
+++ b/Documentation/conf.py
@@ -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
diff --git a/Documentation/sphinx/retouch-translations.sh b/Documentation/sphinx/retouch-translations.sh
new file mode 100755
index 000000000000..edbfde42b1a5
--- /dev/null
+++ b/Documentation/sphinx/retouch-translations.sh
@@ -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
--
2.17.1



2021-05-22 16:58:11

by Wu XiangCheng

[permalink] [raw]
Subject: Re: [PATCH] docs: Activate xeCJK only in CJK chapters

On Sat, May 22, 2021 at 04:28:55PM +0900, Akira Yokosawa wrote:
> 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".
>
>
> 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]>

Thanks,
Wu X.C.


Attachments:
(No filename) (1.29 kB)
signature.asc (673.00 B)
Download all attachments

2021-05-22 18:16:58

by Mauro Carvalho Chehab

[permalink] [raw]
Subject: Re: [PATCH] docs: Activate xeCJK only in CJK chapters

Em Sat, 22 May 2021 16:28:55 +0900
Akira Yokosawa <[email protected]> escreveu:

> 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".

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

2021-05-22 23:33:53

by Akira Yokosawa

[permalink] [raw]
Subject: Re: [PATCH] docs: Activate xeCJK only in CJK chapters

On Sat, 22 May 2021 20:14:39 +0200, Mauro Carvalho Chehab wrote:
> Em Sat, 22 May 2021 16:28:55 +0900
> Akira Yokosawa <[email protected]> escreveu:
>
>> 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".
>
> 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.

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
>
> 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
>

2021-05-22 23:37:00

by Akira Yokosawa

[permalink] [raw]
Subject: Re: [PATCH] docs: Activate xeCJK only in CJK chapters

On Sun, 23 May 2021 00:56:06 +0800, Wu X.C. wrote:
> On Sat, May 22, 2021 at 04:28:55PM +0900, Akira Yokosawa wrote:
>> 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".
>>
>>
>> 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

>
> Thanks,
> Wu X.C.
>

2021-05-25 13:40:44

by Akira Yokosawa

[permalink] [raw]
Subject: [PATCH v3] docs: Activate exCJK only in CJK chapters

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.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.

Signed-off-by: Akira Yokosawa <[email protected]>
Tested-by: Wu XiangCheng <[email protected]>
Link: https://lore.kernel.org/lkml/[email protected]
---
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(-)

diff --git a/Documentation/conf.py b/Documentation/conf.py
index 879e86dbea66..25aa00c707b0 100644
--- a/Documentation/conf.py
+++ b/Documentation/conf.py
@@ -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
diff --git a/Documentation/translations/index.rst b/Documentation/translations/index.rst
index e446e5ed00a6..556b050884fc 100644
--- a/Documentation/translations/index.rst
+++ b/Documentation/translations/index.rst
@@ -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
diff --git a/Documentation/translations/it_IT/index.rst b/Documentation/translations/it_IT/index.rst
index bb8fa7346939..e80a3097aa57 100644
--- a/Documentation/translations/it_IT/index.rst
+++ b/Documentation/translations/it_IT/index.rst
@@ -4,6 +4,10 @@
Traduzione italiana
===================

+.. raw:: latex
+
+ \kerneldocCJKoff
+
:manutentore: Federico Vaga <[email protected]>

.. _it_disclaimer:
diff --git a/Documentation/translations/ja_JP/index.rst b/Documentation/translations/ja_JP/index.rst
index 2f91b895e3c2..f94ba62d41c3 100644
--- a/Documentation/translations/ja_JP/index.rst
+++ b/Documentation/translations/ja_JP/index.rst
@@ -1,7 +1,8 @@
.. raw:: latex

- \renewcommand\thesection*
- \renewcommand\thesubsection*
+ \renewcommand\thesection*
+ \renewcommand\thesubsection*
+ \kerneldocCJKon

Japanese translations
=====================
diff --git a/Documentation/translations/ko_KR/index.rst b/Documentation/translations/ko_KR/index.rst
index b9e27d20b039..6ae258118bdf 100644
--- a/Documentation/translations/ko_KR/index.rst
+++ b/Documentation/translations/ko_KR/index.rst
@@ -1,7 +1,8 @@
.. raw:: latex

- \renewcommand\thesection*
- \renewcommand\thesubsection*
+ \renewcommand\thesection*
+ \renewcommand\thesubsection*
+ \kerneldocCJKon

한국어 번역
===========
diff --git a/Documentation/translations/zh_CN/index.rst b/Documentation/translations/zh_CN/index.rst
index a736057da41f..1f953d3439a5 100644
--- a/Documentation/translations/zh_CN/index.rst
+++ b/Documentation/translations/zh_CN/index.rst
@@ -4,6 +4,7 @@

\renewcommand\thesection*
\renewcommand\thesubsection*
+ \kerneldocCJKon

.. _linux_doc_zh:

--
2.17.1



2021-05-25 15:40:34

by Akira Yokosawa

[permalink] [raw]
Subject: [PATCH v2] docs: Activate exCJK only in CJK chapters

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.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.

Signed-off-by: Akira Yokosawa <[email protected]>
---
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(-)

diff --git a/Documentation/conf.py b/Documentation/conf.py
index 879e86dbea66..25aa00c707b0 100644
--- a/Documentation/conf.py
+++ b/Documentation/conf.py
@@ -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
diff --git a/Documentation/translations/index.rst b/Documentation/translations/index.rst
index e446e5ed00a6..f07eb317cfba 100644
--- a/Documentation/translations/index.rst
+++ b/Documentation/translations/index.rst
@@ -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
diff --git a/Documentation/translations/it_IT/index.rst b/Documentation/translations/it_IT/index.rst
index bb8fa7346939..e80a3097aa57 100644
--- a/Documentation/translations/it_IT/index.rst
+++ b/Documentation/translations/it_IT/index.rst
@@ -4,6 +4,10 @@
Traduzione italiana
===================

+.. raw:: latex
+
+ \kerneldocCJKoff
+
:manutentore: Federico Vaga <[email protected]>

.. _it_disclaimer:
diff --git a/Documentation/translations/ja_JP/index.rst b/Documentation/translations/ja_JP/index.rst
index 2f91b895e3c2..f94ba62d41c3 100644
--- a/Documentation/translations/ja_JP/index.rst
+++ b/Documentation/translations/ja_JP/index.rst
@@ -1,7 +1,8 @@
.. raw:: latex

- \renewcommand\thesection*
- \renewcommand\thesubsection*
+ \renewcommand\thesection*
+ \renewcommand\thesubsection*
+ \kerneldocCJKon

Japanese translations
=====================
diff --git a/Documentation/translations/ko_KR/index.rst b/Documentation/translations/ko_KR/index.rst
index b9e27d20b039..6ae258118bdf 100644
--- a/Documentation/translations/ko_KR/index.rst
+++ b/Documentation/translations/ko_KR/index.rst
@@ -1,7 +1,8 @@
.. raw:: latex

- \renewcommand\thesection*
- \renewcommand\thesubsection*
+ \renewcommand\thesection*
+ \renewcommand\thesubsection*
+ \kerneldocCJKon

한국어 번역
===========
diff --git a/Documentation/translations/zh_CN/index.rst b/Documentation/translations/zh_CN/index.rst
index a736057da41f..1f953d3439a5 100644
--- a/Documentation/translations/zh_CN/index.rst
+++ b/Documentation/translations/zh_CN/index.rst
@@ -4,6 +4,7 @@

\renewcommand\thesection*
\renewcommand\thesubsection*
+ \kerneldocCJKon

.. _linux_doc_zh:

--
2.17.1


2021-05-25 20:49:23

by Akira Yokosawa

[permalink] [raw]
Subject: [PATCH v4] docs: Activate exCJK only in CJK chapters

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.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.

Signed-off-by: Akira Yokosawa <[email protected]>
Tested-by: Wu XiangCheng <[email protected]>
Reviewed-by: Mauro Carvalho Chehab <[email protected]>
Link: https://lore.kernel.org/lkml/[email protected]
---
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(-)

diff --git a/Documentation/conf.py b/Documentation/conf.py
index 879e86dbea66..25aa00c707b0 100644
--- a/Documentation/conf.py
+++ b/Documentation/conf.py
@@ -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
diff --git a/Documentation/translations/index.rst b/Documentation/translations/index.rst
index e446e5ed00a6..556b050884fc 100644
--- a/Documentation/translations/index.rst
+++ b/Documentation/translations/index.rst
@@ -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
diff --git a/Documentation/translations/it_IT/index.rst b/Documentation/translations/it_IT/index.rst
index bb8fa7346939..e80a3097aa57 100644
--- a/Documentation/translations/it_IT/index.rst
+++ b/Documentation/translations/it_IT/index.rst
@@ -4,6 +4,10 @@
Traduzione italiana
===================

+.. raw:: latex
+
+ \kerneldocCJKoff
+
:manutentore: Federico Vaga <[email protected]>

.. _it_disclaimer:
diff --git a/Documentation/translations/ja_JP/index.rst b/Documentation/translations/ja_JP/index.rst
index 2f91b895e3c2..f94ba62d41c3 100644
--- a/Documentation/translations/ja_JP/index.rst
+++ b/Documentation/translations/ja_JP/index.rst
@@ -1,7 +1,8 @@
.. raw:: latex

- \renewcommand\thesection*
- \renewcommand\thesubsection*
+ \renewcommand\thesection*
+ \renewcommand\thesubsection*
+ \kerneldocCJKon

Japanese translations
=====================
diff --git a/Documentation/translations/ko_KR/index.rst b/Documentation/translations/ko_KR/index.rst
index b9e27d20b039..6ae258118bdf 100644
--- a/Documentation/translations/ko_KR/index.rst
+++ b/Documentation/translations/ko_KR/index.rst
@@ -1,7 +1,8 @@
.. raw:: latex

- \renewcommand\thesection*
- \renewcommand\thesubsection*
+ \renewcommand\thesection*
+ \renewcommand\thesubsection*
+ \kerneldocCJKon

한국어 번역
===========
diff --git a/Documentation/translations/zh_CN/index.rst b/Documentation/translations/zh_CN/index.rst
index a736057da41f..1f953d3439a5 100644
--- a/Documentation/translations/zh_CN/index.rst
+++ b/Documentation/translations/zh_CN/index.rst
@@ -4,6 +4,7 @@

\renewcommand\thesection*
\renewcommand\thesubsection*
+ \kerneldocCJKon

.. _linux_doc_zh:

--
2.17.1



2021-05-27 17:54:21

by Jonathan Corbet

[permalink] [raw]
Subject: Re: [PATCH v4] docs: Activate exCJK only in CJK chapters

Akira Yokosawa <[email protected]> writes:

> 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.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.
>
> Signed-off-by: Akira Yokosawa <[email protected]>
> Tested-by: Wu XiangCheng <[email protected]>
> Reviewed-by: Mauro Carvalho Chehab <[email protected]>
> Link: https://lore.kernel.org/lkml/[email protected]

I've applied this, thanks.

jon