nbgrader icon indicating copy to clipboard operation
nbgrader copied to clipboard

"manual grading" screen unable to format any math containing a prime symbol `'`

Open Jannertje opened this issue 4 years ago • 11 comments

Operating system

MacOS 10.14.4 (18E226)

nbgrader --version

0.6.1

jupyter notebook --version

6.0.3

Expected behavior

In one of the courses I am teaching, we wanted to use nbgrader to automate some of the grading. Until now it's working beautifully -- thanks for this. For this week, we have a notebook containing function derivatives, like so: $$ y'(x) = f(x, y(x)) $$ which sets correctly in my source and release versions, looking a little like this: image

Actual behaviour

If I then open a student submission, at first I am able to see the math, like so, image

but when it is about to replace the text with a MathJax formula, it looks like so: image

When this happens, I get these errors in my terminal:

[W 17:49:18.142 NotebookApp] 404 GET /static/components/MathJax/jax/output/HTML-CSS/fonts/STIX/fontdata.js?V=2.7.7 (::1) 2.53ms referer=http://localhost:8889/formgrader/submissions/ccc77ef030ea4ae5bda1d7d0e787089c/?index=0
[W 17:49:20.909 NotebookApp] 404 GET /static/components/MathJax/fonts/HTML-CSS/TeX/otf/MathJax_Script-Regular.otf (::1) 1.49ms referer=http://localhost:8889/formgrader/submissions/ccc77ef030ea4ae5bda1d7d0e787089c/?index=0

This only happens in the formulas containing a prime/derivative sign, weirdly enough.

Steps to reproduce the behavior

I get the same results using a different browser and also using a different machine (MacOS 10.14.6, jupyter 6.0.2, nbgrader 0.6.1)

I am not sure how I can add a MWE but if it seems useful later I can try making a test assignment and a submission, or I could share an anonymized submission from the real assignment. Please let me know which one is preferable.

Jannertje avatar May 14 '20 15:05 Jannertje

OK pardon me, this is a duplicate of #426 -- I am willing to help search for the root cause instead of (stupidly) reinstalling MathJax?

Jannertje avatar May 14 '20 15:05 Jannertje

Thanks @Jannertje. Please do keep us posted if you find the root cause 👍

willingc avatar May 29 '20 05:05 willingc

I recently bumped MathJax to v2.7.8 for nteract. It's probably a good idea to do so here as well (or to double check that the formgrader.tpl is picking up the right version).

willingc avatar May 29 '20 05:05 willingc

+1 same problem.

(base) Fuji-2:math405 ortner$ jupyter notebook --version
6.0.3

(base) Fuji-2:math405 ortner$ nbgrader --version
/Users/ortner/anaconda3/lib/python3.7/site-packages/setuptools/distutils_patch.py:26: UserWarning: Distutils was imported before Setuptools. This usage is discouraged and may exhibit undesirable behaviors or errors. Please use Setuptools' objects directly or at least import Setuptools first.
  "Distutils was imported before Setuptools. This usage is discouraged "
Python version 3.7.7 (default, May  6 2020, 04:59:01)
[Clang 4.0.1 (tags/RELEASE_401/final)]
nbgrader version 0.6.1
[W 15:54:43.160 NotebookApp] 404 GET /static/components/MathJax/jax/output/HTML-CSS/fonts/STIX/fontdata.js?V=2.7.3 (::1) 10.30ms referer=http://localhost:8888/formgrader/submissions/d00203afdb00415ea3519023ac9547c2/
[W 15:54:43.995 NotebookApp] 404 GET /static/components/MathJax/fonts/HTML-CSS/TeX/otf/MathJax_AMS-Regular.otf (::1) 1.66ms referer=http://localhost:8888/formgrader/submissions/d00203afdb00415ea3519023ac9547c2/

(with a apologies for the noise ... replacing MathJax locally with v2.7.8 as described in #426 works as a workaround.)

cortner avatar Aug 27 '20 23:08 cortner

Possible workaround: use y^\prime instead of y'. They give the same LaTeX output in general. Haven't checked if that works around this issue.

slel avatar Aug 28 '20 00:08 slel

Same here, I'm currently using a code written by my self to replace all ' with \prime in the markdown sources. Is that possible to add a function that replaces all ' with \prime when [Math Processing Error] problem occurs? Or where should I look at if I want to contribute to this problem?

This is my sloppy solution:

import json
def replace_prime(f_dir):
    #improt the origin file in to json
    f = open(f_dir, "r")
    json_source = json.loads(f.read())
    cell_number = len(json_source['cells'])
    #go over the markdown cells and replace all ' with \prime in the markdown
    for i in range(cell_number):
        if json_source['cells'][i]['cell_type'] == 'markdown':
            line_number = len(json_source['cells'][i]['source'])
            for j in range(line_number):
                json_source['cells'][i]['source'][j] = json_source['cells'][i]['source'][j].replace('\'', ' \prime ')
    #write the result in to a new file which name have '_g' after origin file name
    new_dir = f_dir[:-6] + '_g.ipynb'
    file = open(new_dir, 'w')
    file.write(json.dumps(json_source, indent=1))
    file.close()

7Gao avatar Nov 30 '20 16:11 7Gao

Same here image

paddyroddy avatar Mar 06 '21 20:03 paddyroddy

Another problem with primes. The server indicates it is using MathJax 2.7.9:

[W 12:26:51.508 NotebookApp] 404 GET /static/components/MathJax/jax/output/HTML-CSS/fonts/STIX/fontdata.js?V=2.7.9 (127.0.0.1) 

roblem avatar Nov 24 '21 17:11 roblem

I've just tried things with clean docker builds for anaconda/conda and vanilla python 3.8, and the "primes" error is present on both. I was hoping that this was isolated to just anaconda/conda, but that isn't the case. I think for math-heavy classes this is a deal breaker.

Here is the Dockerfile for the clean build if it is useful to anyone:

FROM docker.io/python:3.8-bullseye

RUN pip install jupyter nbgrader pandas seaborn matplotlib scipy statsmodels
RUN jupyter nbextension install --sys-prefix --py nbgrader --overwrite
RUN jupyter nbextension enable --sys-prefix --py nbgrader
RUN jupyter serverextension enable --sys-prefix --py nbgrader

CMD ["jupyter", "notebook", "--ip=0.0.0.0", "--port=8888", "--NotebookApp.token=''"]

roblem avatar Nov 25 '21 12:11 roblem

I was working with @cortner on an issue which he's already mentioned in #856, but I think it might also be related to this issue (and maybe #1598). For whatever reason it looks like mathjax on the formgrader page tries to grab components which aren't available in the version of mathjax bundled with notebook. Things like

  • /user/nbgrader/static/notebook/components/MathJax/jax/output/HTML-CSS/fonts/STIX/fontdata.js?V=2.7.9
  • /user/nbgrader/static/notebook/components/MathJax/fonts/HTML-CSS/TeX/otf/MathJax_AMS-Regular.otf

give 404s. As mentioned in #426 replacing notebook/components/MathJax with a full installation seems to fix the issue, but I guess nbrgader needs to restrict the components requested in the MathJax config.

ianabc avatar Aug 31 '22 00:08 ianabc

Thanks for reporting this. It may also be related to https://github.com/jupyter/nbgrader/issues/1622.

Can you try replacing the mathjax import in your local installation to see if that solves the problem ?

The line is : https://github.com/jupyter/nbgrader/blob/90f749b8ea0514700dfa28fe560bbb489746e26f/nbgrader/server_extensions/formgrader/templates/formgrade/index.html.j2#L18

to replace by

{{ mathjax() }} 

This will use the default mathjax from nbconvert. On my side the 404 error disappear and mathjax seems to work correctly.

brichet avatar Sep 06 '22 07:09 brichet