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.

When working on a LaTeX document in Emacs align-current aligns & and \\, but does so for entire sections at a time. Anyone have any idea as to how one limits its range (in a new macro) to say the current environment?

I seldom need to do an align of anythis other than a matrix or a table.

My attempts to build something on top of align-regexp have not been successful.

Ideas?

Edit:

Given the following test data M-X align-current will normally align the &'s and \\'s, but on a sectional basis. I'd like them to work only on the current environment.

\begin{tabular}{xxx}
  a & bbbb & sdssd & \\
ccsssssss & jj& bb
\end{tabular}
\begin{tabular}{xxx}
      a & bbbb & sdssd & \\
cc & jj& bb
\end{tabular}

If I run it in this example, it aligned them in both tabulars at the same time.

share|improve this question
1  
I guess that this is not connected to LaTeX, otherwise you'd have posted it directly here. Probably you should make clearer what the question is about. –  egreg Jul 2 '12 at 15:28
    
@egreg: the most likely is that it has to do with emacs/AucTeX. Daleif, please confirm. –  Bruno Le Floch Jul 2 '12 at 17:39
    
hmm, I thought I did tag it, added emacs, auctex, elisp, it is about writing macros in Emacs. –  daleif Jul 3 '12 at 8:03
    
who can migrate it to somewhere more suitable, this is not a TeX question –  daleif Jul 3 '12 at 13:43
    
I'm not sure there is a more suitable place. Emacs questions fit equally well/poorly everywhere. –  Tyler Jul 24 '12 at 20:12
add comment

migrated from stackoverflow.com Jul 2 '12 at 15:19

This question came from our site for professional and enthusiast programmers.

1 Answer

align-current usually does the right thing for me. It only aligned multiple sections when there was no space before or after the \section macro. You can force align to stay within the current section with the following addition to your .emacs:

(defun align-section ()
  "Apply align to the current section only."
  (interactive)
  (save-excursion)
  (LaTeX-mark-section)
  (align (point) (mark)))

(defun align-environment ()
  "Apply align to the current environment only."
  (interactive)
  (save-excursion)
  (LaTeX-mark-environment)
  (align (point) (mark)))

Edit: I misunderstood the scope. The second function will limit the alignment to the current environment, not the whole section.

Note that this doesn't change align-current, but provides a new function to do what you want. Call it with M-x align-environment.

share|improve this answer
    
Not quite what is wanted, I want it to do this on an environment basis, buy then (LaTeX-mark-environment) should do the trick, I'll do some testing –  daleif Jul 25 '12 at 8:04
    
That does not do the same thing as align-current, see update –  daleif Jul 25 '12 at 8:13
    
Second one does not do anything for me. Did you test it under latex-mode and preferably with auctex installed? –  daleif Jul 26 '12 at 9:06
    
Yes, I just rechecked, copy and paste from my answer to emacs, and it aligns one but not both of the tables in your example. Auctex version 11.86, Emacs 24.1.50.2. –  Tyler Jul 26 '12 at 11:39
    
To clarify, the code above doesn't change the way align-current behaves. It provides align-environment as an alternative. So after running the code, you should use M-x align-environment instead of M-x align-current. –  Tyler Jul 26 '12 at 19:57
show 2 more comments

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.