5

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.

5
  • 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
    Commented Jul 2, 2012 at 15:28
  • @egreg: the most likely is that it has to do with emacs/AucTeX. Daleif, please confirm. Commented Jul 2, 2012 at 17:39
  • hmm, I thought I did tag it, added emacs, auctex, elisp, it is about writing macros in Emacs.
    – daleif
    Commented Jul 3, 2012 at 8:03
  • who can migrate it to somewhere more suitable, this is not a TeX question
    – daleif
    Commented Jul 3, 2012 at 13:43
  • I'm not sure there is a more suitable place. Emacs questions fit equally well/poorly everywhere.
    – Tyler
    Commented Jul 24, 2012 at 20:12

1 Answer 1

3

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.

10
  • 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
    Commented Jul 25, 2012 at 8:04
  • That does not do the same thing as align-current, see update
    – daleif
    Commented Jul 25, 2012 at 8:13
  • Second one does not do anything for me. Did you test it under latex-mode and preferably with auctex installed?
    – daleif
    Commented Jul 26, 2012 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
    Commented Jul 26, 2012 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
    Commented Jul 26, 2012 at 19:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .