Skip to content

Commit

Permalink
Remove png support in mathoid
Browse files Browse the repository at this point in the history
  • Loading branch information
int-y1 authored and Xyene committed Jan 20, 2023
1 parent 36c8059 commit 7be0e32
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
4 changes: 2 additions & 2 deletions judge/models/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def make_timezones():

MATH_ENGINES_CHOICES = (
('tex', _('Leave as LaTeX')),
('svg', _('SVG with PNG fallback')),
('svg', _('SVG only')),
('mml', _('MathML only')),
('jax', _('MathJax with SVG/PNG fallback')),
('jax', _('MathJax with SVG fallback')),
('auto', _('Detect best quality')),
)

Expand Down
31 changes: 10 additions & 21 deletions judge/utils/mathoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,23 @@ def query_mathoid(self, formula, hash):
logger.error('Mathoid failure for: %s\n%s', formula, data)
return

if any(i not in data for i in ('mml', 'png', 'svg', 'mathoidStyle')):
logger.error('Mathoid did not return required information (mml, png, svg, mathoidStyle needed):\n%s', data)
if any(i not in data for i in ('mml', 'svg', 'mathoidStyle')):
logger.error('Mathoid did not return required information (mml, svg, mathoidStyle needed):\n%s', data)
return

css = data['mathoidStyle']
mml = data['mml']
result = {
'css': css, 'mml': mml,
'png': self.cache.cache_data(hash, 'png', bytearray(data['png']['data'])),
'css': css,
'mml': mml,
'svg': self.cache.cache_data(hash, 'svg', data['svg'].encode('utf-8')),
}
self.cache.cache_data(hash, 'mml', mml.encode('utf-8'), url=False, gzip=False)
self.cache.cache_data(hash, 'css', css.encode('utf-8'), url=False, gzip=False)
return result

def query_cache(self, hash):
result = {
'svg': self.cache.get_url(hash, 'svg'),
'png': self.cache.get_url(hash, 'png'),
}
result = {'svg': self.cache.get_url(hash, 'svg')}

key = 'mathoid:css:' + hash
css = result['css'] = self.css_cache.get(key)
Expand Down Expand Up @@ -136,31 +133,23 @@ def get_result(self, formula):
'mml': self.output_mml,
'jax': self.output_jax,
'svg': self.output_svg,
'png': self.output_png,
'raw': lambda x: x,
}[self.type](result)

def output_mml(self, result):
return result['mml']

def output_jax(self, result):
return format_html('<span class="{4}">'
'''<img class="tex-image" src="{0}" style="{2}" alt="{3}"'''
""" onerror="this.src='{1}';this.onerror=null">"""
"""<span class="tex-text" style="display:none">{5}{3}{5}</span>"""
return format_html('<span class="{3}">'
'<img class="tex-image" src="{0}" style="{1}" alt="{2}">'
'<span class="tex-text" style="display:none">{4}{2}{4}</span>'
'</span>',
result['svg'], result['png'], result['css'], result['tex'],
result['svg'], result['css'], result['tex'],
['inline-math', 'display-math'][result['display']], ['~', '$$'][result['display']])

def output_svg(self, result):
return format_html('<img class="{4}" src="{0}" style="{2}" alt="{3}" '
"""onerror="this.src='{1}';this.onerror=null">""",
result['svg'], result['png'], result['css'], result['tex'],
['inline-math', 'display-math'][result['display']])

def output_png(self, result):
return format_html('<img class="{3}" src="{0}" style="{1}" alt="{2}">',
result['png'], result['css'], result['tex'],
result['svg'], result['css'], result['tex'],
['inline-math', 'display-math'][result['display']])

def display_math(self, math):
Expand Down

0 comments on commit 7be0e32

Please sign in to comment.