Skip to content

Commit

Permalink
Support Math alphabets (#51)
Browse files Browse the repository at this point in the history
- Correctly show \bar (#52)
  • Loading branch information
roniemartinez committed Jun 5, 2019
1 parent 638aef2 commit fded646
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -16,7 +16,7 @@ matrix:

branches:
except:
- /^[0-9]+\.[0-9]+\.[0-9]+$/
- /^[0-9]+\.[0-9]+\.[0-9]+/

install:
- pip install pipenv
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,13 @@

## Unreleased

## 2.7.0 - 2019-06-05
### Added
- Support Math alphabets (#51)

### Fixed
- Correctly show \bar (#52)

## 2.6.7 - 2019-04-03
### Removed
- Drop Python 3.4 support
Expand Down
6 changes: 3 additions & 3 deletions Pipfile
Expand Up @@ -4,8 +4,8 @@ url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
codecov = "*"
pytest = "*"
pytest-cov = "*"
codecov = "==2.0.15"
pytest = "==4.6.2"
pytest-cov = "==2.7.1"

[packages]
2 changes: 1 addition & 1 deletion appveyor.yml
Expand Up @@ -11,7 +11,7 @@ environment:

branches:
except:
- /^[0-9]+\.[0-9]+\.[0-9]+$/
- /^[0-9]+\.[0-9]+\.[0-9]+/

install:
- "%PYTHON%\\Scripts\\pip.exe install pipenv"
Expand Down
1 change: 1 addition & 0 deletions latex2mathml/commands.py
Expand Up @@ -31,6 +31,7 @@
r'\left': (1, 'mo', {'stretchy': 'true', 'fence': 'true', 'form': 'prefix'}),
r'\right': (1, 'mo', {'stretchy': 'true', 'fence': 'true', 'form': 'postfix'}),
r'\overline': (1, 'mover', {}),
r'\bar': (1, 'mover', {}),
r'\underline': (1, 'munder', {}),
}

Expand Down
2 changes: 1 addition & 1 deletion latex2mathml/converter.py
Expand Up @@ -140,7 +140,7 @@ def _convert_command(element, elements, index, iterable, parent):
else:
_classify(param, new_parent)
_get_postfix_element(element, parent)
if element == r'\overline':
if element in (r'\overline', r'\bar'):
mo = eTree.SubElement(new_parent, 'mo', stretchy='true')
mo.text = '¯'
elif element == r'\underline':
Expand Down
4 changes: 3 additions & 1 deletion latex2mathml/tokenizer.py
Expand Up @@ -66,7 +66,9 @@ def tokenize(data):
yield buffer
buffer = ''
elif char in '{}*':
if buffer.startswith(r'\begin') or buffer.startswith(r'\end'):
# FIXME: Anything that starts with '\math' passes. There is a huge list of math symbols in
# unimathsymbols.txt and hard-coding all of them is inefficient.
if buffer.startswith(r'\begin') or buffer.startswith(r'\end') or buffer.startswith(r'\math'):
if buffer.endswith('}'):
yield buffer
yield char
Expand Down
2 changes: 1 addition & 1 deletion setup.py
@@ -1,6 +1,6 @@
from setuptools import setup

VERSION = '2.6.7'
VERSION = '2.7.0'

setup(
name='latex2mathml',
Expand Down
23 changes: 23 additions & 0 deletions tests/test_command.py
Expand Up @@ -400,3 +400,26 @@ def test_array_with_horizontal_lines(math_and_row):
s = r'\begin{array}{cr} 1 & 2 \\ 3 & 4 \\ \hline 5 & 6 \end{array}'

assert _convert(math) == convert(s)


def test_issue_52(math_and_row):
math, row = math_and_row
over = eTree.SubElement(row, 'mover')
equal = eTree.SubElement(row, 'mo')
equal.text = '='
sub_right = eTree.SubElement(row, 'msub')

row = eTree.SubElement(over, 'mrow')
sub_left = eTree.SubElement(row, 'msub')
mi = eTree.SubElement(sub_left, 'mi')
mi.text = 'z'
mn = eTree.SubElement(sub_left, 'mn')
mn.text = '1'
mo = eTree.SubElement(over, 'mo', stretchy='true')
mo.text = '¯'

mi = eTree.SubElement(sub_right, 'mi')
mi.text = 'z'
mn = eTree.SubElement(sub_right, 'mn')
mn.text = '2'
assert _convert(math) == convert(r'\bar{z_1} = z_2')
7 changes: 7 additions & 0 deletions tests/test_converter.py
Expand Up @@ -438,3 +438,10 @@ def test_issue_33(math_and_row):
mo = eTree.SubElement(row, 'mo')
mo.text = ']'
assert _convert(math) == convert(latex)


def test_issue_51(math_and_row):
math, row = math_and_row
mi = eTree.SubElement(row, 'mi')
mi.text = 'ℝ'
assert _convert(math) == convert(r'\mathbb{R}')
4 changes: 4 additions & 0 deletions tests/test_tokenizer.py
Expand Up @@ -117,3 +117,7 @@ def test_issue_33():
'&', '\\vdots', '&', '\\ddots', '&', '\\vdots', '\\\\', 'a', '_', '{', 'm', ',', '1', '}', '&', 'a',
'_', '{', 'm', ',', '2', '}', '&', '\\cdots', '&', 'a', '_', '{', 'm', ',', 'n', '}', '\\end{bmatrix}']
assert expected == list(tokenize(latex))


def test_issue_51():
assert [r'\mathbb{R}'] == list(tokenize(r'\mathbb{R}'))

0 comments on commit fded646

Please sign in to comment.