Skip to content

Commit

Permalink
Merge pull request #133 from regebro/more-mathjax
Browse files Browse the repository at this point in the history
Copy in the given mathjax if it's local files.
  • Loading branch information
regebro committed May 22, 2017
2 parents 87c0283 + a66b8e7 commit 65d3227
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
10 changes: 6 additions & 4 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ Changes

- Dropped support for Python 3.3 and 3.4, because I now use recursive glob.

- Added support for resource-directories. This is used by the local mathjax
support.
- Templates can now have a resource-directories statements, to specify extra
directories of resources. This can be used in templates for JS libraries,
like MathJax.

- Templates can also have a resource-directories statements, to specify extra
directories of resources. That's probably not useful, but there it is.
- The MathJax argument can now be a local copy.

- Switched the default MathJax URL to https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1


2.3 (2017-04-12)
Expand Down
10 changes: 9 additions & 1 deletion docs/presentations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,15 @@ so that this::


will be rendered by the MathJax javascript library. The math directive can also
be used as a "role" with the equations inlined with the text flow.
be used as a "role" with the equations inlined with the text flow. Note that
if you use the math statement, by default the MathJax library will be loaded
from the internet, meaning that your presentation will need network connectivity
to work, which can be a problem when presenting and conferences, which often have
bad network connectivity.

This can be solved by specifying a local copy of mathjax with the --mathjax
command line.


External files
--------------
Expand Down
2 changes: 1 addition & 1 deletion hovercraft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def my_gettext(s):
'Ex 8080 or 127.0.0.1:9000. Defaults to 0.0.0.0:8000.'))
parser.add_argument(
'--mathjax',
default=os.environ.get('HOVERCRAFT_MATHJAX', 'https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML'),
default=os.environ.get('HOVERCRAFT_MATHJAX', 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML'),
help=('The URL to the mathjax library.'
' (It will only be used if you have rST ``math::`` in your document)'))
parser.add_argument(
Expand Down
16 changes: 12 additions & 4 deletions hovercraft/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,17 @@ def rst2html(filepath, template_info, auto_console=False, skip_help=False, skip_
extra_info=media)

if sm.need_mathjax and mathjax:
template_info.add_resource(None, JS_RESOURCE,
target=mathjax,
extra_info=JS_POSITION_HEADER)
if mathjax.startswith('http'):
template_info.add_resource(None, JS_RESOURCE,
target=mathjax,
extra_info=JS_POSITION_HEADER)
else:
# Local copy
template_info.add_resource(mathjax, DIRECTORY_RESOURCE,
target='mathjax')
template_info.add_resource(None, JS_RESOURCE,
target='mathjax/MathJax.js?config=TeX-MML-AM_CHTML',
extra_info=JS_POSITION_HEADER)

# Position all slides
position_slides(tree)
Expand Down Expand Up @@ -177,7 +185,7 @@ def generate(args):
is_in_template=True)
else:
for filename in uris:
source_files.extend(copy_resource(filename, css_sourcedir, css_targetdir))
source_files.append(copy_resource(filename, css_sourcedir, css_targetdir))

# All done!

Expand Down
3 changes: 2 additions & 1 deletion hovercraft/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ def copy_resource(self, resource, targetdir):
continue
rest_target_path = file_path[len(source_path)+1:]
target_path = os.path.join(targetdir, final_path, rest_target_path)
yield self._copy_file(file_path, target_path)
# Don't yield the result, we don't monitor these.
self._copy_file(file_path, target_path)
else:
target_path = os.path.join(targetdir, final_path)
yield self._copy_file(source_path, target_path)
Expand Down
2 changes: 1 addition & 1 deletion hovercraft/tests/test_hovercraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def test_mathjax(self):

with open(os.path.join(tmpdir, 'index.html'), 'rb') as outfile:
result = outfile.read()
self.assertIn(b'<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">', result)
self.assertIn(b'<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML">', result)
self.assertIn(br'<div class="math-block ">$$\begin{align}dS = \frac{dQ}{T}\end{align}$$</div>', result)
self.assertIn(br'<span class="math ">\(S = k \log W\)</span>', result)

Expand Down

0 comments on commit 65d3227

Please sign in to comment.