[Tex/LaTex] How to automate the \label-ing of equations

cross-referencingequationskilenumbering

I'm not sure if the way LaTex works allows for automatically labeling of, for example, align environments. This would require that the environment has an internal counter. However, when placing an environment between two previously placed ones, the algorithm would give the last environment a different label that the one assigned in a previous compilation, which is not what we want.

However, would it be possible to build an external solution? One idea is based on the editor. Perhaps it is possible to assign that a shortcut inserts not only the code for the environment but also a code for the label which outputs a successive number every time one uses the shortcut.

I'm specially interested in a solution for this using Kile which is my main editor.

Best Answer

This is not a Kile solution, but an emacs one.

That editor and its AUCTeX-mode provide out-of-the-box automatic labelling of every labellable environment or command.

For example, when you type C-c C-s to insert a structure heading, after prompting you for the level of the heading and its title, it will insert the heading command into the document, together with a label based on these two information.

In the same way, typing C-c C-e to insert an environment and selecting the equation environment (or align, etc.) will insert the environment, together with a label of the form eq:nn where nn is the number of already generated labels +1.

Furthermode, if you combine it with the excellent reftex-mode, you can use its features to retrieve easily the label of an equation or a heading based on the context of this label (for example, the content of the equation environment or the title of the sectioning command associated with the label).

All these features, with suitable settings, will also work as you would expect in a multi-file document.