mathjax/MathJax

The line break(\\) is not work

woody-li opened this issue ยท 54 comments

The latex:
x = a + b \\ y = b + c
The line-break isn't effect and it renders as single line.
However, it works fine and renders as two lines at verision 2.

dpvc commented

Linebreaks are not yet implemented in version 3. This is one of the significant features from version 2 that has not yet been ported to version 3.

Is it possible to update the support information in the symbols table at http://docs.mathjax.org/en/v3.0-latest/input/tex/macros/index.html .
Any schedule to implement the linebreak?

dpvc commented

I'm not sure what you want changed there. The macros are simply listed, and since \\ is used within multi-line environments, it needs to be listed there. There is a link to Carol Fisher's page about the macros (written for v2), but that is not something we maintain, so she would have to maintain it.

In any case, it is not a TeX issue, but an output issue, and the fact that line breaking isn't implemented is documented in several places.

Any schedule to implement the linebreak?

It will be next year, probably in the first half of the year, but there is no specific timetable at the moment.

dpvc commented

In the meantime, you can do something like

\displaylines{x = a + b \\ y = b + c}

to get multiple lines

Thanks for your reply.
The \displaylines solved my problem.

The information I said that adding a column in the macros table to show the support version.

I'm not sure if it is helpful, but I also found the use of \display{align} honours the newline instruction as well.

\begin{align}2x+y&=5\\y&=-2x+5\end{align}

This also requires the addition of the '&' before the alignment point, and has the benefit of making the equations more readable in our use case.

For some reason, I had to add a third / on my environment (Japanese WordPress blog.)
This didn't work (everything was rendered on the same line):

\displaylines{x = a + b \\ y = b + c}

This worked (2 lines):

\displaylines{x = a + b \\\ y = b + c}
dpvc commented

@T-Kuhn, WordPress uses \ as a special character, and it is often stripped out of WordPress posts (depending on what editor you are using). As an escape character, it can prevent the normal action of the character that follows it, so to get an explicit backslash into your post, you need to double it. That is why you need an extra backslash (because the first two equal a single backslash in the output). You probably should double the second one as well, but apparently that is not required.

dpvc commented

I'm moving this issue to the main MathJax issue tracker so that it can be found more readily by others.

@dpvc Thanks for your reply. In the meantime, I figured out that the third backslash is only required if the "Using Markdown" toggle on our specific WordPress blog is set to "on". So, at least in my case, this was a problem between different plugins interfering with each other. Seems like the backslash get's handled as an escape character in Markdown mode on our blog.

dpvc commented

@T-Kuhn, yes, Markdown uses the backslash as an escape character. You may also need to be concerned about underscores, as these are used to indicate italics. So you may need to do things like x\_1 rather than x_1 in some situations.

Any update or schedule about it?

dpvc commented

@woody-li, there is a 3.1 update that is nearly ready to release (hope to have it out by the end of the month). The next release should be at the end of the summer, and will mainly be the long-awaited additional font support for v3 (including STIX2 support and tools for building the data needed for supporting other web fonts). So line breaking and other features will most likely have to wait until next year.

Would it be bad of an idea to add referrence to this task to "Not Yet Ported to Version 3" section in the documenation, for those who go there and want to know status of those items, and possibly for other items on the list? (I assume this ticket is representative for the "Currently, automatic line breaking support is missing from version 3. This is a key feature to be included in a future release." bullet).

So line breaking and other features will most likely have to wait until next year.

That's the reason why nearly nobody is using MathJax 3. I would put it as highest priority if you want to distribute MathJax 3 and see it being successful. I nearly swapped to Katex because of this missing feature, and maybe will do so. However, Mathjax is still my favorite (bolder font, line break of Jax 2 and other features).

Tony2 commented

Would it be bad of an idea to add referrence to this task to "Not Yet Ported to Version 3" section in the documenation, for those who go there and want to know status of those items, and possibly for other items on the list? (I assume this ticket is representative for the "Currently, automatic line breaking support is missing from version 3. This is a key feature to be included in a future release." bullet).

that could have saved me a few hours trying to figure out why line breaking doesn't work for me with v3.

that could have saved me a few hours trying to figure out why line breaking doesn't work for me with v3.

thankfully I didn't have to spend a few hours, but it was an annoying waste of time. Now I have to reset up everything so I can use 2.7. Seems silly to push back such a huge issue

For what it's worth, I think linebreaking is the last thing we are waiting for to move from mathjax 2 to mathjax 3 as the default math rendering in JupyterLab: jupyterlab/jupyterlab#7218

pkra commented

@jasongrout just a thought from a bystander: a group as well funded as the jupyter projects might consider actually supporting MathJax's development.

@pkra, first, the tone of your comment indicates that I came across as entitled in some way to Davide's time. Both of us have been involved with open source and funding long enough to know that there is no entitlement here - I'm sorry if I came across that way. I only meant to flag another potential userbase's interest when and if the work happened.

On the deeper issue you raise: we both know how difficult it is to find funding for open source. A few of us in Jupyter had a great conversation just this morning on how to help fellow open-source projects connect with funding sources in a successful, sustainable way. In fact, @fperez's Scipy keynote next week will focus on the topic of funding open source (Friday morning next week: https://www.scipy2021.scipy.org/schedule).

@dpvc (and @pkra if you're interested too) - if you want to follow up, email me and let's set up a time to brainstorm some ideas about resources for funding (while most of Jupyter's funding is tied to specific initiatives or is controlled by specific PIs for specific projects, we have cultivated a network of contacts and have other ideas about funding). For example (which you may already be aware of), for things like a specific feature, NumFOCUS small development grants may help.

The document says "Currently, automatic line breaking support is missing from version 3. This is a key feature to be included in a future release.", so "\\" means automatic line breaking ๐Ÿ˜‚ ...

dpvc commented

@jasongrout, thanks for your information about line breaking. I know that it is important, and haven't forgotten about it. Things have taken somewhat longer than I had hoped, and I am still working on the font update. I have the toolchain for SVG in pretty good shape, but there is still some work needed for CommonHTML versions. There will be a release at the end of August that will at least include the SVG versions. Line breaking is then the next feature that I will work on. Because I go back to teaching in the fall, that will have to wait until next year. I wish I were able to work faster, but it is what it is.

We have received two small development grants from NumFOCUS already. Doing one for line breaking may be a good fit as well. I will consider it for next year. Thank you for the offer to discuss funding ideas. I would be happy to chat with you about that. We should make arrangements to do that before I go back to teaching.

dpvc commented

@abnerlee:

The document says "Currently, automatic line breaking support is missing from version 3. This is a key feature to be included in a future release.", so "\" means automatic line breaking

Yes, it should really say line breaking of any kind, as they both use the same mechanism.

Is this going to be implemented any time soon?

dpvc commented

@ShadiestGoat, not until next year.

So line breaking and other features will most likely have to wait until next year.

That's the reason why nearly nobody is using MathJax 3. I would put it as highest priority if you want to distribute MathJax 3 and see it being successful. I nearly swapped to Katex because of this missing feature, and maybe will do so. However, Mathjax is still my favorite (bolder font, line break of Jax 2 and other features).

Am I the only person who doesn't see this as such a big deal? When working with LaTeX I always use the amsmath environments like gather and multline if my formula or equation is too long to fit in one line. In fact, LaTeX (like MathJax v3) doesn't even support line breaks in a regular equation environment. The same amsmath environments have been ported to MathJax so there should be no problem writing math just like you would in LaTeX.

Wow, thanks for the comment @averms. From the issue description I incorrectly thought that \\ line breaks aren't supported anywhere. However it seems that on the contrary only the cases not supported by latex itself don't work. All the relevant amsmath environments actually work quite well.

Am I the only person who doesn't see this as such a big deal?

A super common LaTeX paradigm, in my experience, is $stuff$\\$stuff$, which this would be the closest to. Though I'll admit that $stuff$<br>$stuff$ can work in some/most contexts (e.g. Jupyter) for something sort of equivalent.

In any case, I don't think the problem is really humans writing MathJax -- it's packages that generate MathJax code. From that perspective this is a major API break from previous MathJax versions, regardless of what is supposed be doable in LaTeX or not. I'm getting a bit of visceral horror after running across this issue at the thought of trying to figure out where my package is using \\ and what would come out equivalent to those cases.

A super common LaTeX paradigm, in my experience, is $stuff$\\$stuff$, which this would be the closest to.

I don't quite follow. Under which conditions would mathjax see this input? Assuming that v2 MathJax hub is configured to respond to $ delimiters, \\ wouldn't be seen and rendered by MathJax in this example. Can you please elaborate?

EDIT: Additionally, already in MathJax2 a\\a results in a processing error in Jupyterlab. ๐Ÿค” my bad, wrong configuration.

A super common LaTeX paradigm, in my experience, is $stuff$\\$stuff$, which this would be the closest to.

I don't quite follow.

The theory seemed to be that this change would ok because humans writing LaTeX don't (or shouldn't) use \\ in math mode. I was providing something they very commonly do instead, which has no direct analogue in MathJax, and using \\ directly is the closest to.

Additionally, already in MathJax2 a\a results in a processing error in Jupyterlab. ๐Ÿค”

$a\\a$ works fine in currentish jupyter lab (up to date condaforge versions at least), so ๐Ÿค” indeed...

It works when using four slashes \\\\ instead of two \\ in markdown. see below:

\begin{align}
a_{11}& =b_{11}\\\\
  a_{22}& =b_{22}+c_{22}
\end{align}

bump, I think this should be relatively simple to fix?

dpvc commented

@octo-kumo

I think this should be relatively simple to fix?

It's not. It is part of the larger automatic line-breaking process, and that is quite complicated. It is planned for later this year, after the major font update that is currently in process.

It works when using four slashes \\\\ instead of two \\ in markdown. see

Just an FYI for anybody else running across this for markdown documents: I found that using four slashes (\\\\) was necessary to get the correct output on my Hugo site, but caused Typora editor to produce duplicate newlines.

Switching to \newline instead of \\\\ produces the correct results in both places:

\begin{align}
a_{11}& =b_{11}\newline
a_{22}& =b_{22}+c_{22}
\end{align}

Just an FYI for anybody else running across this for markdown documents: I found that using four slashes (\\\\) was necessary to get the correct output on my Hugo site, but caused Typora editor to produce duplicate newlines.

Switching to \newline instead of \\\\ produces the correct results in both places:

And making the command even shorter, you can use \cr for line breaks. That's the plain TeX command for the carriage return linebreak. This works in a Hugo blog and the same formula can compile with pdflatex.

@dpvc
Is it possibile to improve priority. Link-break is a important feature in some cases such as typeset.
Data typeset got broken migrated from version 2 which contains it.

Understand the complicated it is, and thanks for your work.

dpvc commented

@woody-li, line breaking support is under development and should be part of the major feature release at the end of the summer.

@dpvc I'm also interested in the auto line break feature and was trying to find some info regarding when "the major feature release at the end of the summer" is scheduled but haven't been able to find any date for is. Can you by any chance share info on when this release is expected? Thanks!

dpvc commented

I had hoped to have it out several weeks ago, but ran into some issues putting it all together. I am preparing an alpha release as we speak, and am planning to make it available this week.

The linebreaking code is in the linebreak branch of the MathJax-src repository, so theoretically, you could build a version yourself now if you wanted to see how it works.

dpvc commented

The v4.0.0-alpha.1 release was just made, and it includes the line-breaking implementation. See the release notes for extensive details. I encourage you to try it out. Please report problems by opening a new issue, not adding them here. Thanks.

So, still not working...

dpvc commented

@Humam-Hamdan, line breaking support is in v4.0-alpha released last year, and in the 4.0-beta released last week. The official v4.0 is planned for the end of August.

@dpvc ok, thx

@dpvc Hi again, currently on ver 4.1. but still not working.
$$f(x)=c;c \in \mathbb{R} \newline \mathbb{L} = \{y|y=c; c \in \mathbb{R}}$$
image

@Humam-Hamdan it seems you missed a backslash at the end. You should have \mathbb{R}\} instead of \mathbb{R}}. Also, change \newline to \\. Hope this helps!

Well, it didnโ€™t, tried the double slashes but sadly didnโ€™t work.

@Humam-Hamdan ok. What version of MathJax are you using? Please provide a minimal reproducible example if you can.

For example, if you open the following HTML file in your browser, you should see the equation properly rendered. The line break error will still be present if you replace the MathJax version 4.0.0-beta.3 by version 3.

<html>
  <head>
    <script>
      MathJax = {
        tex: {
          inlineMath: [
            ["$", "$"],
            ["$$", "$$"],
          ],
        },
        svg: { fontCache: "global" },
      };
    </script>
    <script
      id="MathJax-script" async
      src="https://cdn.jsdelivr.net/npm/mathjax@4.0.0-beta.3/tex-mml-chtml.js"
    ></script>
  </head>
  <body>
    $$f(x)=c;c \in \mathbb{R} \\ \mathbb{L} = \{y|y=c; c \in \mathbb{R}\}$$
  </body>
</html>

@Humam-Hamdan, there is no version 4.1, so I'm not sure which version you are using (4.0.0-alpha.1 maybe?). @nhpf's file works for me as expected, as it does when I change to 4.0.0-alpha.1 (and add the es5 directory), in case that's what you were using. It also works at 4.0.0-beta.4, which is the current beta release. This is an even smaller test file:

<!DOCTYPE html>
<html>
  <head>
    <script
      id="MathJax-script" async
      src="https://cdn.jsdelivr.net/npm/mathjax@4.0.0-beta.4/tex-chtml.js"
    ></script>
  </head>
  <body>
    $$f(x)=c;c \in \mathbb{R} \newline \mathbb{L} = \{y|y=c; c \in \mathbb{R}\}$$
  </body>
</html>

i copied and pasted the code, and here's the result.
also, i'm on version 0.4.1 (stable)
image

i'm on version 0.4.1 (stable)

This is not a MathJax version. What is it really that this is the version of? Some MathJax plugin for your content-management system?

Also, the output you show is not the output from the file that either @nhpf or I sent you, as the blackboard bold characters are different in the v4.0 beta versions.

When you say you copied and pasted, did you create a new blank file, say test.html on your local computer disk and past the examples into that, save it, and open the local file in a browser? Or did you past it into some content-management system that you are using? You should do the former, not the latter.

Oh Ok, I'm on obsidian, Thanks.

2024 and still no fix?
immagine

dpvc commented

still no fix?

@CaneMandarinesco, line breaking is supported in v4, which is currently in beta release. There will be at least one more beta version before an official release. The current beta is pretty close to the final version, but as this is a major update, all the ducks need to be in a row, and things have been pushed back, from our earlier planned release date.

This affects the latest version of Jupyter lab. I'm finding my \\ backslashes are ignored in array cells. It used to work.