Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Build doc with mathjax3 (default: offline)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwankyu committed Apr 7, 2022
1 parent 321c8b5 commit 7cc5eb7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
1 change: 0 additions & 1 deletion build/pkgs/mathjax3/spkg-src
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ mkdir src
mv MathJax-${GIT_VERSION}/es5 src/mathjax
rm -r MathJax-${GIT_VERSION}


PACKAGE_VERSION=${GIT_VERSION}

# repack
Expand Down
19 changes: 10 additions & 9 deletions src/sage/docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
import os
import sphinx
from sage.env import SAGE_DOC_SRC, SAGE_DOC, THEBE_DIR, PPLPY_DOCS, MATHJAX_DIR
from sage.env import SAGE_SHARE, SAGE_DOC_SRC, SAGE_DOC, THEBE_DIR, PPLPY_DOCS
from sage.misc.latex_macros import sage_mathjax_macros
import sage.version
from sage.misc.sagedoc import extlinks
Expand Down Expand Up @@ -284,16 +284,17 @@ def set_intersphinx_mappings(app, config):
"autoload": {"color": [], "colorv2": ["color"]},
},
}
mathjax_path = "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"

mathjax_relative = os.path.basename(MATHJAX_DIR)
if os.environ.get('SAGE_OFFLINE_DOC', 'no') == 'yes':
mathjax_path = 'mathjax/tex-chtml.js'
html_common_static_path += [os.path.join(SAGE_SHARE, 'mathjax3')]
else:
mathjax_path = "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"

# It would be really nice if sphinx would copy the entire mathjax
# directory, (so we could have a _static/mathjax directory), rather than
# the contents of the directory
html_common_static_path.append(MATHJAX_DIR)
exclude_patterns += ['**/' + os.path.join(mathjax_relative, i)
for i in ('docs', 'README*', 'test', 'unpacked', 'LICENSE')]
# 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
# source directory, using slashes as directory separators on all platforms.
exclude_patterns = []

# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def var(key: str, *fallbacks: Optional[str], force: bool = False) -> Optional[st
CREMONA_MINI_DATA_DIR = var("CREMONA_MINI_DATA_DIR", join(SAGE_SHARE, "cremona"))
CREMONA_LARGE_DATA_DIR = var("CREMONA_LARGE_DATA_DIR", join(SAGE_SHARE, "cremona"))
JMOL_DIR = var("JMOL_DIR", join(SAGE_SHARE, "jmol"))
MATHJAX_DIR = var("MATHJAX_DIR", join(SAGE_SHARE, "mathjax"))
MATHJAX_DIR = var("MATHJAX_DIR", join(SAGE_SHARE, "mathjax3"))
MTXLIB = var("MTXLIB", join(SAGE_SHARE, "meataxe"))
THREEJS_DIR = var("THREEJS_DIR", join(SAGE_SHARE, "threejs-sage"))
PPLPY_DOCS = var("PPLPY_DOCS", join(SAGE_SHARE, "doc", "pplpy"))
Expand Down
13 changes: 12 additions & 1 deletion src/sage_docbuild/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@
import time
import types
import warnings
from pathlib import Path

import sphinx.util.console
import sphinx.ext.intersphinx

import sage.all
from sage.misc.cachefunc import cached_method
# Do not import SAGE_DOC globally as it interferes with doctesting with a random replacement
from sage.env import SAGE_DOC_SRC, SAGE_SRC, DOT_SAGE
from sage.env import SAGE_SHARE, SAGE_DOC_SRC, SAGE_SRC, DOT_SAGE

from .build_options import (LANGUAGES, SPHINXOPTS, OMIT,
ALLSPHINXOPTS, NUM_THREADS, WEBSITESPHINXOPTS,
Expand Down Expand Up @@ -153,6 +154,11 @@ def f(self, *args, **kwds):
if ABORT_ON_ERROR:
raise Exception("Non-exception during docbuild: %s" % (e,), e)

# if type == 'html' and os.environ.get('SAGE_OFFLINE_DOC', 'no') == 'yes':
# if Path(self.dir).parent.parent.name == 'doc':
# logger.warning("Copying mathjax files...")
# shutil.copytree(os.path.join(SAGE_SHARE, 'mathjax3'), output_dir)

if "/latex" in output_dir:
logger.warning("LaTeX file written to {}".format(output_dir))
else:
Expand Down Expand Up @@ -1576,6 +1582,9 @@ def setup_parser():
standard.add_argument("-N", "--no-colors", dest="color",
action="store_false",
help="do not color output; does not affect children")
standard.add_argument("--offline-doc", dest="offline_doc", default=True,
action="store_true",
help="do not assume internet connection; in particular, do not use MathJax CDN")
standard.add_argument("-q", "--quiet", dest="verbose",
action="store_const", const=0,
help="work quietly; same as --verbose=0")
Expand Down Expand Up @@ -1741,6 +1750,8 @@ def excepthook(*exc_info):
os.environ['SAGE_SKIP_PLOT_DIRECTIVE'] = 'yes'
if args.skip_tests:
os.environ['SAGE_SKIP_TESTS_BLOCKS'] = 'True'
if args.offline_doc:
os.environ['SAGE_OFFLINE_DOC'] = 'yes'

ABORT_ON_ERROR = not args.keep_going

Expand Down

0 comments on commit 7cc5eb7

Please sign in to comment.