Page MenuHomePhabricator

Request for feature: automatic figure and equation (formula) numbering
Open, NormalPublic

Description

Author: cyril.buttay

Description:
Hi,

I'm struggling with figure and equation numbering in articles, because it has to be done manually at the moment. An automatic numbering system in the way of the cite.php extension would make it a lot simpler and would avoid errors when modifying an article. An identical system for equations would also be great.

The LaTeX code for this is very simple (at least from the user point of view!): the \label{<nameoftheanchor} command is used in the equation or the figure (and is respectively replaced during compilation by "(1)" or "Fig. 1") and the command \ref{<nameoftheanchor>} is placed wherever you need to refer to the label (and is respectively replaced at compilation-time by "(1)" or "figure 1").

I have no real idea of the amount of work such an extension would require (I had a look at Cite.php, and I can imagine it is quite a lot...), but I think it is of great importance for long Wikipedia articles (and might even be mandatory for Wikibooks!).

What do you think?

Cyril


Merged duplicate:
Sometimes pictures (tabulars, equations, etc.) are not described properly in the text. (=cannot directly be refered to, therefore...)
It is sometimes hard to figure out which picture is meant.

Reader of Wikipedia would benefit, because the picture which is described is named unambiguously.

Editors of Wikipedia will have an easy to use tool to address a certain picture in the text.

How is this problem being addressed now?

Sometimes the pictures are numbered by the editors.

This is inconvenient, when there are a lot of pictures in one article, and more pictures are added somewhere in the middle of the article.

What are the proposed solutions?

Each picture, which should get a number, is marked with a label-tag.

One can now address the picture by addressing to the label-tag.

This is similar to the references numbering in wikipedia and the picture numbering in latex.

--Boehm (talk) 23:39, 9 November 2015 (UTC)

This card tracks a proposal from the 2015 Community Wishlist Survey: https://meta.wikimedia.org/wiki/2015_Community_Wishlist_Survey

This proposal received 13 support votes, and was ranked #56 out of 107 proposals. https://meta.wikimedia.org/wiki/2015_Community_Wishlist_Survey/Multimedia#Automatic_numbering_of_pictures

Details

Reference
bz5600

Event Timeline

bzimport raised the priority of this task from to Low.
bzimport set Reference to bz5600.
bzimport added a subscriber: Unknown Object (MLST).
bzimport created this task.Apr 16 2006, 1:24 PM

ezyang wrote:

It shouldn't be too difficult. The biggest problem is forcing the system to
treat the resulting output as wikitext too... nothing on surmountable though. A
few cleverly placed global counters and a developer with SVN access to spearhead
it should make it work out. I could volunteer to write preliminary code.

cyril.buttay wrote:

I guess this enhancement is feasible, as this kind of feature exists in many
softwares, and its requirements look pretty close to those of the current "cite"
plugin. However, I don't know anything about MediaWiki or php, so I would spend
ages trying to implement it myself, and I would end up with a mix of security
holes and bugs... So please, if you think you could work on it, this feature
would be really helpful for long articles in wikipedia and wikibooks.

Cyril

Perhaps this could be done as a extension. Moving to extension requests.

This feature was also requested recently by a new user on Portuguese Wikibooks:
[[wikibooks:pt:Tópico:Utilizador Discussão:Rpez/Oi!/resposta (4)]]

dirk.hunniger wrote:

For Debian there is the mediawiki2latex package. It gives you the latex source. There you can easily enable the equation numbering.

physik wrote:

Is there a reason not to use templates for numbered equations.
Id's in the \latex style can be assigned by the id attribute of the math element.

physik wrote:

oups I wanted to write
Id's in the \label style can be assigned by the id attribute of the math element.

He7d3r added a comment.Sep 3 2014, 5:35 PM

That will not automatically generate the numbering, I think.

physik wrote:

OK. I was thinking there are templates that can benefit from css based numbering.
If that's not the case I'm happy to fix that problem.
The math extension can not look outside of the math tag.
There is a hook that could be used

wfRunHooks( 'MathFormulaRendered',
array( &$renderer,
&$renderedMath,
$parser->getTitle()->getArticleID(),
$parser->nextLinkID() ) );// Enables indexing of math formula

In practice $parser->nextLinkID() creates numbers 0 to n. But I think that's not guaranteed to be the case in the future.
For example http://demo.formulasearchengine.com/index.php/Spectrum_%28functional_analysis%29#math22
is the 23'th math tag that has been processed on that page.
Like MathSearch it would be simple to develop an extension that adds a custom tag for numbered equations. But I'm not sure if that's a feature that should go to the Math extension.
If you think that's a feature that should go to the math extension I'm happy to implement that... should not be hard at all.

physik wrote:

PS: It would be great if someone would use the https://www.mediawiki.org/wiki/Extension:Math/Roadmap#Wanted_features page. So we can see if something is really a wanted feature of if it's just an outdated bug from 2006... that's what I thought at a first look

He7d3r added a comment.Sep 3 2014, 6:34 PM

The main problem we need to solve is to provide a wiki equivalent syntax for the following simple feature of LaTeX, so that Mathematic and Physics books can be written collaboratively on Wikibooks projects:

[[b:Some book/Chapter 1]]

Let
\begin{equation}\label{foobar}
x = 1 + 2.
\end{equation}

Equation \eqref{foobar} is known as...

[[b:Some book/Chapter 2]]

By \eqref{foobar}, it follows that...

The automatically numbering is necessary not only for formulas in a single page, but also for several pages (chapters) of a single book. However, since not even <ref>s work like that yet (see bug 10092), a first step would be to allow cross references like the ones above in a single page.

Not having something like this prevent us from importing good quality content to Wikibooks projects.

physik wrote:

I see different problems. The label problem and the numbering and and numbered label generation problem. That might be independent of the Math extension since it applies to images as well.
I created a test page here
https://en.wikipedia.org/wiki/User:Physikerwelt/bug5600#foobar
to demonstrate what works today.
Basically the link could be replaced by an interwiki link to
[[w:User:Physikerwelt/bug5600#foobar]] to be a global reference.
I think a template should replace [[w:User:Physikerwelt/bug5600#foobar]] by
[[w:User:Physikerwelt/bug5600#foobar|equation reference]]
A global table of all equations is desired.
I see that a table of all equations would be helpful here. I implemented that for the MathSearch extension. (Recently I updated the fact that the references link to revisions and not pages. Just to be sure...)
But before we start to implement something we should exactly describe what we want to achieve.
For me it's still not clear what this bug is about.

He7d3r added a comment.Sep 3 2014, 7:58 PM

The main point is that the label for the link #foobar should be generated automatically, based on the number of equations (in the current page/book/etc). E.g. it would be like 1 in that page (since that is the first formula, and this number "1" should increase/update automatically - as in LaTeX - if another formula is added before it).

Any sort of counter like this would inherently be a side effect, which we're trying to move away from.

He7d3r added a comment.Sep 3 2014, 8:33 PM

Copying below the relevant conversation from today on #mediawiki-parsoid:

<helderwiki> didn't we have a change in the way references (from Cite) are automatically numbered? Any chance of using something similar to fix this?
<helderwiki> https://bugzilla.wikimedia.org/show_bug.cgi?id=5600#c9
<helderwiki> (change = using CSS or something)
<helderwiki> the link above is to a feature request: automatic figure and (math) equation numbering
<subbu> helderwiki that feature is not yet there. but, WIP.
<subbu> cite auto-numbering
<gwicke> helderwiki: visual numbering is fairly easy with CSS
<gwicke> it's already used for Parsoid content
<helderwiki> gwicke: subbu|coffee could you add any input to that bug? See the use case I mentioned on
<helderwiki> https://bugzilla.wikimedia.org/show_bug.cgi?id=5600#c11
<gwicke> helderwiki: it sounds like you'd like to reference formulas too, which goes beyond what CSS counters can do
<gwicke> you probably want to specify an id on the math tag
<gwicke> <math id="foobar">...</math>
<gwicke> which would just translate to that HTML id in the output
<gwicke> & can be displayed with CSS
<helderwiki> Added one more comment at https://bugzilla.wikimedia.org/show_bug.cgi?id=5600#c13
<helderwiki> gwicke: yeah, for one hand we want the numbering of the formulas to be added automatically (which could be done with CSS, I think), but it should be possible to reference these formulas by name in the wikitext, and "something" should be able to label it accordingly to the same (CSS?) number
<gwicke> it's possible to display either a counter or a label
<gwicke> using css
<helderwiki> jackmcbarn: could you elaborate what you mean by "side effect" in that context?
<helderwiki> WONTFIXING something like that would mean no Mathematics on Wikibooks projects... It is sad to hear that.
<gwicke> helderwiki: nobody said wontfix
<jackmcbarn> helderwiki: adding an equation at the top of the page would mean all of the rest of them would get renumbered
<jackmcbarn> gwicke: i did
<gwicke> oh, missed that
<gwicke> well, numbering for display is fine with css
<helderwiki> jackmcbarn: that is exactly the feature from tex which we are lacking in wikitext
<gwicke> for linking you want stable ids
<jackmcbarn> helderwiki: deliberately so
<jackmcbarn> it would be like Cite all over again
<helderwiki> and which is preventing us from convincing a few teachers to writte their books on Wikibooks collaborativelly
<gwicke> helderwiki: I don't see a problem really
<jackmcbarn> helderwiki: if you can find a css way to do that, you can do it, but what you asked for in the report would mean the parser would have to be in charge of numbering, which can't happen
<jackmcbarn> gwicke: the problem is they don't just want numbers on the equations. they want to be able to say "figure 1", etc. dynamically from the prose
<helderwiki> exactly!
<jackmcbarn> that's what the problem is
<gwicke> ah.. so not figure foobar
<helderwiki> but by referring to these formulae/figures by their labels/ids
<helderwiki> In latex source, it is like "foobar", but once we compile the document, the labels are generated automatically
<gwicke> helderwiki, jackmcbarn: that's definitely harder
<jackmcbarn> gwicke: wouldn't it be equivalent to another Cite?
<gwicke> is the numbering absolutely needed?
<helderwiki> yep. it is the way it works on Physics and Math texts nowadays (outside wikis)
<gwicke> "figure foo" could work from a functional pov
<gwicke> there is always JS
<jackmcbarn> helderwiki: if you know of any way to do it that would let you add an equation to the top of a page, and only have to parse it rather than reparse the entire page, then it'll be doable
<jackmcbarn> js would probably be the least bad solution
<gwicke> yeah, if CSS doesn't work & those labels absolutely need to be numbered rather than named..
<gwicke> it's worth considering the trade-offs carefully though
<helderwiki> where is the patch (WIP?) of the CSS implementation for the numbering of Cite refs?
<helderwiki> also, can I copy this log to Bugzilla?
<gwicke> helderwiki: the CSS for that is deployed
<helderwiki> hmm... it seems I missed that :-)
<gwicke> helderwiki: http://git.wikimedia.org/blob/mediawiki%2Fcore/8fde6c3da0eed6cdadb8372397c338ca04bf3a38/resources%2Fsrc%2Fmediawiki.skinning%2Fcontent.parsoid.less#L13
<gwicke> for auto-numbered external links
<gwicke> helderwiki: so it seems that it's not yet deployed for Cite
<subbu> helderwiki, for cite, marcoil is working on it and said he will have soemthing on friday.
<helderwiki> do we have things like "mw:ExtLink" in the HTML already?
<gwicke> in Parsoid HTML, yes
<gwicke> that's the HTML you see when you use VE or Flow
<helderwiki> ok
<helderwiki> its not used on normal page views yet, right?
<gwicke> not yet, yes
<gwicke> we are working on it ;)

He7d3r added a comment.Sep 3 2014, 8:56 PM

The problem of referencing the content generated automatically by CSS without using JavaScript is discussed here:
http://stackoverflow.com/q/16453488

physik wrote:

I think it gives a wrong impression to mark this bug as wontfix.

It's just not a problem of the Math extension. It's a more general problem:
We can create a new bug that describes what we really want.
What I got is:
"
Replace labels of links to an named HTML entities by an auto-generated subsequent number.
"

(In reply to physikerwelt from comment #17)

Replace labels of links to an named HTML entities by an auto-generated
subsequent number.

That would also be WONTFIX, for the same reason (unless you did it with JavaScript or something else hacky like that).

physik wrote:

I have no inside knowledge about WikiSource, but the title of the project indicates that the feature is required.

All sources contain numbered equations, figures, tables etc.

It is a major requirement to the MediaWiki software that those numbers will be added automatically. Technical limitations and performance optimizations are of minor importance.

So I can not understand the conclusion that this short coming will not be fixed (wontfix).

jitseniesen wrote:

How is Cite going to work around the restriction "Any sort of counter like this would inherently be a side effect, which we're trying to move away from." (comment 14).

In particular, in the following extract the footnote numbers of both <ref> tags have to be coincide and the links have to go to the same footnote:

Some statement.<ref name="source1">Details of source 1</ref>
...
Another statement supported by the same source.<ref name="source1" />

It would be helpful if the constraint on side effects is explained somewhere so that we know what we have to work around (or overturn).

Reopening since this is a necessary feature (even if its only possible implementation is based on JS)

physik wrote:

Do you think this issue is specific to the math extension. If not please change the product and component.

(In reply to Jitse Niesen from comment #20)

How is Cite going to work around the restriction "Any sort of counter like
this would inherently be a side effect, which we're trying to move away
from." (comment 14).

In particular, in the following extract the footnote numbers of both <ref>
tags have to be coincide and the links have to go to the same footnote:

Some statement.<ref name="source1">Details of source 1</ref>
...
Another statement supported by the same source.<ref name="source1" />

It would be helpful if the constraint on side effects is explained somewhere
so that we know what we have to work around (or overturn).

Parsoid includes its own implementation of Cite as an extra parsing pass, which gets used instead of the "real" Cite. Building and maintaining that is a lot of work for the Parsoid team, and it's the only way things with side effects can work under Parsoid.

physik wrote:

I would say that's good news. I think there is a way to separate the counter and reference generation from the cite extension. That said it would reduce he maintenance effort for the Parsoid team in the future.

removing wikisource, has not been a required functionality, and would generally be hard coded to match a work, especially where individual pages are being replicate, and would need anchors

jitseniesen wrote:

At least conceptually it should be possible to use Cite for formulas. The following wikitext in fact gives something close to what we want.

A standard limit is
:<ref name=sinlim> <math> \lim_{x\to0} \frac{\sin x}{x} = 1 </math> </ref>
We can proof <ref name=sinlim /> using l'Hopital's rule.

The main difference is that <ref> puts the contents in a footnote, while we want it to appear at the same location - this should actually simplify matters. Thus, if we could add an extra attribute to the ref tag like contentsLocation=here and get the Cite extension to honour this attribute, we're in business.

Then there is some styling to get right but that should not be too much of a problem. The same mechanism can also be used to refer to tables. To be clear, this gives only the possibility to refer to equations on the same page, not on other equations.

Are there any issues with this?

He7d3r updated the task description. (Show Details)Apr 26 2015, 6:00 PM
He7d3r added projects: Math, Parsoid, Wikisource.
He7d3r set Security to None.
Rpez added a subscriber: Rpez.Apr 26 2015, 7:01 PM
Rpez added a comment.Apr 26 2015, 7:27 PM

My main concern regards proper equation numbering on Wikibooks as it is preventing people from collaborating on technical books such as math, physics...
People used to LaTeX-style cross-reference won't write books without it. Please raise the priority on this feature request!!
A successful implementation of equation numbering for wikibooks would also allow cross-reference between pages and include automatic chapter numbering for pdf and epub export (e.g. Eq 1.10 for the 10th equation on chapter 1).
Thanks!

Rpez awarded a token.Apr 26 2015, 7:28 PM

There are two orthogonal challanges. One is to display the numbers and the other is to allow for cross references.
Cross references are possible today. In Math 2.0 the id tag can be used to assign names to equations.
For example

https://en.wikipedia.org/wiki/Mass%E2%80%93energy_equivalence#MassEnergyEquivalence

links to the first equation on that page.
All that needs to be done is to print the next to the equation for displaystyle equations and to reformat links like the link above.

I would prefere an implementation indepenedt of the math extension since the same mechanism should be used for tables and figures as well.

Physikerwelt raised the priority of this task from Low to Normal.May 16 2015, 2:12 PM
Physikerwelt removed a project: Math.

This IS relevant for the Math extension (in fact it is the main usecase for the feature, since [almost] all mathematicians use this in LaTeX).

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptAug 9 2015, 12:34 AM

@He7d3r Yes this is relevant for writing math, but not directly for the math extension. The math extension has done its part.
The id attribute is equivalent to the latex command \label. The implementation of \ref cannot be done within the same code that is responsible for the rendering of the math tags. Rendering the math tags must only depend on the input of a individual math tag and not of its surroundings

He7d3r rescinded a token.Aug 9 2015, 5:05 PM
He7d3r awarded a token.
Debenben added a subscriber: Debenben.

Hi all,
in the WikiToLearn project (see wikitech-l for a brief introduction of what we do), we would love to support this feature in a non-hacky way. Until recently we have been using MathJaX native capabilities to do that, which unfortunately forced us to impose it onto our users (ugh!).
I am willing to spend time into looking how to implement that (and actually doing it), but I really need a little guidance on where to look and how to best implement it. I also mention @cscott here because of his comment on T112991.

@cscott: Would it be possible to provide some feedback to T7600#1904261 (basic pointers)? Thanks in advance...

TheDJ added a subscriber: TheDJ.Dec 20 2017, 8:30 PM

This came up during the 2017 wishlist again:
https://meta.wikimedia.org/wiki/2017_Community_Wishlist_Survey/Editing/Automatically_create_a_reference_id_for_pictures_with_a_label

There was a suggestion for scholarpedia's <figref>
http://www.scholarpedia.org/w/index.php?title=Lattice_quantum_field_theory
It seems the code for that is not publicly available right now, but I guess someone could request that from them.