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

There should be no new line after equation/math block in tex document #787

Closed
johnjarmitage opened this issue Nov 28, 2023 · 6 comments
Closed
Labels
bug Something isn't working

Comments

@johnjarmitage
Copy link

Description

I have come across a bug in the layout of equations and text when building latex files. It is identical to this issue in pandoc that was solved in 2015/2016, jgm/pandoc#2171. The issue is that mystmd is adding a return after the equation when createing the latex file. An axample,

In markdown I have:

Manning-Strickler empirical law, such that,
```{math}
\tau_{b} = \rho_{w} C_{f} u^{2}
``` 
where...

and this gets converted into latex as,

Manning-Strickler empirical law, such that

\begin{equation}
\tau_{b} = \rho_{w} C_{f} u^{2}
\end{equation}

where,

The markdown version has a paragraph with an equation in the paragraph, while in latex the extra return means a new paragraph is started either side of the equation. I want the markdown to tex conversion to look like this:

Manning-Strickler empirical law, such that
\begin{equation}
\tau_{b} = \rho_{w} C_{f} u^{2}
\end{equation}
where,

I'm using myst v1.1.29

Proposed solution

Perhaps a similar solution as used in pandoc, something to do with defining inline and block equations? I am however not sure as I don't know anything about this.

@johnjarmitage johnjarmitage added the bug Something isn't working label Nov 28, 2023
@akhmerov
Copy link

akhmerov commented Dec 21, 2023

Arriving here from #819 (a duplicate of this issue). Also relevant is sphinx-doc/sphinx#8166 because myst-parser should stay compatible with sphinx, which doesn't have a math role.

Some considerations:

  • I believe math embedded in a paragraph rather than ending it should be the default. Well, because naively I'd expect that most equations occur not at the end of paragraph.
  • For compatibility with sphinx/docutils doctree, a math environment should probably by default convert into a math directive (which breaks the paragraph).

Therefore a reasonable balance seems to be:

  • Make dollar-ed display math and math denoted using a latex environment (\begin{equation} etc) to be converted into an in-paragraph display math
  • Keep :::math ... ::: insert an end of paragraph.

@rowanc1 rowanc1 changed the title There should be no new line after equation block in tex document There should be no new line after equation/math block in tex document Mar 15, 2024
@LecrisUT
Copy link
Contributor

Therefore a reasonable balance seems to be:

* Make dollar-ed display math and math denoted using a latex environment (`\begin{equation}` etc) to be converted into an in-paragraph display math

* Keep `:::math ... :::` insert an end of paragraph.

I don't think the special treatment of :::math is necessary. Within markdown the double line break already has the same meaning as with LaTeX, i.e.

This is a text with equation
:::math
a + b = c,
:::
which continues without paragraph

Here we have a new paragraph:
:::math
c = a + b.
:::

And we want to break the paragraph above

Should be converted to:

This is a text with equation
\begin{equation}
a + b = c,
\end{equation}
which continues without paragraph.

Here we have a new paragraph:
\begin{equation}
c = a + b.
\end{equation}

And we want to break the paragraph above

I was looking at where the newlines are inserted, but it seems further up in the middle layers 1. Not a straightforward patch thus far.

Footnotes

  1. https://github.com/executablebooks/mystmd/blob/4f6699c27b60b60fe5cce31da3d1056ce82c9e3a/packages/myst-to-tex/src/math.ts#L51-L58

@rowanc1
Copy link
Member

rowanc1 commented Mar 25, 2024

Hi all - I have put a fix for this together in #1032. The way that I decided to go in that PR is to track the spacing directly on the math node, this allows us to have markdown act the same as latex for the output (i.e. no extra space generated if it is part of the same paragraph). I decided not to to do this by nesting the math inside of a paragraph, as that is rendered as a div and in html p > div is not allowed.

I have tested this for amsmath, math directives, and dollar-math. (The dollar-math has a bug if it is the start of a paragraph which I haven't yet tracked down.)

@rowanc1
Copy link
Member

rowanc1 commented Mar 26, 2024

This will be released in the next version, hopefully in the next few days!

@rowanc1 rowanc1 closed this as completed Mar 26, 2024
@dellaert
Copy link

@rowanc1 before opening a new issue on this. It seems

Paragraph
$$Ax=b$$
Paragraph

does work, but

Paragraph
$$
Ax=b
$$
Paragraph

does not :-/

Neither of them work well with jupyter-book, so I'll switch everything to \begin{equation} and \end{equation}, which seems to work well both for latex genertion 8and* jupyter-book.

@rowanc1
Copy link
Member

rowanc1 commented Dec 18, 2024

Could you open a new issue on this please! The former is tested, but not the dollars on new lines. Should be an easy fix.

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

5 participants