Katex: Equation numbering

Created on 10 Sep 2015  Â·  29Comments  Â·  Source: KaTeX/KaTeX

Suggested by @RoyiAvital in https://github.com/Khan/KaTeX/issues/61. We'll want to support both display mode and inline mode.

enhancement

Most helpful comment

So, what's the current status on \tag?

All 29 comments

There are several issues to this which should be considered.

  • Explicit numbering using \tag. This is probably easiest, since it simply means taking the given number and putting it somewhere to the right of the equation. Since we don't support \\ outside array-like constructs, we don't have to worry about whether to apply one or multiple numbers in that case.
  • Equation environments with automatic numbering. Things like {equation}, {gather}, {align}. In my opinion, it would make sense to allow these only on the outermost level, i.e. if the environment starts at the very beginning of the input and ends just before the end, perhaps with some whitespace padding at either end. Personally I'd rather implement such top-level-only environments after #347 got merged and also after #266 resp. https://github.com/gagern/KaTeX/commit/e98b34ebee30238b108bc60969e3f952fb014b34 got implemented.
  • Consistent numbering across different KaTeX blocks. I imagine we'll want to allow some counter-holding object in the options, something like counters: {equation: 0}. Passing the same counters object to multiple invocations would ensure that the counters get incremented consistently across these invocations.

From http://docs.mathjax.org/en/latest/tex.html#automatic-equation-numbering :

Equations can be numbered in two ways: either number the AMSmath environments as LaTeX would, or number all displayed equations (the example above uses AMS-style numbering). Set autoNumber to "all" if you want every displayed equation to be numbered. You can use \notag or \nonumber to prevent individual equations from being numbered, and \tag{} can be used to override the usual equation number with your own symbol instead.

Note that the AMS environments come in two forms: starred and unstarred. The unstarred versions produce equation numbers (when autoNumber is set to "AMS") and the starred ones don’t.

You can use \label to give an equation an identifier that you can use to refer to it later, and then use \ref or \eqref within your document to insert the actual equation number at that location, as a reference.

Personally I'm used to this MathJax way, would KaTeX be similar?

@utensil I think we'd probably implement things using the progression that @gagern suggested. The \tag{} command is useful on it's own and can be used to number equations and is a lot easier to implement. Automatic numbering is harder, but if tag{} is implemented we can use that functionality when implementing automatic number.

@kevinbarabash Thanks for explaining. Now I see the reason and tag{} is indeed a good alternative in, say, math blog writing.

Implementation of tag{} before \begin{equation} is indeed a good idea!

BTW, if someone wants a hack in the meantime, place your TeX code in <dtex> tags,

Einstein said:<dtex>E = mc^2</dtex>,

and place the following script at the end of your HTML document:

<script>
    txlist = document.getElementsByTagName("dtex");
    for (var i = 0; i < txlist.length; i++) {
        var tx = txlist[i];
        var txtext = "\\displaystyle " + tx.textContent;
        var html = katex.renderToString(txtext, tx, { displayMode: true });
        html = "<div style='text-align:center'>" + html 
                   + "<span style='float:right'>(" + (i+1) + ")</span></div>";
        tx.innerHTML = html;
    }
</script>

I'm no javascript expert, so surely you can improve this code somehow..

@pnsaevik can you post some screenshots?

I improved the equation numbering and implemented some bibliography script as well. You can view the result at http://folk.uib.no/plo092/katex. This is how it looks on my computer:

image

I have not tested on anything other than the latest chrome and iexplore browsers. I should also point out that I changed the font, this seems to work fine.

Kudos to you, @pnsaevik !

Is that Calibri? I'd expect some things to be subtly mispositioned from changing the fonts but that does look pretty reasonable.

Looks pretty good. I noticed that the number (1) isn't centered vertically, but that shouldn't be too hard to fix.

The font change is a little experiment on my part. It's Charis SIL with some extra letter spacing (certainly not Calibri, which is sans-serif and licence restricted). It looks nice, but certain things _are_ definitely mispositioned. And the greek letters doesn't always blend in nicely with the latin ones.

I'm sure the vertical alignment of (1) can be fixed, but I'm unsure if I can do it outside KaTeX. Multi-line equation numbering would also be somewhat challenging outside KaTeX.

Sorry, I meant Cambria which does look at least somewhat similar. I thought of it because I knew it had a math variant. It is non-free but it comes with Office so it's decently common.

Cambria would definitely be an alternative, but you would have to rely on the user to have it installed, since common Office installations doesn't include a webfont license. Besides, the mathfont version (Cambria Math) bundles all glyphs (italic, bold, symbols and operators) in a single file, and I'm unsure of how to extract them for use on a web page.

Another alternative would be Linux Libertine which has decent greek glyphs. But I find the strokes slightly too thin for web usage.

I'm sure the vertical alignment of (1) can be fixed, but I'm unsure if I can do it outside KaTeX. Multi-line equation numbering would also be somewhat challenging outside KaTeX.

Agreed. This is something that we'd want to add to KaTeX.

I just browsed through some issues relating to equation numbering, and I'd have to say I'm impressed with all the exciting work going on here!

Regarding \tag{} implementation, it seems like there are three ways of doing this:

  1. HTML <table>s
  2. KaTeX' internal CSS-table implementation
  3. CSS float or CSS absolute position

On my own HTML pages, I'm currently going for the <table> solution, but I understand from browsing the GitHub issues that consistent browser behavior is not guaranteed since the table layout algorithm is not specified. My implementation goes like

<table style="width: 100%">
<td style="width: 10000px;"></td>
<td>Formula goes here</td>
<td style="width: 10000px; text-align: right;">Equation number goes here</td>
</table>

which seems to work nicely for me at least.

Which brings be to method number 2: KaTeX has its own CSS implementation of table-like structures, which is used for the matrix environments and @gagern 's awsome addition (#398): The aligned environment. If HTML <table>s are out of the question, can we use KaTeX' internal CSS table representation to implement equation numbering in a way analogous to my own <table> implementation?

The solution I posted previously is method number 3. Seems to work fine, except that equation numbers are not vertically aligned. Could be fixed by letting KaTeX add some extra margin on top of the equation number, which would be possible since KaTeX knows the height of the current equation line.

BTW, here is a CSS implementation of automatic equation numbering using the <table> idea, which integrates with the current KaTeX release:

.katex-display {
    display: table;
    width: 100%;
}

.katex-display>.katex {
    display: table-cell;
}

.katex-display::before, .katex-display::after {
    width: 10000px;
    display: table-cell;
    text-align: right;
    vertical-align: middle;
}

body {
    counter-reset: equnum;
}

.katex-display::after {
    counter-increment: eqnum;
    content: "(" counter(eqnum) ")";
}

A similar CSS implementation of the float idea, with top-aligned equation numbers, is

body {
    counter-reset: equnum;
}

.katex-display::after {
    counter-increment: eqnum;
    content: "(" counter(eqnum) ")";
    float: right;
}

So, what's the current status on \tag?

Any updates on this issue?

@zeeshansayyed no updates, but we definitely would like to support \tag and equation number.

Dear Kevin,
please look into the code that I wrote and posted on "Issues"
and you will recognize that I already solved the problem.

https://github.com/Khan/KaTeX/issues/571

You are welcome to use the code in a new version of KaTeX.
Let me know if you wish more help from my side.
Sincerely
Pietro

2017-08-10 4:14 GMT+02:00 Kevin Barabash notifications@github.com:

@zeeshansayyed https://github.com/zeeshansayyed no updates we
definitely would like to support \tag and equation number.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/Khan/KaTeX/issues/350#issuecomment-321431253, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AEcWB3xFhx0rvO7bH2gQLy_E7GIfLdIdks5sWmeIgaJpZM4F7UwO
.

Is automatic equation numbering incorporated into katex?

@jdhao #1309 adds \tag which is a step towards equation numbering.

Sorry to bother, is auto increasing labels for equations (instead of \tag{...}) implemented now?

@pennestri thanks for linking to that issue and linking to your code. I wasn't able to access the demo link because of a NET::ERR_CERT_COMMON_NAME_INVALID issue.

@upupming auto-increasing labels have not be added yet.

Dear Kevin,
I am sorry NET::ERR_CERT_COMMON_NAME_INVALID, I will fix it as soon as
possible.
Pietro

Il giorno gio 11 lug 2019 alle ore 03:59 Kevin Barabash <
[email protected]> ha scritto:

@pennestri https://github.com/pennestri thanks for linking to that
issue and linking to your code. I wasn't able to access the demo link
because of a NET::ERR_CERT_COMMON_NAME_INVALID issue.

@upupming https://github.com/upupming auto-increasing labels have not
be added yet.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/KaTeX/KaTeX/issues/350?email_source=notifications&email_token=ABDRMB7M46RBO4EMURW6HRDP62HW7A5CNFSM4BPNJQHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZVICCQ#issuecomment-510296330,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABDRMB4NWGEFXIH7VC2YSULP62HW7ANCNFSM4BPNJQHA
.

Ciao,

Ho appena firmato la petizione "Facciamo valere i diritti dei caregiver
nelle università!" e vorrei chiederti di aiutarci aggiungendo il tuo nome.

Il nostro obiettivo è quello di raggiungere 150.000 firme e abbiamo bisogno
del tuo sostegno. Puoi saperne di più e leggere la petizione qui:

http://chng.it/QfMcRYQwRk

Grazie!
Pietro

Closed via PR#1309 and PR#2369.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mpolyak picture mpolyak  Â·  3Comments

janosh picture janosh  Â·  4Comments

asmeurer picture asmeurer  Â·  3Comments

jason-s picture jason-s  Â·  3Comments

OisinMoran picture OisinMoran  Â·  4Comments