| Print dvi | usdvi |

# LaTeX-tab.el Documentation

### Christophe Deleuze

Abstract: LaTeX-tab.el is a simple Emacs-lisp package designed to ease the editing of tabular-like LaTeX environnements. It integrates nicely with emacs’ AUCTEX package.

## 1  Introduction

LaTeX-tab.el is a (rather) simple Emacs-lisp package designed to ease the editing of LaTeX tabulars (and friends1). It needs to have AUCTEX[1] installed and integrates nicely with it. The only functionality it currently provides is the ability to format tabulars so that they’re easy to read (and so to edit) in your emacs buffer.

It has been tested with emacs version 21, but should work on about any version of emacs and xemacs.

## 2  Installation

First you need to find out where AUCTEX is installed. It is probably something like /usr/share/emacs/site-lisp/ (or /usr/local/share/...). In this place there’s a startup file called tex-site.el and an auctex directory. Simply copy latextab.el in the auctex directory and put the following two lines at the end of the tex-site.el file2:

(autoload 'ltxtab-init "latextab" "" t)


By default, AUCTEX’s LaTeX-fill-environment function is overriden so that LaTeX-tab.el’s ltxtab-format function is called if the current environment happens to be one of the array family. You should then use AUCTEX menu entry LaTeX/Formatting and Marking/Format Environment or the associated key sequence (C-c C-q C-e by default).

Alternatively, you may choose not to override any AUCTEX functionnality. This is done by setting ltxtab-override-auctex to nil. A new menu entry LaTeX/Formatting and Marking/Format Tab is created, associated with the C-c C-q C-t key sequence.

## 3  Usage

All LaTeX-tab.el functionnality is provided by the ltxtab-format command which can always be called directly from the minibuffer (M-x ltxtab-format). Other ways to run the command from menus and keystrokes depend on the chosen configuration, see previous section.

### 3.1  Basic usage

Suppose you have edited this simple tabular:

\begin{tabular}{cccc}
1 & 2 & 3 & 4 \\
\hline
one & two & three   & four \\
\end{tabular}


When the point is inside3 the tabular (or friend), simply execute the ltxtab-format emacs command, and the tabular is formated so that columns are aligned, which makes it much more readable:

\begin{tabular}{cccc}
1  &  2  &   3   & 4 \\
\hline
one & two & three & four \\
\end{tabular}


More precisely, what LaTeX-tab.el does is:

1. “compress” all cells (put just one white space between &s and cell material),
2. compute the max width of cells for each column to be the column width,
3. expand cells to their column width.

If you then edit the tab again, don’t bother to preserve the alignement of columns, just mess everything up and run ltxtab-format again when you’re done.

### 3.2  Forcing column width

ltxtab-format will always choose the minimum possible size for each column (i.e. the size of the widest cell in the column, after compression). Sometimes, you want some columns to be widest then that. An easy way to do that is to insert a fake (i.e. commented out) tab line. ltxtab-format will consider this line along with the others to compute the width of each column.

For example, if you want the second column to be at least 8 characters wide, you can insert a fake tabular line like that :

\begin{tabular}{cccc}
%    & -------- &
1  &  2  &   3   & 4 \\
\hline
one & two & three & four \\
\end{tabular}


ltxtab-format will then format it this way:

\begin{tabular}{cccc}
%  & -------- &
1  &    2     &   3   & 4 \\
\hline
one &   two    & three & four \\
\end{tabular}


Note that the fake line is compressed just as the others, so don’t put just white spaces in it!

### 3.3  Complex tabulars

LaTeX allows you to omit empty cells at the end of a row. LaTeX-tab.el has no problem dealing with that. More importantly, LaTeX-tab.el knows how to deal with LaTeX’s \multicolumn command. Thus:

\begin{tabular}{cccccc}
%    & -------- &
1 & 2 & 3 & 3' & 3'' & 4 \\
\hline
one & two & \multicolumn{3}{c}{three} & four \\
uno & dos & tres & tres & tres & quatro
\end{tabular}


is formatted as:

\begin{tabular}{cccccc}
%  & -------- &
1  &    2     &  3   &  3'  &     3''     & 4 \\
\hline
one &   two    & \multicolumn{3}{c}{three} & four \\
uno &   dos    & tres & tres &    tres     & quatro
\end{tabular}


Well, I admit this could be improved :-)

### 3.4  Specifying alignement info

By default, cell expansion (step 3 above) is made in such a way that cell content is centered. You can ask ltxtab-format to perform expansion so that content is either left or right aligned (on a per column basis4). To do that, call ltxtab-format with a numeric prefix arg. Emacs then prompts you for a string of the form llccrr: each character in the string specifies how content in a column is to be aligned, l meaning align on the left and so on. Example:

M-0 M-x ltxtab-format
Alignement info: llrr

\begin{tabular}{cccc}
1   & 2   &     3 & 4 \\
\hline
one & two & three & four \\
\end{tabular}


Note that, as appears in the previous example, you can’t right-align the last column.

## 4  Feedback

For any problem, question, or whatever, send me a mail to latextab@free.fr (please include the word “latextab” in the subject). For a bug report, make sure you tell me what version of LaTeX-tab.el you’re using and try to provide a minimal example where things go wrong.

## References

[1]
AUCTEX. Emacs package. [ url ]

## 5  Revision history

??          Nov 2002     creation

0.5       5 Sep 2003     public diffusion

0.6      18 Jun 2004     \&'s bug fix by Joachim Schlosser
<joachim at schlosser dot info>

0.61      9 Dec 2008     always require 'cl
(previously only for emacs versions < 21)

0.7 series triggered by bug reports from
Lukasz Klich <klich.lukasz at gmail dot com>

0.7      30 Aug 2010     handle included environment

0.71     31 Aug 2010     multicolumn

0.72      4 Sep 2010     remove tabulations


1
The recognized environments are defined in the ltxtab-envlist variable.
2
If you later upgrade AUCTEX you may need to redo this, so keep a copy of the two files.
3
i.e. between the begin and end parts.
4
Of course, this formatting only affects the way things look in your emacs buffer, not in the document typeset by LaTeX.

http://christophe.deleuze.free.fr/D/latextab.html  –  Page generated on  ,