Skip to content

Commit 3650864

Browse files
committed
Add font information to hosting page
1 parent d564220 commit 3650864

File tree

1 file changed

+119
-2
lines changed

1 file changed

+119
-2
lines changed

web/hosting.rst

Lines changed: 119 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ or something like ``assets/mathjax`` in your application directory.
164164

165165
.. _link-files:
166166

167-
Linking to you Your Copy of MathJax
168-
===================================
167+
Linking to Your Copy of MathJax
168+
===============================
169169

170170
You can include MathJax in your web page by putting
171171

@@ -204,6 +204,72 @@ to load MathJax in your page. For example, your page could look like
204204

205205
-----
206206

207+
.. _obtaining-fonts:
208+
209+
Obtaining the Needed Fonts
210+
==========================
211+
212+
In version 3, there was only one font (``mathjax-tex``) and it was
213+
bundled with MathJax itself, so there when you installed MathJax, you
214+
also git that font. That is no longer the case with version 4, since
215+
there is a choice of fonts, and they are made available in separate
216+
pacakges. Installing MathJax via ``npm`` or ``pnpm`` will get you the
217+
default ``mathjax-mnewcm`` font, but if you plan to use a different
218+
font and have that served from your server, you will need to load its
219+
font package as well. E.g.,
220+
221+
.. code-block:: shell
222+
223+
pnpm install @mathjax/mathjax-stix2-font@4
224+
225+
to install the `mathjax-stix2` font.
226+
227+
You will need to move the ``node_modules/@mathjax/mathjax-stix2-font``
228+
directory to a suitable location on your server, as you have the
229+
MathJax files themselves.
230+
231+
In order to use the font you have loaded, you will need to configure
232+
MathJax to tell it the font you need, and where the font fils are
233+
located on your server. For example:
234+
235+
.. code-block:: js
236+
237+
MathJax = {
238+
output: {
239+
font: 'mathjax-stix2',
240+
fontPath: '<path-to-mathjax-stix2-font>',
241+
}
242+
};
243+
244+
where ``<path-to-mathjax-stix2-font>`` is the URL for where you have
245+
places the ``@mathjax/mathjax-stix2-font`` folder.
246+
247+
In this case, your page might look like
248+
249+
.. code-block:: html
250+
251+
<!DOCTYPE html>
252+
<html>
253+
<head>
254+
...
255+
<script>
256+
MathJax = {
257+
output: {
258+
font: 'mathjax-stix2',
259+
fontPath: '/mathjax-strix2-font',
260+
}
261+
};
262+
</script>
263+
<script defer src="/mathjax/tex-chtml.js"></script>
264+
</head>
265+
<body>
266+
...
267+
</body>
268+
</html>
269+
270+
271+
_____
272+
207273
.. _same-origin-policy:
208274

209275
Fonts on Shared Servers
@@ -274,4 +340,55 @@ For web servers other than Apache, you will need to consult the
274340
server's documentation to determine how to specify the needed header
275341
line for fonts on your system.
276342

343+
-----
344+
345+
.. _using-locally:
346+
347+
Using MathJax Locally
348+
=====================
349+
350+
You can use MathJax locally without a connection to the internet by
351+
following the basic outline above, and using ``file://`` URLs to
352+
access your local files. Note, however, that some browsers have
353+
additional cross-origin restrictions for ``file://`` URLs, and that
354+
may limit where you can place the MathJax files and font files.
355+
356+
In that case, you may need to run a local webserver for MathJax and
357+
its files. For example, if you have ``python`` installed, and have
358+
placed the ``mathjax`` and ``mathjax-newcm-font`` files in a directory
359+
called ``assets``, then if do
360+
361+
.. code-block:: shell
362+
363+
cd assets
364+
python -M http.server 8000
365+
366+
and configure your page like
367+
368+
.. code-block:: html
369+
370+
<!DOCTYPE html>
371+
<html>
372+
<head>
373+
...
374+
<script>
375+
MathJax = {
376+
output: {
377+
font: 'mathjax-stix2',
378+
fontPath: 'http://localhost:8000/mathjax-strix2-font',
379+
}
380+
};
381+
</script>
382+
<script defer src="http://localhost:8000/mathjax/tex-chtml.js"></script>
383+
</head>
384+
<body>
385+
...
386+
</body>
387+
</html>
388+
389+
then you should be able to load this file using a ``file://`` URL and
390+
have MathJax served from the local pyhton server without the need for
391+
any access to the internet.
392+
393+
277394
|-----|

0 commit comments

Comments
 (0)