Equivalent of LaTeX's \label and \ref in HTML

I have an FAQ in HTML (example) in which the questions refer to each other a lot. That means whenever we insert/delete/rearrange the questions, the numbering changes. LaTeX solves this very elegantly with \label and \ref -- you give items simple tags and LaTeX worries about converting to numbers in the final document.

How do people deal with that in HTML?

ADDED: Note that this is no problem if you don't have to actually refer to items by number, in which case you can set a tag with

<a name="foo">

and then link to it with

<a href="#foo">some non-numerical way to refer to foo</a>.

But I'm assuming "foo" has some auto-generated number, say from an <ol> list, and I want to use that number to refer to and link to it.

Answers


There is nothing like this in HTML.

The way you would normally solve this, is by having the HTML for the links generated, by either parsing the HTML itself and inserting the TOC (you can do that on the server, before you send the HTML out to the browser, or on the client, by traversing the DOM with a little piece of ECMAScript and simply collecting and inspecting all <a> elements) or generating the entire HTML document from a higher level source like a database, an XML document, markdown or – why not? – even LaΤΕΧ.


I know it's not widely supported by browsers, but you can do this using CSS counter. Also, consider using ids instead of names for your anchors.


Instead of \label{key} use <a name="key" />. Then link using <a href="#key">Link</a>.


PrinceXML can do that, but that's about it. I suppose it'd be best to use server-side scripting.


Here's how I ended up solving this with a php script:

http://yootles.com/genfaq

It's roughly as convenient as \label and \ref in LaTeX and even auto-generates the index of questions. And I put it on an etherpad instance which is handy when multiple people are contributing questions to the FAQ.


Need Your Help

UIImageView image not being removed when set to nil in uicollectionviewcell

ios uiimageview uiimage uicollectionview uicollectionviewcell

Basically what I am doing is taking an image of the view, applying a blur to it, and then using that as a blurred uiview overlay in reusable collection view cells in a simple uicollectionview.