-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
128 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,23 @@ | ||
import mathtranslate | ||
mathtranslate.process_latex.test_environment = False | ||
import mathtranslate.process_latex as pl | ||
import re | ||
old = r""" | ||
This is a paragraph with some L_a_T_e_X environments: | ||
\begin{enumerate} | ||
\item First item | ||
\item Second item | ||
\end{enumerate} | ||
And some math: $E=mc^2$ and $$\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}$$ | ||
$ H \psi = E \psi$ | ||
$ H \psi = E \psi$ | ||
$ H \psi = E \psi$ | ||
$ H \psi = E \psi$ | ||
$ H \psi = E \psi$ | ||
$ H \psi = E \psi$ | ||
$ H \psi = E \psi$ | ||
$ H \psi = E \psi$ | ||
$ H \psi = E \psi$ | ||
$ H \psi = E \psi$ | ||
""" | ||
new = r""" | ||
THIS IS A PARAGRAPH WITH SOME L\_A\_T\_E\_X ENVIRONMENTS: | ||
\begin{enumerate} | ||
\item First item | ||
\item Second item | ||
\end{enumerate} | ||
AND SOME MATH: $E=mc^2$ AND $$\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}$$ | ||
??? | ||
$ H \psi = E \psi$ | ||
$ H \psi = E \psi$ | ||
$ H \psi = E \psi$ | ||
$ H \psi = E \psi$ | ||
$ H \psi = E \psi$ | ||
$ H \psi = E \psi$ | ||
$ H \psi = E \psi$ | ||
$ H \psi = E \psi$ | ||
$ H \psi = E \psi$ | ||
""" | ||
text1, eqs = mathtranslate.process_latex.replace_latex_envs(old) | ||
old = open("./old.txt").read() | ||
new = open("./new.txt").read() | ||
text1, eqs = mathtranslate.process_latex.replace_latex_objects(old) | ||
text2 = re.sub(r'XMATHX_2(?![\d_])', 'XMATHX_2_2', text1) | ||
text3 = text2.upper() | ||
text4 = mathtranslate.process_latex.recover_latex_envs(text3, eqs) | ||
text4 = mathtranslate.process_latex.recover_latex_objects(text3, eqs) | ||
assert text4 == new | ||
|
||
old_special = r'\\ \ \& \%' | ||
new_special = r' \\ \ \& \% ' | ||
intermediate = pl.replace_special(old_special) | ||
assert intermediate.count(mathtranslate.config.math_code) == 4 | ||
assert pl.recover_special(intermediate) == new_special | ||
|
||
old_accent = r'\^{o} \^o \"{o} \"o' | ||
new_accent = r'\^{o} \^{o} \"{o} \"{o}' | ||
intermediate = pl.replace_accent(old_accent) | ||
assert intermediate.count(mathtranslate.config.math_code) == 4 | ||
assert pl.recover_accent(pl.replace_accent(old_accent)) == new_accent |