Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find a way to support custom Math expressions #1096

Closed
BoboTiG opened this issue Nov 12, 2021 · 9 comments
Closed

Find a way to support custom Math expressions #1096

BoboTiG opened this issue Nov 12, 2021 · 9 comments
Labels
bug Something isn't working

Comments

@BoboTiG
Copy link
Owner

BoboTiG commented Nov 12, 2021

Sample output of the english Wiktionary parsing:

<math> ERROR with \begin{align}\frac{\pi}{2} & = \prod_{n=1}^{\infty} \frac{ 4n^2 }{ 4n^2 - 1 } = \prod_{n=1}^{\infty} \left(\frac{2n}{2n-1} \cdot \frac{2n}{2n+1}\right) \\[6pt]& = \Big(\frac{2}{1} \cdot \frac{2}{3}\Big) \cdot \Big(\frac{4}{3} \cdot \frac{4}{5}\Big) \cdot \Big(\frac{6}{5} \cdot \frac{6}{7}\Big) \cdot \Big(\frac{8}{7} \cdot \frac{8}{9}\Big) \cdot \; \cdots \\\end{align} in [Wallis product]

<math> ERROR with f:\Z_2^n \to \Z_2 in [bent function]

<math> ERROR with \frac = \frac in [circle of Apollonius]

<math> ERROR with \and in [conjunction]

<math> ERROR with n\in\N in [elementary symmetric polynomial]

<math> ERROR with (x_1, x_2, \ldots, x_m, y)\in\R^{m+1} in [graph]

<math> ERROR with f: \R^m\rightarrow\R in [graph]

<math> ERROR with a_i \isin R in [group ring]

<math> ERROR with \R^3 in [halfway model]

<math> ERROR with \begin{align}\rho(g, h) (0,x_1,\ldots,x_k) &= g(x_1,\ldots,x_k) \\\rho(g, h) (y+1,x_1,\ldots,x_k) &= h(y,\rho(g, h) (y,x_1,\ldots,x_k),x_1,\ldots,x_k)\,\end{align} in [primitive recursion]

<math> ERROR with \isin in [supermodular]

I guess Mediawiki is using custom symbols somehow. We should find a way to handle them.

@BoboTiG BoboTiG added the bug Something isn't working label Nov 12, 2021
@BoboTiG
Copy link
Owner Author

BoboTiG commented Nov 12, 2021

Sample output of the portuguese Wiktionary:

<math> ERROR with \Delta U = Q - \Tau in [calor]
<math> ERROR with \Tau in [calor]
<math> ERROR with \Delta U = Q - \Tau in [trabalho]
<math> ERROR with \Tau in [trabalho]

@BoboTiG
Copy link
Owner Author

BoboTiG commented Nov 12, 2021

If we find something, we should also update the Wiki.

@lasconic
Copy link
Collaborator

lasconic commented Dec 17, 2021

@lasconic
Copy link
Collaborator

@lasconic
Copy link
Collaborator

Most of the errors can be fixed with simple string substitutions based on the list provided above. Just a couple are more problematic:

Portuguese, French, the remaining english ones etc... they work ok with the PR to come.

lasconic added a commit to lasconic/ebook-reader-dict that referenced this issue Dec 18, 2021
@lasconic
Copy link
Collaborator

Note for later, to debug latex output, add "-d -1" in dvioptions

lasconic added a commit to lasconic/ebook-reader-dict that referenced this issue Dec 18, 2021
@lasconic
Copy link
Collaborator

lasconic commented Feb 3, 2022

I found why the few words using \begin{align} don't work.

See https://comp.text.tex.narkive.com/zTTDqtBD/help-with-amsmath-align-not-possible

render_expr = f"{expr}" if expr.startswith("\\begin{align}") else f"${expr}$"

would fix it but we need to change the IMAGE_CSS... Needs more work.

@Moonbase59
Copy link
Contributor

Even if this is closed, let me add the ones my renderer found in the DE Wiktionary:

2022-02-04 02:05:54 ERROR: Couldn’t render 'N_{\rm A}'
2022-02-04 02:08:56 ERROR: Couldn’t render '\R'
2022-02-04 02:10:13 ERROR: Couldn’t render '\Zi\sqrt{5}'
2022-02-04 02:10:19 ERROR: Couldn’t render '\N'
2022-02-04 02:10:20 ERROR: Couldn’t render '\R'
2022-02-04 02:15:49 ERROR: Couldn’t render 'y(x) = e^{(x-x_0)A}\cdot y_0 + \int_{x_0}^x e^{(x-t)A}g(t){\rm d}t\ '
2022-02-04 02:18:11 ERROR: Couldn’t render '- 42 \in \R'

Mostly due to \R and \rm, I should think. Unfortunately, my renderer doesn’t spit out the article.

@lasconic
Copy link
Collaborator

lasconic commented Feb 4, 2022

You need to replace these :

# see issue #1096
expr = expr.replace("\\Z", "\\mathbb{Z}")
expr = expr.replace("\\N", "\\mathbb{N}")
expr = expr.replace("\\R", "\\mathbb{R}")
expr = expr.replace("\\isin", "\\in")
expr = expr.replace("\\and", "\\land")
expr = expr.replace("\\Tau", "\\mathrm{T}")
expr = expr.replace("\\infin", "\\infty")
expr = expr.replace("\\rarr", "\\rightarrow")

See #1096 (comment)

Though, I feel like we are doing double work here...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants