Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
flatlatex
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
leger
flatlatex
Commits
546e8fcb
Commit
546e8fcb
authored
Jan 02, 2017
by
Jean-Benoist Leger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more tests (and bug fix)
parent
773a394f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
2 deletions
+60
-2
flatlatex/conv.py
flatlatex/conv.py
+1
-2
flatlatex/latexfuntypes.py
flatlatex/latexfuntypes.py
+2
-0
flatlatex/parser.py
flatlatex/parser.py
+3
-0
flatlatex/tests/test_conv.py
flatlatex/tests/test_conv.py
+33
-0
flatlatex/tests/test_parser.py
flatlatex/tests/test_parser.py
+21
-0
No files found.
flatlatex/conv.py
View file @
546e8fcb
...
...
@@ -28,8 +28,7 @@ import regex
from
.
import
latexfuntypes
from
.
import
parser
class
LatexSyntaxError
(
SyntaxError
):
pass
from
.latexfuntypes
import
LatexSyntaxError
class
converter
:
"""flatlatex converter class
...
...
flatlatex/latexfuntypes.py
View file @
546e8fcb
...
...
@@ -27,4 +27,6 @@ class latexfun:
self
.
fun
=
fun
self
.
nargs
=
nargs
class
LatexSyntaxError
(
SyntaxError
):
pass
flatlatex/parser.py
View file @
546e8fcb
...
...
@@ -23,10 +23,13 @@
# POSSIBILITY OF SUCH DAMAGE.
import
regex
from
.latexfuntypes
import
LatexSyntaxError
def
parse_one_element
(
s
):
R
=
r
'((?>\\(?:[^A-Za-z]|[A-Za-z]+))|(?>[^\{\}\\])|\{(?1)*\})'
r
=
regex
.
match
(
R
,
s
)
if
not
r
:
raise
LatexSyntaxError
s
=
s
[
r
.
span
()[
1
]:]
c
=
r
.
captures
()[
0
]
if
c
[
0
]
==
'
\\
'
:
...
...
flatlatex/tests/test_conv.py
0 → 100644
View file @
546e8fcb
from
..
import
converter
def
test_conv1
():
c
=
converter
()
r
=
c
.
convert
(
r
'\forall \eta>0\, \exists n\in\mathbb{N}\, \forall i>n\, |u_i-\mathcal{l}|<\eta'
)
assert
r
==
'∀η>0 ∃n∊ℕ ∀i>n |uᵢ-𝓵|<η'
def
test_conv2
():
c
=
converter
()
c
.
add_newcommand
(
r
'\newcommand\prob{\mathbb{P}}'
)
c
.
add_newcommand
(
r
'\newcommand\binom[2]{\frac{#2!}{#1!(#2-#1)!}}'
)
r
=
c
.
convert
(
r
'\prob(X=k)\,=\,\binom{k}{n}\times p^k(1-p)^{n-k}'
)
assert
r
==
'ℙ(X=k) = (n!)/(k!(n-k)!)×pᵏ(1-p)ⁿ⁻ᵏ'
def
test_conv3
():
c
=
converter
()
c
.
allow_zw
=
True
r
=
c
.
convert
(
r
'\frac{8}{9}'
)
assert
r
==
'⁸⁄₉'
c
.
allow_zw
=
False
r
=
c
.
convert
(
r
'\frac{8}{9}'
)
assert
r
==
'8/9'
def
test_conv4
():
c
=
converter
()
c
.
allow_combinings
=
True
r
=
c
.
convert
(
r
'\hat\alpha'
)
assert
r
==
'
\u03B1\u0302
'
c
.
allow_combinings
=
False
r
=
c
.
convert
(
r
'\hat\alpha'
)
assert
r
==
'hat(
\u03B1
)'
flatlatex/tests/test_parser.py
0 → 100644
View file @
546e8fcb
from
..
import
parser
def
test_parser
():
expected
=
{
r
'\\'
:
[(
'cmd'
,
r
'\\'
)],
r
'\cd'
:
[(
'cmd'
,
r
'\cd'
)],
r
'ab'
:
[(
'char'
,
'a'
),(
'char'
,
'b'
)],
r
'e{to{t}o}e'
:
[(
'char'
,
'e'
),(
'subexpr'
,
'to{t}o'
),(
'char'
,
'e'
)],
r
'g_f'
:
[(
'char'
,
'g'
),(
'oper'
,
'_'
),(
'char'
,
'f'
)],
r
'h^i'
:
[(
'char'
,
'h'
),(
'oper'
,
'^'
),(
'char'
,
'i'
)],
}
for
k
,
v
in
expected
.
items
():
assert
all
([
pki
==
vi
for
pki
,
vi
in
zip
(
parser
.
parse
(
k
),
v
)]),
"parser '%s'"
%
k
for
k1
,
v1
in
expected
.
items
():
for
k2
,
v2
in
expected
.
items
():
assert
all
([
pki
==
vi
for
pki
,
vi
in
zip
(
parser
.
parse
(
k1
+
' '
+
k2
),
v1
+
v2
)]),
"parser '%s'+'%s'"
%
(
k1
,
k2
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment