Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3387996rwe; Mon, 29 Aug 2022 10:39:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR5XzGC/9RojNeSAyN+n/qDjQ1iv6OTof5WBxnsEKfb8jl+MGB0+eeg1Aii1uPV/DQH1Y6f5 X-Received: by 2002:a17:906:53ca:b0:73a:7443:7c42 with SMTP id p10-20020a17090653ca00b0073a74437c42mr13864374ejo.761.1661794784794; Mon, 29 Aug 2022 10:39:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661794784; cv=none; d=google.com; s=arc-20160816; b=eMCfBwlct+mAhupIRJ91tANHPCbS3FFUQR1Qbze1fmNGtPHU7jLJzVQ7MKMZVaSazC M4DpVlmi/+jyVBCVkPrxx5RebOrCSlDg6kytt9/nTnI8VJeJawbq0tbxXXAXcXPIcpGE yeHTE8THPhYGNi9rvTRddH8+/523Cd3EUfdvVFLXG+rQyQYMSNRnKrPqs3iRHeJ0HTJj HJpdbBMwl/hqjrpJhFeitH7R59lTt0cMQDEwAXm+axevUT2zwUYQNCQF5iEzvy+sf3z+ 7++V2UrGSoS7JWVzPJC32U5Q0LhdmX0zJ0RMhjJj1sQ6Ag0rs8GJ+YC9NW6DNTFcvu1B 37VA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature:dkim-filter; bh=KVB/dfI17sai5/pehF9fzhRTupEe9KHezPY2ahrCIbw=; b=T/9fGNwk2FrIQCUkgCg6x/lOpNItbCLJYCHdnjZl1jcbb21+Jap8qQ6DG38eED7N/e bRiB8loWLs8mDV74riScCTCK6HKuGMpTMt//u2onyUjTgSMLf2WbXVIqT8y/Tj712WMN 1llMfbMZCdXxuBNR+WhevgnQX6YAkJWrpLs1GKNkVZe10ZMjFIxD8PE2DXxx+9HzIzDS rD2TSHxHwme1GdaaiX886xoVkgNAV5LlVBPDTHasWRTVPy2wgI0oCcGMihqQN8tpZXZO 1jeEvdZv7EvaFJ8YkC6O0xv+3KBtpaI17iPBGpwnzQG3XOXiVx9bQy3tDdo6/H16+4pq o18g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lwn.net header.s=20201203 header.b=QwTgRXzd; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eb10-20020a0564020d0a00b00446273b0d6asi8133002edb.572.2022.08.29.10.39.18; Mon, 29 Aug 2022 10:39:44 -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=@lwn.net header.s=20201203 header.b=QwTgRXzd; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231206AbiH2Q71 (ORCPT + 99 others); Mon, 29 Aug 2022 12:59:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231202AbiH2Q7J (ORCPT ); Mon, 29 Aug 2022 12:59:09 -0400 Received: from ms.lwn.net (ms.lwn.net [45.79.88.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FD7C9C216; Mon, 29 Aug 2022 09:59:03 -0700 (PDT) Received: from localhost (unknown [IPv6:2601:281:8300:73:8b7:7001:c8aa:b65f]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ms.lwn.net (Postfix) with ESMTPSA id B35244B7; Mon, 29 Aug 2022 16:59:02 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 ms.lwn.net B35244B7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lwn.net; s=20201203; t=1661792342; bh=KVB/dfI17sai5/pehF9fzhRTupEe9KHezPY2ahrCIbw=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=QwTgRXzdYlLH5j0A2Em9SIf1KJoja/q2AcPXbQqdwS5M6SHBV5RUm6C7UdkGFLDJX ohAMJFbG9mdKOmMOtSjw/JbNNlI3R36d54X6coH4bUZklfobNAXEicoDdW5D3t2vo1 ZQQDcWvDmi3aX4Bw/+AaS8LUdskyqRv3KlC+gATKuH96YLy4PTUcBhlg1jMJoScf0c e7uN4dhtLmB+Q3FIpFN54J+jTAKV/SrTwnANoHohsxTBqB+lmQ6ZgJ+Ax/q/c32XiB RQlKber4hPQNkck1dD2FG2oGXf9GxgI7enHtTCfHZtxaSlRm6JeLmUaKWyWdiR4KQY /Y8R4BLBOiPYw== From: Jonathan Corbet To: Akira Yokosawa , Mauro Carvalho Chehab Cc: linux-doc@vger.kernel.org, Mauro Carvalho Chehab , linux-kernel@vger.kernel.org, Akira Yokosawa Subject: Re: [PATCH v3 1/2] docs/conf.py: Treat mathjax as fallback math renderer In-Reply-To: References: <9b8ff6d7-e97a-c03f-7d46-4b80ae3cf196@gmail.com> Date: Mon, 29 Aug 2022 10:59:02 -0600 Message-ID: <87edwzoujt.fsf@meer.lwn.net> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 Akira Yokosawa writes: > 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) I've taken this line out as I applied the patch. The docs build is verbose enough as it is, and this line isn't really going to add anything for most people. If it needs to be there, I think, it should only show up on a V=1 build. Thanks, jon