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

GladTeX should not nest math environments in "\[" "\]" #21

Open
belonesox opened this issue Feb 28, 2024 · 4 comments
Open

GladTeX should not nest math environments in "\[" "\]" #21

belonesox opened this issue Feb 28, 2024 · 4 comments

Comments

@belonesox
Copy link
Contributor

belonesox commented Feb 28, 2024

Consider following case — math environment in markdown math mode $$:

image

$$
\begin{align*}
	\sum_{j=1}^{n} a_{ij} x_j = b_i, \ i = 1, \ldots, m\  (m < n) \leftarrow Ax = b,\\
	x_j \geqslant 0, \ j = 1, \ldots, n.
\end{align*}
$$

VSCode preview / KaTeX works OK with it (see screenshot).
In pandoc JSON we have


        {
            "t": "Para",
            "c": [
                {
                    "t": "Math",
                    "c": [
                        {
                            "t": "DisplayMath"
                        },
                        "\n\\begin{align*}\n\\sum_{j=1}^{n} a_{ij} x_j = b_i, \\ i = 1, \\ldots, m\\  (m < n) \\leftarrow Ax = b,\\\\\nx_j \\geqslant 0, \\ j = 1, \\ldots, n.\n\\end{align*}\n"
                    ]
                }
            ]
        },

Unfortunately, GladTeX nest all this in "[" "]" (and latex compilation failed, because "Erroneous nesting of equation structures"`)

    def _format_document(self, preamble):
        """Return a formatted LaTeX document with the specified formula
        embedded."""
        opening, closing = None, None
        if self.__maths_env:
            opening = '\\begin{%s}' % self.__maths_env
            closing = '\\end{%s}' % self.__maths_env
        else:
            # determine characters with which to surround the formula
            opening = '\\[' if self.__displaymath else '\\('
            closing = '\\]' if self.__displaymath else '\\)'

Probably there is planned some detection of mathenvs (set_latex_environment), but the function is not used still.

May be for displaymath node just check that the node text starting with \begin{ and then not wrap such nodes with anything? (without detecting name of the environment)

If this OK, I can patch it...

@humenda
Copy link
Owner

humenda commented Feb 28, 2024 via email

@belonesox
Copy link
Contributor Author

OK, I updated description (the only screenshot I left to show, that VSCode/KaTeX works with it…).

@belonesox
Copy link
Contributor Author

OK with description of the issue?

@humenda
Copy link
Owner

humenda commented Mar 3, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants