# KaTeX/KaTeX

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.

# Equation numbering #350

Open
opened this Issue Sep 10, 2015 · 24 comments

Projects
None yet
10 participants
Member

### kevinbarabash commented Sep 10, 2015

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

Closed

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.

Closed

Contributor

### utensil commented Oct 12, 2015

 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?
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.
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 commented Nov 23, 2015

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

### pnsaevik commented Nov 23, 2015

 BTW, if someone wants a hack in the meantime, place your TeX code in  tags, Einstein said:E = mc^2, and place the following script at the end of your HTML document:  I'm no javascript expert, so surely you can improve this code somehow..
Member

### kevinbarabash commented Nov 23, 2015

 @pnsaevik can you post some screenshots?

### 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: 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 commented Nov 24, 2015

 Kudos to you, @pnsaevik !
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.
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 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.
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 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.
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 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: HTML s KaTeX' internal CSS-table implementation CSS float or CSS absolute position On my own HTML pages, I'm currently going for the  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 
Formula goes here Equation number goes here
 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 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  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 commented Dec 1, 2015

 BTW, here is a CSS implementation of automatic equation numbering using the  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 commented Nov 13, 2016

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

Closed

### zeeshansayyed commented Aug 9, 2017

 Any updates on this issue?
Member

### kevinbarabash commented Aug 10, 2017 • edited

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

### pennestri commented Sep 10, 2017

 Dear Kevin, please look into the code that I wrote and posted on "Issues" and you will recognize that I already solved the problem. #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 : … @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 <#350 (comment)>, or mute the thread .

Closed

Merged

Closed

### jdhao commented May 18, 2018

 Is automatic equation numbering incorporated into katex?
Member

### kevinbarabash commented May 18, 2018

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

Open

Closed

Open

### edemaine referenced this issue Nov 20, 2018

Closed

#### Display block instead of inline-block and equation numbering #1785

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