Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
1  
I don't get it. If I put in the code \begin{align}\label{eq:x} x&=x \\ \label{eq:f} f(x)&=f(x) \end{align} then I can refer to them by \eqref{eq:x} and \eqref{eq:f}. What other solution you want? –  tohecz Feb 8 '13 at 20:09
2  
You need to distinguish between labels (assigned by the author in \label{<label name>}) and the actual equation number (assigned internally be several counters) that can be referred to by \eqref{<label name>} and similar ref commands. –  Qrrbrbirlbel Feb 8 '13 at 20:12
    
@tohecz yes, I want a way to automate the labeling process so that I don't have to write \label{eq:f} on every equation. –  Barefeg Feb 8 '13 at 21:11
2  
@Barefeg You do not need to label any equation unless you reference it, LaTeX will automatically number the equations and deal with inserted equations automatically. The label is an internal reference for you to manage cross references, it makes no sense to generate the labels automatically. –  David Carlisle Feb 8 '13 at 22:21
1  
@DavidCarlisle I know that I 'do not need to label an equation unless I make reference to it' but for me it's more efficient to label all of then so that if in any moment I need to reference an equation (I'm talking an ongoing project written in latex, not only typesetting notes from paper or similar) then it's as easy as looking at its label with showlabels package and writing it down. Instead, if I do like you say, then I have to go hunt that equation in some remote place in the code. In that case it makes sense to do it beforehand and automatically. –  Barefeg Feb 8 '13 at 23:05
show 3 more comments

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

share|improve this answer
    
You do use "anonymous" labels? I've hoped that it's something people don't do... :( –  tohecz Feb 8 '13 at 22:52
    
Section labels are definitely not anonymous. I also usually set relevant names for "important" equations. But sometimes there isn't really any name that would describe the equation well-enough (for example one in many intermediate results in a long calculation). And the ability to view context through the label replaces quite efficiently the need for an explicit name, in my opinion. –  T. Verron Feb 8 '13 at 23:20
    
Also, as the OP stated in a comment to his question, anonymous labels make sense in a workflow using showlabels from mathtools. This way, every equation has a label you can use later if needed. And then it will be time, if you want, to choose a more relevant label (it's a matter of a simple search-and-replace). But I still find it way better than blind-backtracking to the position of the equation, add the label, and then go back to where you were working. –  T. Verron Feb 8 '13 at 23:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.