All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] docs: conf.py: Reduce texlive dependency
@ 2022-08-05 14:21 Akira Yokosawa
  2022-08-05 14:22 ` [PATCH 1/3] docs/conf.py: Treat mathjax as fallback math renderer Akira Yokosawa
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Akira Yokosawa @ 2022-08-05 14:21 UTC (permalink / raw)
  To: Jonathan Corbet, Mauro Carvalho Chehab
  Cc: Linux Doc Mailing List, Mauro Carvalho Chehab, LKML, Akira Yokosawa

This was inspired from the discussion on the expected behavior of
sphinx-pre-install [1].

There was a mismatch between Mauro's intent and my expectation for
the --no-pdf option of sphinx-pre-install.

My thought was if I installed all the packages suggested from
"./scripts/sphinx-pre-install --no-pdf", "make htmldocs" should run
free of complaints of missing commands or packages.

However, I got this warning when I tried the procedure on a debian-
based container image:

    WARNING: LaTeX command 'latex' cannot be run (needed for math display),
    check the imgmath_latex setting

, or:

    WARNING: dvipng command 'dvipng' cannot be run (needed for math display),
    check the imgmath_dvipng setting

Mauro's response to my complaint was this:

> The idea of using --no-pdf is to setup an environment without LaTeX,
> meaning that math tags would only be partially parsed: basically, the
> output would be html with LaTeX-like math expressions (at least last
> time I tried).

The mismatch can be resolved by using "mathjax" for math rendering
and making "make htmldocs" be free of texlive packages.

mathjax is the default math renderer since Sphinx 1.8.  It delegates
math rendering to web browsers.  

As Mauro has pointed out, "make epubdocs" requires imgmath.

So this patch set treats mathjax as a fallback math renderer for html
docs when imgmath requirements are not met.
Existing systems which meet imgmath requirements are not affected by
this change.

Summary of math rendering in html:

         dvipng, browser             before           after
    ==========================  ===============  ================
    dvipng                      imgmath (png)    <--
    no divpng, with javascript  raw math:: code  mathjax
    no dvipng, w/o javascript   raw math:: code  raw mathjax code

Patch 1/3 adds code in conf.py so that for html docs, the imgmath
extension will be loaded only when both latex and dvipng are available.
For epub docs, imgmath will always be loaded (no change).

Patch 2/3 adds code respecting a new env variable "LOAD_IMGMATH" which
will override the math renderer choice. This variable can be helpful
on distros such as Arch linux, Mageia, etc. whose packaging policy is
coarse-grained.

E.g., to test math rendering by mathjax, run:
    make LOAD_IMGMATH=no htmldocs

I mentioned in the thread of [1] that imgmath can generate scalable
math images in SVG.

My plan was to implement that option as well.  But during tests under
Fedora/CentOS/openSUSE, I encountered a couple of warnings from dvisvgm.
That would be regressions on existing systems which happen to have
not-working dvisvgm along with working dvipng.  I'm thinking of adding
the SVG option later if I can figure out the minimal requirement for
dvisvgm under imgmath.

Patch 3/3 is an independent change in the LaTeX preamble for pdf docs.
Currently, xeCJK.sty provided for RHEL 9 (and its clones) is broken
due to the lack of new dependency.  As a workaround, treat the absence
of xeCJK.sty as the additional knob for skipping CJK contents.

Note: Generated LaTeX sources will be the same regardless of existence
of the "Noto Sans CJK SC" font and xeCJK.sty.

[1]: https://lore.kernel.org/r/3ba5a52e-cab6-05cf-a66e-adc58c467e1f@gmail.com/

        Thanks, Akira
--
Akira Yokosawa (3):
  docs/conf.py: Treat mathjax as fallback math renderer
  docs/conf.py: Respect env variable LOAD_IMGMATH
  docs: kerneldoc-preamble: Test xeCJK.sty before loading

 Documentation/conf.py                       | 46 ++++++++++++++++++++-
 Documentation/sphinx/kerneldoc-preamble.sty | 22 +++++++---
 2 files changed, 61 insertions(+), 7 deletions(-)


base-commit: 339170d8d3da5685762619080263abb78700ab4c
-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] docs/conf.py: Treat mathjax as fallback math renderer
  2022-08-05 14:21 [PATCH 0/3] docs: conf.py: Reduce texlive dependency Akira Yokosawa
@ 2022-08-05 14:22 ` Akira Yokosawa
  2022-08-05 14:24 ` [PATCH 2/3] docs/conf.py: Respect env variable LOAD_IMGMATH Akira Yokosawa
  2022-08-05 14:26 ` [PATCH 3/3] docs: kerneldoc-preamble: Test xeCJK.sty before loading Akira Yokosawa
  2 siblings, 0 replies; 5+ messages in thread
From: Akira Yokosawa @ 2022-08-05 14:22 UTC (permalink / raw)
  To: Jonathan Corbet, Mauro Carvalho Chehab
  Cc: Linux Doc Mailing List, Mauro Carvalho Chehab, LKML, Akira Yokosawa

Currently, math expressions using the "math::" directive or
the ":math:" role of Sphinx need the imgmath extension for proper
rendering in html and epub builds.
imgmath requires dvipng (and latex).
Otherwise, "make htmldocs" will complain of missing commands.

As a matter of fact, the mathjax extension is loaded by default since
Sphinx v1.8 and it is good enough for html docs without any dependency
on texlive packages.

Stop loading the imgmath extension for html docs unless requirements
for imgmath are met.

For epub docs, keep the same behavior of always loading imgmath.

Signed-off-by: Akira Yokosawa <akiyks@gmail.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
---
 Documentation/conf.py | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/Documentation/conf.py b/Documentation/conf.py
index 934727e23e0e..3ec1f845c839 100644
--- a/Documentation/conf.py
+++ b/Documentation/conf.py
@@ -15,6 +15,23 @@
 import sys
 import os
 import sphinx
+from subprocess import check_output
+
+# helper
+# ------
+
+def have_command(cmd, ver_opt, str_in_ver):
+    """Run ```cmd`` with ``ver_opt`` and see if ``str_in_ver`` is found
+    or not.
+    """
+
+    try:
+        ver_str = check_output([cmd, ver_opt]).decode('utf-8', 'ignore')
+        have_cmd = str_in_ver in ver_str
+    except:
+        have_cmd = False
+
+    return have_cmd
 
 # Get Sphinx version
 major, minor, patch = sphinx.version_info[:3]
@@ -106,7 +123,22 @@ else:
 autosectionlabel_prefix_document = True
 autosectionlabel_maxdepth = 2
 
-extensions.append("sphinx.ext.imgmath")
+# Load math renderer:
+# For html builder, load imgmath only when its dependencies are met.
+# mathjax is the default math renderer since Sphinx 1.8.
+have_latex =  have_command('latex', '--version', 'pdfTeX')
+have_dvipng = have_command('dvipng', '--version', 'dvipng')
+load_imgmath = ((have_latex and have_dvipng)
+                or (major == 1 and minor < 8)
+                or 'epub' in sys.argv)
+
+if load_imgmath:
+    extensions.append("sphinx.ext.imgmath")
+    math_renderer = 'imgmath'
+else:
+    math_renderer = 'mathjax'
+
+sys.stderr.write("math_renderer: %s\n" % math_renderer)
 
 # Add any paths that contain templates here, relative to this directory.
 templates_path = ['_templates']
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] docs/conf.py: Respect env variable LOAD_IMGMATH
  2022-08-05 14:21 [PATCH 0/3] docs: conf.py: Reduce texlive dependency Akira Yokosawa
  2022-08-05 14:22 ` [PATCH 1/3] docs/conf.py: Treat mathjax as fallback math renderer Akira Yokosawa
@ 2022-08-05 14:24 ` Akira Yokosawa
  2022-08-05 20:35   ` Mauro Carvalho Chehab
  2022-08-05 14:26 ` [PATCH 3/3] docs: kerneldoc-preamble: Test xeCJK.sty before loading Akira Yokosawa
  2 siblings, 1 reply; 5+ messages in thread
From: Akira Yokosawa @ 2022-08-05 14:24 UTC (permalink / raw)
  To: Jonathan Corbet, Mauro Carvalho Chehab
  Cc: Linux Doc Mailing List, Mauro Carvalho Chehab, LKML, Akira Yokosawa

On some distros with coarse-grained packaging policy, dvipng is
installed along with latex.  In such cases, math rendering will
use imgmath by default.  It is possible to override the choice by
specifying the option string of "-D html_math_renderer='mathjax'"
to sphinx-build (Sphinx >= 1.8).

To provide developers an easier-to-use knob, add code for an env
variable "LOAD_IMGMATH" which overrides the automatic choice
of math renderer for html docs.

    LOAD_IMGMATH=yes : Load imgmath even if dvipng is not found
    LOAD_IMGMATH=no  : Don't load imgmath (fall back to mathjax)

Signed-off-by: Akira Yokosawa <akiyks@gmail.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
---
 Documentation/conf.py | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/Documentation/conf.py b/Documentation/conf.py
index 3ec1f845c839..03613eb59578 100644
--- a/Documentation/conf.py
+++ b/Documentation/conf.py
@@ -128,8 +128,20 @@ autosectionlabel_maxdepth = 2
 # mathjax is the default math renderer since Sphinx 1.8.
 have_latex =  have_command('latex', '--version', 'pdfTeX')
 have_dvipng = have_command('dvipng', '--version', 'dvipng')
-load_imgmath = ((have_latex and have_dvipng)
-                or (major == 1 and minor < 8)
+load_imgmath = have_latex and have_dvipng
+
+# Respect LOAD_IMGMATH (for html docs only)
+if 'LOAD_IMGMATH' in os.environ:
+    opt_load_imgmath = os.environ['LOAD_IMGMATH']
+    if 'yes' in opt_load_imgmath:
+        load_imgmath = True
+    elif 'no' in opt_load_imgmath:
+        load_imgmath = False
+    else: # otherwide, auto selection
+        pass
+
+# Always load imgmath for Sphinx <1.8 or for epub docs
+load_imgmath = (load_imgmath or (major == 1 and minor < 8)
                 or 'epub' in sys.argv)
 
 if load_imgmath:
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] docs: kerneldoc-preamble: Test xeCJK.sty before loading
  2022-08-05 14:21 [PATCH 0/3] docs: conf.py: Reduce texlive dependency Akira Yokosawa
  2022-08-05 14:22 ` [PATCH 1/3] docs/conf.py: Treat mathjax as fallback math renderer Akira Yokosawa
  2022-08-05 14:24 ` [PATCH 2/3] docs/conf.py: Respect env variable LOAD_IMGMATH Akira Yokosawa
@ 2022-08-05 14:26 ` Akira Yokosawa
  2 siblings, 0 replies; 5+ messages in thread
From: Akira Yokosawa @ 2022-08-05 14:26 UTC (permalink / raw)
  To: Jonathan Corbet, Mauro Carvalho Chehab
  Cc: Linux Doc Mailing List, Mauro Carvalho Chehab, LKML, Akira Yokosawa

On distros whose texlive packaging is fine-grained, texlive-xecjk
can be installed/removed independently of other texlive packages.
Conditionally loading xeCJK.sty depending only on the existence of
the "Noto Sans CJK SC" font might end up in xelatex error of
"xeCJK.sty not found!".

Improve the situation by testing existence of xeCJK.sty before
loading it.

This is useful on RHEL 9 and its clone distros where texlive-xecjk
doesn't work at the moment due to the missing dependency [1].
"make pdfdocs" for non-CJK contents should work after removing
texlive-xecjk.

Link: [1] https://bugzilla.redhat.com/show_bug.cgi?id=2086254
Signed-off-by: Akira Yokosawa <akiyks@gmail.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
---
 Documentation/sphinx/kerneldoc-preamble.sty | 22 +++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/Documentation/sphinx/kerneldoc-preamble.sty b/Documentation/sphinx/kerneldoc-preamble.sty
index 2a29cbe51396..9707e033c8c4 100644
--- a/Documentation/sphinx/kerneldoc-preamble.sty
+++ b/Documentation/sphinx/kerneldoc-preamble.sty
@@ -70,8 +70,16 @@
 
 % 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}{
-    % Load xeCJK when CJK font is available
+    \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.
@@ -196,7 +204,7 @@
     % Inactivate CJK after tableofcontents
     \apptocmd{\sphinxtableofcontents}{\kerneldocCJKoff}{}{}
     \xeCJKsetup{CJKspace = true}% For inter-phrase space of Korean TOC
-}{ % No CJK font found
+}{ % Don't enable CJK
     % Custom macros to on/off CJK and switch CJK fonts (Dummy)
     \newcommand{\kerneldocCJKon}{}
     \newcommand{\kerneldocCJKoff}{}
@@ -204,14 +212,16 @@
     %% 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 in place of zh_CN translation.
-	\begin{sphinxadmonition}{note}{Note on missing fonts:}
+	%% 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.
+	    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
-	    by following instructions from
+	    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.
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/3] docs/conf.py: Respect env variable LOAD_IMGMATH
  2022-08-05 14:24 ` [PATCH 2/3] docs/conf.py: Respect env variable LOAD_IMGMATH Akira Yokosawa
@ 2022-08-05 20:35   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 5+ messages in thread
From: Mauro Carvalho Chehab @ 2022-08-05 20:35 UTC (permalink / raw)
  To: Akira Yokosawa
  Cc: Jonathan Corbet, Linux Doc Mailing List, Mauro Carvalho Chehab, LKML

Em Fri, 5 Aug 2022 23:24:46 +0900
Akira Yokosawa <akiyks@gmail.com> escreveu:

> On some distros with coarse-grained packaging policy, dvipng is
> installed along with latex.  In such cases, math rendering will
> use imgmath by default.  It is possible to override the choice by
> specifying the option string of "-D html_math_renderer='mathjax'"
> to sphinx-build (Sphinx >= 1.8).
> 
> To provide developers an easier-to-use knob, add code for an env
> variable "LOAD_IMGMATH" which overrides the automatic choice
> of math renderer for html docs.
> 
>     LOAD_IMGMATH=yes : Load imgmath even if dvipng is not found
>     LOAD_IMGMATH=no  : Don't load imgmath (fall back to mathjax)

I would use a var name starting with SPHINX, like SPHINX_IMGMATH.

Anyway, for this entire series:

Acked-by: Mauro Carvalho Chehab <mchehab@kernel.org>

> 
> Signed-off-by: Akira Yokosawa <akiyks@gmail.com>
> Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
> ---
>  Documentation/conf.py | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/conf.py b/Documentation/conf.py
> index 3ec1f845c839..03613eb59578 100644
> --- a/Documentation/conf.py
> +++ b/Documentation/conf.py
> @@ -128,8 +128,20 @@ autosectionlabel_maxdepth = 2
>  # mathjax is the default math renderer since Sphinx 1.8.
>  have_latex =  have_command('latex', '--version', 'pdfTeX')
>  have_dvipng = have_command('dvipng', '--version', 'dvipng')
> -load_imgmath = ((have_latex and have_dvipng)
> -                or (major == 1 and minor < 8)
> +load_imgmath = have_latex and have_dvipng
> +
> +# Respect LOAD_IMGMATH (for html docs only)
> +if 'LOAD_IMGMATH' in os.environ:
> +    opt_load_imgmath = os.environ['LOAD_IMGMATH']
> +    if 'yes' in opt_load_imgmath:
> +        load_imgmath = True
> +    elif 'no' in opt_load_imgmath:
> +        load_imgmath = False
> +    else: # otherwide, auto selection
> +        pass
> +
> +# Always load imgmath for Sphinx <1.8 or for epub docs
> +load_imgmath = (load_imgmath or (major == 1 and minor < 8)
>                  or 'epub' in sys.argv)
>  
>  if load_imgmath:



Thanks,
Mauro

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-08-05 20:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-05 14:21 [PATCH 0/3] docs: conf.py: Reduce texlive dependency Akira Yokosawa
2022-08-05 14:22 ` [PATCH 1/3] docs/conf.py: Treat mathjax as fallback math renderer Akira Yokosawa
2022-08-05 14:24 ` [PATCH 2/3] docs/conf.py: Respect env variable LOAD_IMGMATH Akira Yokosawa
2022-08-05 20:35   ` Mauro Carvalho Chehab
2022-08-05 14:26 ` [PATCH 3/3] docs: kerneldoc-preamble: Test xeCJK.sty before loading Akira Yokosawa

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.