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

Commit

Permalink
Merge remote-tracking branch 'origin/public/docs/mathjax_ext' into pu…
Browse files Browse the repository at this point in the history
…blic/doctests/furo
  • Loading branch information
tobiasdiez committed Apr 27, 2022
2 parents 541194d + 89ec417 commit b6c595b
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 83 deletions.
12 changes: 3 additions & 9 deletions build/pkgs/mathjax/SPKG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Description

MathJax is a JavaScript library for displaying mathematical formulas.

MathJax is used by the Jupyter notebook and the Sphinx documentation.
MathJax is used by the Sage documentation built by Sphinx.

License
-------
Expand All @@ -22,17 +22,11 @@ Home page: https://www.mathjax.org/
Dependencies
------------

None.
None


Special Update/Build Instructions
---------------------------------

None.
None

Patches
-------

- nopng_config.patch: prevent font warning messages since png files are
removed. See section "Trimming II -- not strictly necessary" of
https://github.com/mathjax/MathJax-docs/wiki/Guide%3A-reducing-size-of-a-mathjax-installation
6 changes: 3 additions & 3 deletions build/pkgs/mathjax/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tarball=mathjax-VERSION.tar.gz
sha1=a1b31066a541167c65d6b43f24f3a06f03760662
md5=02d1067dc06d9ca7d380457a49404766
cksum=1204309472
sha1=3f7abecf8cacd7f5d7f9ae6c3baca7739101c17d
md5=ba1a65ab58aaad6c84f39735c619bc34
cksum=1142131398
2 changes: 1 addition & 1 deletion build/pkgs/mathjax/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.4.p0
3.2.0
88 changes: 48 additions & 40 deletions build/pkgs/mathjax/spkg-src
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,65 @@ set -e

[ -n "${SAGE_ROOT}" ] || SAGE_ROOT="$(pwd)/../../../"


# determine latest version.
GIT_VERSION="$(curl http://docs.mathjax.org/en/latest/installation.html | grep 'Current Version' | sed 's|^.*archive/||g' | sed 's/.zip".*//g')"
# 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 latest version.
URL="https://github.com/mathjax/MathJax/archive/${GIT_VERSION}.zip"
# 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
mv MathJax-${GIT_VERSION} src

# Strip mathjax according to
# https://github.com/mathjax/MathJax-docs/wiki/Guide%3A-reducing-size-of-a-mathjax-installation

# Trimming I -- removing files unnecessary for deployment
FILEDIRS_TO_REMOVE='docs/ test/ unpacked/ .gitignore README-branch.txt README.md bower.json'
for filedir in ${FILEDIRS_TO_REMOVE} ; do
rm -rf "src/${filedir}"
done

# Trimming II -- not strictly necessary (requires the patch nopng_config.patch)
rm -rf 'src/fonts/HTML-CSS/TeX/png/'

# Trimming III -- fonts
FONTS_TO_REMOVE='Asana-Math Gyre-Pagella Gyre-Termes Latin-Modern Neo-Euler'
for font in ${FONTS_TO_REMOVE} ; do
find . -type d -name "${font}" -prune -exec rm -rf {} \;
done

FONT_FORMATS_TO_REMOVE='eot otf svg'
for fontformat in ${FONT_FORMATS_TO_REMOVE} ; do
find . -type d -name "${fontformat}" -prune -exec rm -rf {} \;
done

# Trimming IV -- reducing input and output options
OUTPUT_OPTIONS_TO_REMOVE='NativeMML SVG'
for output in ${OUTPUT_OPTIONS_TO_REMOVE} ; do
rm -rf "src/jax/output/${output}"
done

# repack
tar czf "$SAGE_ROOT/upstream/mathjax-${GIT_VERSION}.tar.gz" src

# Put files under mathjax directory
mkdir src
mv MathJax-${GIT_VERSION}/es5 src/mathjax
rm -r MathJax-${GIT_VERSION}


# The following block of commented-out lines were used to reduce the package
# size of MathJax2. We keep these lines for the future when we will want to
# reuse and rewrite them to remove unnecessary font files from MathJax3.

## Trimming I -- removing files unnecessary for deployment
#FILEDIRS_TO_REMOVE='docs/ test/ unpacked/ .gitignore README-branch.txt README.md bower.json'
#for filedir in ${FILEDIRS_TO_REMOVE} ; do
# rm -rf "src/${filedir}"
#done
#
## Trimming II -- not strictly necessary (requires the patch nopng_config.patch)
#rm -rf 'src/fonts/HTML-CSS/TeX/png/'
#
## Trimming III -- fonts
#FONTS_TO_REMOVE='Asana-Math Gyre-Pagella Gyre-Termes Latin-Modern Neo-Euler'
#for font in ${FONTS_TO_REMOVE} ; do
# find . -type d -name "${font}" -prune -exec rm -rf {} \;
#done
#
#FONT_FORMATS_TO_REMOVE='eot otf svg'
#for fontformat in ${FONT_FORMATS_TO_REMOVE} ; do
# find . -type d -name "${fontformat}" -prune -exec rm -rf {} \;
#done
#
## Trimming IV -- reducing input and output options
#OUTPUT_OPTIONS_TO_REMOVE='NativeMML SVG'
#for output in ${OUTPUT_OPTIONS_TO_REMOVE} ; do
# rm -rf "src/jax/output/${output}"
#done


PACKAGE_VERSION=${GIT_VERSION}

# Repackage.
tar czf "$SAGE_ROOT/upstream/mathjax-${PACKAGE_VERSION}.tar.gz" src
rm -rf src

# update package info
echo "${GIT_VERSION}" > 'package-version.txt'
# Update package info
echo "${PACKAGE_VERSION}" > 'package-version.txt'
"$SAGE_ROOT"/sage --package fix-checksum mathjax


36 changes: 20 additions & 16 deletions src/sage/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sage_docbuild.ext.inventory_builder',
'sage_docbuild.ext.multidocs',
'sage_docbuild.ext.sage_autodoc',
'sphinx.ext.todo',
'sphinx.ext.extlinks',
'IPython.sphinxext.ipython_directive',
'matplotlib.sphinxext.plot_directive',
'jupyter_sphinx']
extensions = [
'sage_docbuild.ext.inventory_builder',
'sage_docbuild.ext.multidocs',
'sage_docbuild.ext.sage_autodoc',
'sphinx.ext.todo',
'sphinx.ext.extlinks',
'sphinx.ext.mathjax',
'IPython.sphinxext.ipython_directive',
'matplotlib.sphinxext.plot_directive',
'jupyter_sphinx',
]

jupyter_execute_default_kernel = 'sagemath'

Expand Down Expand Up @@ -305,16 +308,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_USE_CDNS', 'no') == 'yes':
mathjax_path = "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"
else:
mathjax_path = 'mathjax/tex-chtml.js'
html_common_static_path += [MATHJAX_DIR]

# 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
27 changes: 13 additions & 14 deletions src/sage/misc/latex_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ def produce_latex_macro(name, *sample_args):
INPUT:
- ``name`` - name of macro to be defined, also name of corresponding Sage object
- ``sample_args`` - (optional) sample arguments for this Sage object
- ``name`` -- name of macro to be defined, also name of corresponding Sage object
- ``sample_args`` -- (optional) sample arguments for this Sage object
EXAMPLES::
Expand Down Expand Up @@ -109,7 +110,7 @@ def convert_latex_macro_to_mathjax(macro):
INPUT:
- ``macro`` - LaTeX macro definition
- ``macro`` -- LaTeX macro definition
See the web page
https://docs.mathjax.org/en/latest/input/tex/macros.html for a
Expand All @@ -123,18 +124,18 @@ def convert_latex_macro_to_mathjax(macro):
sage: convert_latex_macro_to_mathjax('\\newcommand{\\GF}[1]{\\Bold{F}_{#1}}')
('GF', ['\\Bold{F}_{#1}', 1])
"""
left_bracket = macro.find("[")
right_bracket = macro.find("[")
left_bracket = macro.find('[')
right_bracket = macro.find('[')
if left_bracket >= 0:
right_bracket = macro.find("]")
right_bracket = macro.find(']')
num_args = int(macro[left_bracket + 1 : right_bracket])
else:
num_args = 0
start_name = macro.find("{") + 1 # add one to go past the backslash
end_name = macro.find("}")
start_name = macro.find('{') + 1 # add one to go past the backslash
end_name = macro.find('}')
name = macro[start_name + 1 : end_name]
start_defn = macro.find("{", end_name)
end_defn = macro.rfind("}")
start_defn = macro.find('{', end_name)
end_defn = macro.rfind('}')
defn = macro[start_defn + 1 : end_defn]
if num_args == 0:
return name, defn
Expand Down Expand Up @@ -197,7 +198,7 @@ def sage_latex_macros():
def sage_mathjax_macros():
r"""
Return Sage's macro definitions for usage with MathJax.
This feeds each item output by :func:`sage_latex_macros` to
:func:`convert_latex_macro_to_mathjax`.
Expand All @@ -207,6 +208,4 @@ def sage_mathjax_macros():
sage: sage_mathjax_macros()
{'Bold': ['\\mathbf{#1}', 1], 'CC': '\\Bold{C}', ...
"""
return dict(
[convert_latex_macro_to_mathjax(m) for m in sage_latex_macros()]
)
return dict(convert_latex_macro_to_mathjax(m) for m in sage_latex_macros())
5 changes: 5 additions & 0 deletions src/sage_docbuild/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,9 @@ def setup_parser():
standard.add_argument("--no-prune-empty-dirs", dest="no_prune_empty_dirs",
action="store_true",
help="do not prune empty directories in the documentation sources")
standard.add_argument("--use-cdns", dest="use_cdns", default=False,
action="store_true",
help="assume internet connection and use CDNs; in particular, use MathJax CDN")
standard.add_argument("-N", "--no-colors", dest="color",
action="store_false",
help="do not color output; does not affect children")
Expand Down Expand Up @@ -1741,6 +1744,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.use_cdns:
os.environ['SAGE_USE_CDNS'] = 'yes'

ABORT_ON_ERROR = not args.keep_going

Expand Down

0 comments on commit b6c595b

Please sign in to comment.