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

Equation numbering #350

Open
kevinbarabash opened this Issue Sep 10, 2015 · 24 comments

Comments

Projects
None yet
10 participants
@kevinbarabash
Copy link
Member

kevinbarabash commented Sep 10, 2015

Suggested by @RoyiAvital in #61. We'll want to support both display mode and inline mode.

@gagern

This comment has been minimized.

Copy link
Collaborator

gagern commented Sep 11, 2015

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. gagern@e98b34e 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.
@utensil

This comment has been minimized.

Copy link
Contributor

utensil commented Oct 12, 2015

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?

@kevinbarabash

This comment has been minimized.

Copy link
Member

kevinbarabash commented Oct 12, 2015

@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.

@utensil

This comment has been minimized.

Copy link
Contributor

utensil commented Oct 13, 2015

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

@pnsaevik

This comment has been minimized.

Copy link

pnsaevik commented Nov 23, 2015

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

@pnsaevik

This comment has been minimized.

Copy link

pnsaevik commented Nov 23, 2015

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..

@kevinbarabash

This comment has been minimized.

Copy link
Member

kevinbarabash commented Nov 23, 2015

@pnsaevik can you post some screenshots?

@pnsaevik

This comment has been minimized.

Copy link

pnsaevik commented Nov 24, 2015

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.

@PeterBocan

This comment has been minimized.

Copy link

PeterBocan commented Nov 24, 2015

Kudos to you, @pnsaevik !

@sophiebits

This comment has been minimized.

Copy link
Contributor

sophiebits commented Nov 24, 2015

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

@kevinbarabash

This comment has been minimized.

Copy link
Member

kevinbarabash commented Nov 24, 2015

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

@pnsaevik

This comment has been minimized.

Copy link

pnsaevik commented Nov 25, 2015

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.

@sophiebits

This comment has been minimized.

Copy link
Contributor

sophiebits commented Nov 25, 2015

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.

@pnsaevik

This comment has been minimized.

Copy link

pnsaevik commented Nov 25, 2015

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.

@kevinbarabash

This comment has been minimized.

Copy link
Member

kevinbarabash commented Nov 25, 2015

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.

@pnsaevik

This comment has been minimized.

Copy link

pnsaevik commented Dec 1, 2015

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.

@pnsaevik

This comment has been minimized.

Copy link

pnsaevik commented Dec 1, 2015

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;
}
@zhy0

This comment has been minimized.

Copy link

zhy0 commented Nov 13, 2016

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

@pennestri

This comment has been minimized.

Copy link

pennestri commented Nov 28, 2016

@zeeshansayyed

This comment has been minimized.

Copy link

zeeshansayyed commented Aug 9, 2017

Any updates on this issue?

@kevinbarabash

This comment has been minimized.

Copy link
Member

kevinbarabash commented Aug 10, 2017

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

@pennestri

This comment has been minimized.

Copy link

pennestri commented Sep 10, 2017

@jdhao

This comment has been minimized.

Copy link

jdhao commented May 18, 2018

Is automatic equation numbering incorporated into katex?

@kevinbarabash

This comment has been minimized.

Copy link
Member

kevinbarabash commented May 18, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment