Katex: Support for "equation" environment

Created on 3 Mar 2016  Â·  24Comments  Â·  Source: KaTeX/KaTeX

It seems that multi-line auto rendering is not possible for the moment.

For example:

\begin{equation}
  x = a_0 + \cfrac{1}{a_1
          + \cfrac{1}{a_2
          + \cfrac{1}{a_3 + \cfrac{1}{a_4} } } }
\end{equation}

Here is the exception:

KaTeX auto-render: Failed to parse `
    \begin{equation}
    x = a_0 + \cfrac{1}{a_1
            + \cfrac{1}{a_2
            + \cfrac{1}{a_3 + \cfrac{1}{a_4} } } }
  \end{equation}\frac{1}{2} 
    ` with  Error: KaTeX parse error: No such environment: equation at position 21: begin{equation}̲

Any ideas ?

enhancement

Most helpful comment

It is possible to add very basic support for \begin{equation} ... \end{equation} by specifying a custom delimiter in auto-render. For example:

renderMathInElement(document.body, {
  delimiters: [
    {left: "$$", right: "$$", display: true},
    {left: "\\(", right: "\\)", display: false},
    {left: "\\[", right: "\\]", display: true},
    {left: "\\begin{equation}", right: "\\end{equation}", display: true}
  ]
});

See https://codepen.io/edemaine/pen/EpNamj for a demo.

However, equation numbering isn't supported yet; #350 tracks that. Note that manual numbering via \tag is possible, though.

All 24 comments

The equation env has not been implemented yet...

But the aligned* is implemented according to the wiki page: https://github.com/Khan/KaTeX/wiki/Function-Support-in-KaTeX

It does not work neither.

\begin{aligned}
a&=b&c&=d\\
e&=f
\end{aligned}

It gives No such environment: aligned* exception

I also tried array.

\begin{array}{ccc}
a&=&b&c&=&d\\
e&=&f
\end{array}

array env works.

It seems that aligned is not recognized by the environment.
https://github.com/Khan/KaTeX/blob/master/src/Parser.js#L428

aligned is supported on master but not in the most recent release. I can see how the wiki page is a little confusing. The * after aligned is supposed indicate that there is a note at the bottom of the wiki page that states *Committed to master but not part of the most current release.

(I replaced * with † to make things less confusing maybe)

Thank you for the clarification. =)

@invkrh I also hope for the implementation of \begin {equation} for Katex. It would be fantastic.

It is possible to add very basic support for \begin{equation} ... \end{equation} by specifying a custom delimiter in auto-render. For example:

renderMathInElement(document.body, {
  delimiters: [
    {left: "$$", right: "$$", display: true},
    {left: "\\(", right: "\\)", display: false},
    {left: "\\[", right: "\\]", display: true},
    {left: "\\begin{equation}", right: "\\end{equation}", display: true}
  ]
});

See https://codepen.io/edemaine/pen/EpNamj for a demo.

However, equation numbering isn't supported yet; #350 tracks that. Note that manual numbering via \tag is possible, though.

@edigleyalexandre You can add support for $ by adding another delimiter to the list.

@edemaine I added but it did not work.

@edigleyalexandre It matters where in the list things are placed. Be sure that "$" comes after "$$", as in:

renderMathInElement(document.body, {
  delimiters: [
    {left: "$$", right: "$$", display: true},
    {left: "$", right: "$", display: true},
    {left: "\\(", right: "\\)", display: false},
    {left: "\\[", right: "\\]", display: true},
    {left: "\\begin{equation}", right: "\\end{equation}", display: true}
  ]
});

I added as indicated, but it does not render. Look here.

@edigleyalexandre Can you be specific about an example of $...$ text that doesn't render? I tried adding an example to your page, then running the same renderMathInElement, and it worked fine. You might be running into the ignoredTags setting, because you have $...$ text inside <code>...</code> elements; see https://github.com/Khan/KaTeX/tree/master/contrib/auto-render for documentation.

P.S. @ronkok Probably meant display: false as in {left: "$", right: "$", display: false},

@edemaine Here's how to get with Mathjax. On here. The idea is to leave it with Katex. The page shows code and rendering.

\begin {matrix} and \begin {cases} are supported on Katex. I tested the main page of the Katex website and rendered it, but the blog did not render. What happened? Page with \begin {cases} that did not render.

Well, you did omit a comma that should follow {left: "\(", right: "\)", display: false}. I don't know if that by itself is enough to stop the script.

It worked. Forgive me for that.

This is still the problem. It is impossible to render equation-based environments such as

Environment `\begin{equation}...\end{equation}`
with auto-numbering:

\begin{equation}
h(z) = \sinh(z)
\end{equation}

---

Environment `\begin{equation}...(\#eq:label)\end{equation}`
with auto-numbering and label (for bookdown):

\begin{equation}
  f\left(k\right) = \binom{n}{k} p^k\left(1-p\right)^{n-k}
  (\#eq:binom)
\end{equation}

---

Environment `\begin{equation}...\label{label}\end{equation}`
with auto-numbering label for xaringan

\begin{equation}
  g\left(k\right) = \binom{n}{k} p^k\left(1-p\right)^{n-k}
\label{binom2}
\end{equation}

in several Markdown editors - see at least https://github.com/benweet/stackedit/issues/1424 and https://github.com/laurent22/joplin/issues/2212 .

omg. This is awesome!

Looks like it is not fixed, for example Joplin do not show \begin{equation}...\end{equation} blocks.

\begin{equation}...\end{equation} is so common in LaTex, why not consider to support this ?

Closed via PR#2369.

Screenshot 2020-10-28 at 3 58 02 PM
`Without equation, it is working as overflow: scroll

$Ta{n^{ - 1}}\left( {\cfrac{{3x - {x^3}}}{{1 - 3{x^2}}}} \right)Ta{n^{ - 1}}\left( {\cfrac{{3x - {x^3}}}{{1 - 3{x^2}}}} \right)Ta{n^{ - 1}}\left( {\cfrac{{3x - {x^3}}}{{1 - 3{x^2}}}} \right)Ta{n^{ - 1}}\left( {\cfrac{{3x - {x^3}}}{{1 - 3{x^2}}}} \right)Ta{n^{ - 1}}\left( {\cfrac{{3x - {x^3}}}{{1 - 3{x^2}}}} \right)$

Without array it is working as expected (Breaking properly)
\begin{equation}
Ta{n^{ - 1}}\left( {\cfrac{{3x - {x^3}}}{{1 - 3{x^2}}}} \right)Ta{n^{ - 1}}\left( {\cfrac{{3x - {x^3}}}{{1 - 3{x^2}}}} \right)Ta{n^{ - 1}}\left( {\cfrac{{3x - {x^3}}}{{1 - 3{x^2}}}} \right)Ta{n^{ - 1}}\left( {\cfrac{{3x - {x^3}}}{{1 - 3{x^2}}}} \right)Ta{n^{ - 1}}\left( {\cfrac{{3x - {x^3}}}{{1 - 3{x^2}}}} \right)
\end{equation}

With array and without equation (Not Breaking properly, overflow is scrolling)

  1. $3Ta{n^{ - 1}}x$$=\left{\begin{array}{ccc} Ta{n^{ - 1}}\left( {\cfrac{{3x - {x^3}}}{{1 - 3{x^2}}}} \right), & if\;\cfrac{{ - 1}}{{\sqrt 3 }} < x < \cfrac{1}{{\sqrt 3 }} <= \cfrac{1}{{\sqrt 4 }} <= \cfrac{1}{{\sqrt 4 }} <= \cfrac{1}{{\sqrt 4 }} \ \end{array}\right.$

With array and with equation it is not working as expected (Curly braces has problem) - THIS IS MY ISSUE
$3Ta{n^{ - 1}}x$$=\left{\begin{array}{ccc} \begin{equation}
Ta{n^{ - 1}}\left( {\cfrac{{3x - {x^3}}}{{1 - 3{x^2}}}} \right)Ta{n^{ - 1}}\left( {\cfrac{{3x - {x^3}}}{{1 - 3{x^2}}}} \right)Ta{n^{ - 1}}\left( {\cfrac{{3x - {x^3}}}{{1 - 3{x^2}}}} \right)Ta{n^{ - 1}}\left( {\cfrac{{3x - {x^3}}}{{1 - 3{x^2}}}} \right)Ta{n^{ - 1}}\left( {\cfrac{{3x - {x^3}}}{{1 - 3{x^2}}}} \right) \end{equation}
\end{array}\right}$
`

ISSUE: Why if I add an equation inside an array it's breaking?

@Varun-msd Soft line breaks occur after top-level relations and binary operators. If you wrap an equation environment or an array environment around some math, then the nested operators are no longer top-level.

Why was it programmed to work this way? Because KaTeX emulates TeX and that is the way TeX does soft line breaks. It is so specified in The TeXbook on page 173.

So @ronkok you say that we can't achieve the solution of my problem in Katex ? , my question is because it works in MathJax 2.0 but not in MathJax 3.0 (as they don't support line breaking till now)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fabiospampinato picture fabiospampinato  Â·  4Comments

oddhack picture oddhack  Â·  3Comments

mbourne picture mbourne  Â·  3Comments

pyramation picture pyramation  Â·  4Comments

OisinMoran picture OisinMoran  Â·  4Comments