Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1041762rwe; Fri, 26 Aug 2022 22:23:28 -0700 (PDT) X-Google-Smtp-Source: AA6agR64mXDhvu2MogBzb77EloMmxs7FqqLcDMzmgnSewrT08MpVSJ3pTxhy/+qgTbQU/ztZ2gUP X-Received: by 2002:a17:907:a06b:b0:73d:dde9:75a7 with SMTP id ia11-20020a170907a06b00b0073ddde975a7mr5064276ejc.52.1661577808544; Fri, 26 Aug 2022 22:23:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661577808; cv=none; d=google.com; s=arc-20160816; b=BikEGoSCcZDHL2LJUbztBnYp+papT0RrEWM4AfsAeETpLJv2rCHgTVMIYavLQ5rjfO qFFMGSsHg/wLnTpemSBZbV51sOmXAToANeCA6SobBHTVZ6OxJwZi6FLAuHWaDY+iE3kx AeOYNTFd7hV2krGjVd0fk62J5/BqqfzF49ucBpGV/HvaYnTn/QWx2d7g/Dq0pgyjW74s NMyHZ3wDbHVE7h88p6dbLZ+fehSiFIhQE90CMyRuWGjr/3Z46Zt2x8mhjocRikLqRSw6 +RjDLgjub6yE7OY3LunAHSbhICY0qxtaS3sqiKo7ps+mrthIKp+tDZFOXJ5mynaZuhFw emCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=IhCtCt7xUVdmEi8KPUgqmHyWKIflwsN7bIzGfwY7bdQ=; b=bfVPe6T+xLLFYZJjWGAA747TcN1hjOuz215x+VOcZJBV/n8rXFKBohWHNz7znfEPgX ahiSDH7GEGBCl3xI6UpX/J3gG57JYqJtFDHOcFOMRTreluf/r9wd0IiglZeeOzGA9QWQ MYfV5Y3635a0rVXstSVM5LsqUNpO45fFc9PsiJ4SvORS5+xP1g0f8VPXT8/7+kXwzINW dwjB7CWiu4YNG7GxcAl3lrcqxDnZxzQarkoici0/vo1duqIWdRXg1VDOkKUjz8aOW+uk SzUWnnDVEWX6rfc8YX9H+8XcLsGQZK4Ys0a99TviHbEODBfXCExFRoDZAibGzO3q5Kt2 0GQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GhjKS05o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ej28-20020a056402369c00b00447fd99f61csi1868134edb.511.2022.08.26.22.23.03; Fri, 26 Aug 2022 22:23:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GhjKS05o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242001AbiH0Eh1 (ORCPT + 99 others); Sat, 27 Aug 2022 00:37:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231216AbiH0EhY (ORCPT ); Sat, 27 Aug 2022 00:37:24 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D5991D333; Fri, 26 Aug 2022 21:37:23 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id 72so3346671pfx.9; Fri, 26 Aug 2022 21:37:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc; bh=IhCtCt7xUVdmEi8KPUgqmHyWKIflwsN7bIzGfwY7bdQ=; b=GhjKS05oVLRs6NiQ5Evb/3S/bSmoXAWHCZylVi4Poux54vSKgLevmdWB6McKCaXO9b 2t2SELt8vH/ki8S4dvp7DwXJDRlzy3EsXW9ozIG/2QZeQT7irAjNbtgZcZnAXi3hSkE4 yL9pimCkFF36aZyBCYsmbkJc/8WPj2tOigpUi7PUPtd0dPbQ79RzJcjXx7WExRdH6bSA Qftlioux7MVpq6I0KmZUPNxqoZI96uv2TA8KPxLfk53jQEl6aXeleX//aYmN7WDWZVvB 3bmeeRq8wooBKUPKAsorB7erhgJZTvt5nmPZa2gUEQ+m6cHpLliKb1ucq2yiqHJUCS3h RdoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc; bh=IhCtCt7xUVdmEi8KPUgqmHyWKIflwsN7bIzGfwY7bdQ=; b=ujoNUjyw5xf3PWIto5BKJS/e0CL6uYBcTExgmZWsWx6x8mL54gzPFfgTHDfjbc/W/o jhRxIKL7MjpqsVhS/HauPf4bb/3JeqFo3Tw4TCpFWEO0nMVGDRYw/n2crHl+gRCEUTPr J5x3N7O1yXB1/unw+amqlyQoeCJFbZixx8G4UiRfgYYnfYoHlR6nNhC1xyDB6gV6Yy59 adIOEyAuPPb0fOJov961JBKrsovvCJxS46TRQx7CQoCBCFU8XsRbJ6prDAHxyqL4oRNT KpaplOENaYrhX6xjsVuGie3h5ApfQW33x1MWSUnX3DuyvDUQj7x3jFJhiz4kCObCK6Q3 Oe2Q== X-Gm-Message-State: ACgBeo2wNkE9qikcH6M3BHSpp5F9RBIxcI1pKSrolkD9Y+kSmbvGrro7 OBsEwcqle0ePXTyQEQFjMiE= X-Received: by 2002:a63:914a:0:b0:42b:4eaf:7c75 with SMTP id l71-20020a63914a000000b0042b4eaf7c75mr5798107pge.306.1661575042929; Fri, 26 Aug 2022 21:37:22 -0700 (PDT) Received: from [192.168.11.9] (KD106167171201.ppp-bb.dion.ne.jp. [106.167.171.201]) by smtp.gmail.com with ESMTPSA id jj22-20020a170903049600b00172dc6e1916sm2451488plb.220.2022.08.26.21.37.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Aug 2022 21:37:20 -0700 (PDT) Message-ID: Date: Sat, 27 Aug 2022 13:37:18 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: [PATCH v3 1/2] docs/conf.py: Treat mathjax as fallback math renderer Content-Language: en-US To: Jonathan Corbet , Mauro Carvalho Chehab Cc: linux-doc@vger.kernel.org, Mauro Carvalho Chehab , linux-kernel@vger.kernel.org, Akira Yokosawa References: <9b8ff6d7-e97a-c03f-7d46-4b80ae3cf196@gmail.com> From: Akira Yokosawa In-Reply-To: <9b8ff6d7-e97a-c03f-7d46-4b80ae3cf196@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. To find out whether required commands are available, add a helper find_command(), which is a wrapper of shutil.which(). For epub docs, keep the same behavior of always loading imgmath. Signed-off-by: Akira Yokosawa Acked-by: Mauro Carvalho Chehab --- Changes since v2: - Mention find_command() in the changelog. - Simplify find_command() by using shutil.which(). Changes sinve v1: - Acked-by from Mauro -- Documentation/conf.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/Documentation/conf.py b/Documentation/conf.py index 255384d094bf..c4aaedd96220 100644 --- a/Documentation/conf.py +++ b/Documentation/conf.py @@ -15,6 +15,18 @@ import sys import os import sphinx +import shutil + +# helper +# ------ + +def have_command(cmd): + """Search ``cmd`` in the ``PATH`` environment. + + If found, return True. + If not found, return False. + """ + return shutil.which(cmd) is not None # Get Sphinx version major, minor, patch = sphinx.version_info[:3] @@ -107,7 +119,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') +have_dvipng = have_command('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