From cc6596c2973edb03c3e907e5555574d6b81123b7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 9 Jul 2025 13:52:25 +0000 Subject: [PATCH 1/3] Initial plan From 5d573257326e2fea2bab056538a2d25349b796fb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 9 Jul 2025 14:01:24 +0000 Subject: [PATCH 2/3] Implement MathJax detection in meson with fallback to CDN Co-authored-by: tobiasdiez <5037600+tobiasdiez@users.noreply.github.com> --- build/pkgs/mathjax/SPKG.rst | 19 -------------- build/pkgs/mathjax/checksums.ini | 3 --- build/pkgs/mathjax/distros/conda.txt | 1 - build/pkgs/mathjax/distros/fedora.txt | 1 - build/pkgs/mathjax/distros/gentoo.txt | 1 - build/pkgs/mathjax/distros/opensuse.txt | 1 - build/pkgs/mathjax/distros/repology.txt | 1 - build/pkgs/mathjax/distros/void.txt | 1 - build/pkgs/mathjax/package-version.txt | 1 - build/pkgs/mathjax/spkg-configure.m4 | 26 ------------------- build/pkgs/mathjax/spkg-install.in | 2 -- build/pkgs/mathjax/spkg-src | 34 ------------------------- build/pkgs/mathjax/type | 1 - meson.build | 33 ++++++++++++++++++++++++ src/sage/env.py | 1 - src/sage_docbuild/conf.py | 10 +++++++- src/sage_docbuild/mathjax_config.py.in | 8 ++++++ 17 files changed, 50 insertions(+), 94 deletions(-) delete mode 100644 build/pkgs/mathjax/SPKG.rst delete mode 100644 build/pkgs/mathjax/checksums.ini delete mode 100644 build/pkgs/mathjax/distros/conda.txt delete mode 100644 build/pkgs/mathjax/distros/fedora.txt delete mode 100644 build/pkgs/mathjax/distros/gentoo.txt delete mode 100644 build/pkgs/mathjax/distros/opensuse.txt delete mode 100644 build/pkgs/mathjax/distros/repology.txt delete mode 100644 build/pkgs/mathjax/distros/void.txt delete mode 100644 build/pkgs/mathjax/package-version.txt delete mode 100644 build/pkgs/mathjax/spkg-configure.m4 delete mode 100644 build/pkgs/mathjax/spkg-install.in delete mode 100755 build/pkgs/mathjax/spkg-src delete mode 100644 build/pkgs/mathjax/type create mode 100644 src/sage_docbuild/mathjax_config.py.in diff --git a/build/pkgs/mathjax/SPKG.rst b/build/pkgs/mathjax/SPKG.rst deleted file mode 100644 index 630198fdeb9..00000000000 --- a/build/pkgs/mathjax/SPKG.rst +++ /dev/null @@ -1,19 +0,0 @@ -mathjax: A JavaScript library for displaying mathematical formulas -================================================================== - -Description ------------ - -MathJax is a JavaScript library for displaying mathematical formulas. - -MathJax is used in the Sage documentation built by Sphinx. - -License -------- - -Apache License, version 2.0 - -Upstream Contact ----------------- - -Home page: https://www.mathjax.org/ diff --git a/build/pkgs/mathjax/checksums.ini b/build/pkgs/mathjax/checksums.ini deleted file mode 100644 index 9be83c3fee4..00000000000 --- a/build/pkgs/mathjax/checksums.ini +++ /dev/null @@ -1,3 +0,0 @@ -tarball=mathjax-VERSION.tar.gz -sha1=3f7abecf8cacd7f5d7f9ae6c3baca7739101c17d -sha256=9b2ed180ff2ddb8d4ea1d00e4d14791320c35496f57073514a129c0c67f7625b diff --git a/build/pkgs/mathjax/distros/conda.txt b/build/pkgs/mathjax/distros/conda.txt deleted file mode 100644 index 37aaaac759c..00000000000 --- a/build/pkgs/mathjax/distros/conda.txt +++ /dev/null @@ -1 +0,0 @@ -mathjax diff --git a/build/pkgs/mathjax/distros/fedora.txt b/build/pkgs/mathjax/distros/fedora.txt deleted file mode 100644 index 9b7fbe7fff9..00000000000 --- a/build/pkgs/mathjax/distros/fedora.txt +++ /dev/null @@ -1 +0,0 @@ -mathjax3 diff --git a/build/pkgs/mathjax/distros/gentoo.txt b/build/pkgs/mathjax/distros/gentoo.txt deleted file mode 100644 index e0d633a9b98..00000000000 --- a/build/pkgs/mathjax/distros/gentoo.txt +++ /dev/null @@ -1 +0,0 @@ ->=dev-libs/mathjax-3 diff --git a/build/pkgs/mathjax/distros/opensuse.txt b/build/pkgs/mathjax/distros/opensuse.txt deleted file mode 100644 index 37aaaac759c..00000000000 --- a/build/pkgs/mathjax/distros/opensuse.txt +++ /dev/null @@ -1 +0,0 @@ -mathjax diff --git a/build/pkgs/mathjax/distros/repology.txt b/build/pkgs/mathjax/distros/repology.txt deleted file mode 100644 index 37aaaac759c..00000000000 --- a/build/pkgs/mathjax/distros/repology.txt +++ /dev/null @@ -1 +0,0 @@ -mathjax diff --git a/build/pkgs/mathjax/distros/void.txt b/build/pkgs/mathjax/distros/void.txt deleted file mode 100644 index 37aaaac759c..00000000000 --- a/build/pkgs/mathjax/distros/void.txt +++ /dev/null @@ -1 +0,0 @@ -mathjax diff --git a/build/pkgs/mathjax/package-version.txt b/build/pkgs/mathjax/package-version.txt deleted file mode 100644 index 944880fa15e..00000000000 --- a/build/pkgs/mathjax/package-version.txt +++ /dev/null @@ -1 +0,0 @@ -3.2.0 diff --git a/build/pkgs/mathjax/spkg-configure.m4 b/build/pkgs/mathjax/spkg-configure.m4 deleted file mode 100644 index 70fb46a2067..00000000000 --- a/build/pkgs/mathjax/spkg-configure.m4 +++ /dev/null @@ -1,26 +0,0 @@ -SAGE_SPKG_CONFIGURE([mathjax], [ - # Arch: /usr/share/mathjax - # Gentoo: /usr/share/mathjax - # Void: /usr/share/mathjax - AC_MSG_CHECKING([for MathJax-3.x]) - m4_foreach([mathjax_dir], [/usr/share/mathjax], [ - # tex-chtml.hs is used in src/sage_docbuild/conf.py - # and was not present in MathJax-2.x - AS_IF([test -f "mathjax_dir/tex-chtml.js"], [ - SAGE_MATHJAX_DIR="mathjax_dir" - AC_MSG_RESULT([mathjax_dir]) - ]) - ]) - AS_IF([test -z "${SAGE_MATHJAX_DIR}"], [ - AC_MSG_RESULT([no]) - sage_spkg_install_mathjax=yes - ]) -],[],[],[ - # post-check - AS_IF([test x$sage_spkg_install_mathjax = xyes], [ - # Our spkg-src script adds an extra "mathjax" - SAGE_MATHJAX_DIR='${prefix}'/share/mathjax/mathjax - ]) - - AC_SUBST(SAGE_MATHJAX_DIR, "${SAGE_MATHJAX_DIR}") -]) diff --git a/build/pkgs/mathjax/spkg-install.in b/build/pkgs/mathjax/spkg-install.in deleted file mode 100644 index 2eeaf6e84b4..00000000000 --- a/build/pkgs/mathjax/spkg-install.in +++ /dev/null @@ -1,2 +0,0 @@ -TARGET="${SAGE_SHARE}/mathjax" -sdh_install src/* "${TARGET}" diff --git a/build/pkgs/mathjax/spkg-src b/build/pkgs/mathjax/spkg-src deleted file mode 100755 index bd7fa941cc9..00000000000 --- a/build/pkgs/mathjax/spkg-src +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash - -set -e - -[ -n "${SAGE_ROOT}" ] || SAGE_ROOT="$(pwd)/../../../" - -# determine the latest version -GIT_VERSION="$(curl https://github.com/mathjax/MathJax/releases | grep 'MathJax v' | head -1 | sed 's|^.*MathJax v||g' | sed 's/\s*$//g')" -echo "GIT_VERSION=$GIT_VERSION" - -# fetch and rename the latest version -URL="https://github.com/mathjax/MathJax/archive/refs/tags/${GIT_VERSION}.zip" -echo "Downloading $URL" -rm -rf src -if [ -z "$UPSTREAM_SOURCE_TARBALL" ]; then - tar xzf <( curl -L "$URL" ) -else - tar xzf "$UPSTREAM_SOURCE_TARBALL" -fi - -# put files under mathjax directory -mkdir src -mv MathJax-${GIT_VERSION}/es5 src/mathjax -rm -r MathJax-${GIT_VERSION} - -PACKAGE_VERSION=${GIT_VERSION} - -# repackage -tar czf "$SAGE_ROOT/upstream/mathjax-${PACKAGE_VERSION}.tar.gz" src -rm -rf src - -# update package info -echo "${PACKAGE_VERSION}" > 'package-version.txt' -"$SAGE_ROOT"/sage --package fix-checksum mathjax diff --git a/build/pkgs/mathjax/type b/build/pkgs/mathjax/type deleted file mode 100644 index a6a7b9cd726..00000000000 --- a/build/pkgs/mathjax/type +++ /dev/null @@ -1 +0,0 @@ -standard diff --git a/meson.build b/meson.build index 13a445376c6..6d9b4d0512b 100755 --- a/meson.build +++ b/meson.build @@ -218,4 +218,37 @@ run_command(create_files_command, check: true) root = meson.current_source_dir() +# MathJax detection logic +# Check for system-wide MathJax installation +mathjax_dir = '' +mathjax_found = false + +# Check common system locations for MathJax +foreach dir : ['/usr/share/mathjax', '/usr/local/share/mathjax'] + if not mathjax_found and fs.is_file(dir / 'tex-chtml.js') + mathjax_dir = dir + mathjax_found = true + message('Found MathJax at: ' + dir) + endif +endforeach + +# If not found, use the bundled/prefix location +if not mathjax_found + mathjax_dir = get_option('prefix') / 'share' / 'mathjax' / 'mathjax' + message('Using bundled MathJax location: ' + mathjax_dir) +endif + +# Generate the configuration template +mathjax_config_data = configuration_data() +mathjax_config_data.set('MATHJAX_DIR', mathjax_dir) + +# Create config file in the build directory +configure_file( + input: 'src/sage_docbuild/mathjax_config.py.in', + output: 'mathjax_config.py', + configuration: mathjax_config_data, + install: true, + install_dir: get_option('prefix') / 'lib' / 'python' + py.language_version() / 'site-packages' / 'sage_docbuild' +) + subdir('src') diff --git a/src/sage/env.py b/src/sage/env.py index 8771f713e26..db0221869c1 100644 --- a/src/sage/env.py +++ b/src/sage/env.py @@ -228,7 +228,6 @@ def var(key: str, *fallbacks: Optional[str], force: bool = False) -> Optional[st # installation directories for various packages JMOL_DIR = var("JMOL_DIR") -MATHJAX_DIR = var("MATHJAX_DIR", join(SAGE_SHARE, "mathjax")) MTXLIB = var("MTXLIB", join(SAGE_SHARE, "meataxe")) THREEJS_DIR = var("THREEJS_DIR") PPLPY_DOCS = var("PPLPY_DOCS", join(SAGE_SHARE, "doc", "pplpy")) diff --git a/src/sage_docbuild/conf.py b/src/sage_docbuild/conf.py index da9da0361ca..dc322b032df 100644 --- a/src/sage_docbuild/conf.py +++ b/src/sage_docbuild/conf.py @@ -28,12 +28,20 @@ from sphinx.util.docutils import SphinxDirective import sage.version -from sage.env import MATHJAX_DIR, PPLPY_DOCS, SAGE_DOC, SAGE_DOC_SRC +from sage.env import PPLPY_DOCS, SAGE_DOC, SAGE_DOC_SRC from sage.features.sphinx import JupyterSphinx from sage.misc.latex_macros import sage_mathjax_macros from sage.misc.sagedoc import extlinks as extlinks # noqa: PLC0414 from sage.misc.sagedoc_conf import * # Load configuration shared with sage.misc.sphinxify +# Import MathJax configuration from the build system +try: + from sage_docbuild.mathjax_config import MATHJAX_DIR +except ImportError: + # Fallback to default location if config file is not available + import os + MATHJAX_DIR = os.path.join(os.environ.get('SAGE_LOCAL', '/usr/local'), 'share', 'mathjax') + # --------------------- # General configuration # --------------------- diff --git a/src/sage_docbuild/mathjax_config.py.in b/src/sage_docbuild/mathjax_config.py.in new file mode 100644 index 00000000000..2e1cb98d943 --- /dev/null +++ b/src/sage_docbuild/mathjax_config.py.in @@ -0,0 +1,8 @@ +# MathJax configuration generated by meson +""" +MathJax configuration for Sage documentation build system. +This file is automatically generated by the meson build system. +""" + +# MathJax directory path determined by meson +MATHJAX_DIR = '@MATHJAX_DIR@' \ No newline at end of file From 9dd0ab8eb37d6221bb2534befead4f5825915c5a Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Fri, 11 Jul 2025 22:55:21 +0200 Subject: [PATCH 3/3] Move mathjax detection to docbuild meson file --- meson.build | 33 -------------------------- src/meson.build | 1 + src/sage_docbuild/conf.py | 10 ++------ src/sage_docbuild/config.py.in | 6 +++++ src/sage_docbuild/mathjax_config.py.in | 8 ------- src/sage_docbuild/meson.build | 21 ++++++++++++++++ 6 files changed, 30 insertions(+), 49 deletions(-) create mode 100644 src/sage_docbuild/config.py.in delete mode 100644 src/sage_docbuild/mathjax_config.py.in create mode 100644 src/sage_docbuild/meson.build diff --git a/meson.build b/meson.build index 6d9b4d0512b..13a445376c6 100755 --- a/meson.build +++ b/meson.build @@ -218,37 +218,4 @@ run_command(create_files_command, check: true) root = meson.current_source_dir() -# MathJax detection logic -# Check for system-wide MathJax installation -mathjax_dir = '' -mathjax_found = false - -# Check common system locations for MathJax -foreach dir : ['/usr/share/mathjax', '/usr/local/share/mathjax'] - if not mathjax_found and fs.is_file(dir / 'tex-chtml.js') - mathjax_dir = dir - mathjax_found = true - message('Found MathJax at: ' + dir) - endif -endforeach - -# If not found, use the bundled/prefix location -if not mathjax_found - mathjax_dir = get_option('prefix') / 'share' / 'mathjax' / 'mathjax' - message('Using bundled MathJax location: ' + mathjax_dir) -endif - -# Generate the configuration template -mathjax_config_data = configuration_data() -mathjax_config_data.set('MATHJAX_DIR', mathjax_dir) - -# Create config file in the build directory -configure_file( - input: 'src/sage_docbuild/mathjax_config.py.in', - output: 'mathjax_config.py', - configuration: mathjax_config_data, - install: true, - install_dir: get_option('prefix') / 'lib' / 'python' + py.language_version() / 'site-packages' / 'sage_docbuild' -) - subdir('src') diff --git a/src/meson.build b/src/meson.build index 335f35d5823..0848e514a10 100644 --- a/src/meson.build +++ b/src/meson.build @@ -238,4 +238,5 @@ src = meson.current_source_dir() # Submodules subdir('sage') +subdir('sage_docbuild') subdir('doc') diff --git a/src/sage_docbuild/conf.py b/src/sage_docbuild/conf.py index dc322b032df..e751432a3a3 100644 --- a/src/sage_docbuild/conf.py +++ b/src/sage_docbuild/conf.py @@ -34,13 +34,7 @@ from sage.misc.sagedoc import extlinks as extlinks # noqa: PLC0414 from sage.misc.sagedoc_conf import * # Load configuration shared with sage.misc.sphinxify -# Import MathJax configuration from the build system -try: - from sage_docbuild.mathjax_config import MATHJAX_DIR -except ImportError: - # Fallback to default location if config file is not available - import os - MATHJAX_DIR = os.path.join(os.environ.get('SAGE_LOCAL', '/usr/local'), 'share', 'mathjax') +from .config import MATHJAX_PATH # --------------------- # General configuration @@ -558,7 +552,7 @@ def linkcode_resolve(domain, info): if os.environ.get('SAGE_USE_CDNS', 'no') == 'yes': mathjax_path = "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js" else: - mathjax_path = os.path.join(MATHJAX_DIR, 'tex-chtml.js') + mathjax_path = MATHJAX_PATH # A list of glob-style patterns that should be excluded when looking for source # files. They are matched against the source file names relative to the diff --git a/src/sage_docbuild/config.py.in b/src/sage_docbuild/config.py.in new file mode 100644 index 00000000000..385455605c8 --- /dev/null +++ b/src/sage_docbuild/config.py.in @@ -0,0 +1,6 @@ +""" +Documentation configuration generated by meson +""" + +# MathJax path +MATHJAX_PATH: str = '@MATHJAX_PATH@' diff --git a/src/sage_docbuild/mathjax_config.py.in b/src/sage_docbuild/mathjax_config.py.in deleted file mode 100644 index 2e1cb98d943..00000000000 --- a/src/sage_docbuild/mathjax_config.py.in +++ /dev/null @@ -1,8 +0,0 @@ -# MathJax configuration generated by meson -""" -MathJax configuration for Sage documentation build system. -This file is automatically generated by the meson build system. -""" - -# MathJax directory path determined by meson -MATHJAX_DIR = '@MATHJAX_DIR@' \ No newline at end of file diff --git a/src/sage_docbuild/meson.build b/src/sage_docbuild/meson.build new file mode 100644 index 00000000000..aa9a3f3846a --- /dev/null +++ b/src/sage_docbuild/meson.build @@ -0,0 +1,21 @@ +# Check for system-wide MathJax installation +mathjax_path = '' +mathjax_found = false +foreach dir : ['/usr/share/mathjax', '/usr/local/share/mathjax'] + if not mathjax_found and fs.is_file(dir / 'tex-chtml.js') + mathjax_path = dir / 'tex-chtml.js' + mathjax_found = true + message('Found MathJax at: ' + dir) + endif +endforeach +if not mathjax_found + mathjax_path = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js' + message('Using CDN MathJax: ' + mathjax_path) +endif +docs_config_data = configuration_data() +docs_config_data.set('MATHJAX_PATH', mathjax_path) +configure_file( + input: 'config.py.in', + output: 'config.py', + configuration: docs_config_data, +)