[TxMt] Summary/Plug for LaTeX in TextMate
Charilaos Skiadas
skiadas at hanover.edu
Sat Dec 9 00:42:42 UTC 2006
I recently sent an email to the MacTeX mailing list, in response to
someone's question about what each editor for LateX has going for
them. It is a long post talking about some of the major things in the
bundle, so I thought it might be of interest/useful to some people in
this list. Appended:
Haris
A lot of these things are documented in many places, so to begin with
I will add some links to resources, and then will talk about some of
the things it can do well, IMHO.
1. First and foremost, there are a number of screencasts I've done,
along with blog posts, a lot of them on the LaTeX bundle. They are here:
http://skiadas.dcostanet.net/afterthought/list-of-my-textmate-pages/
Also see here for more TextMate screencasts: http://macromates.com/
screencasts
2. The online TextMate manual is a key resource of information. There
you can learn about:
1. snippets (http://macromates.com/textmate/manual/
snippets#snippets). These are easy to create yourself for common
repeatable code (and so much more).
2. project navigation (http://macromates.com/textmate/manual/
working_with_multiple_files#moving_between_files_with_grace)
3. Find and Replace in multiple files (option regexp included)
(http://macromates.com/textmate/manual/
working_with_multiple_files#find_and_replace_in_projects)
4. Navigating within a single file (http://macromates.com/textmate/
manual/navigation_overview#navigation_overview)
5. Moving text (http://macromates.com/textmate/manual/
working_with_text#moving_text)
6. Setting up your preferred color arrangement via themes: (http://
macromates.com/textmate/manual/themes#themes)
Now I'll talk about the LaTeX-specific commands in TextMate. I will
not refer to their shortcuts, because you can set these to whatever
you like, though they do have some reasonable defaults. You can see
these commands using ctrl-esc and navigating into the LaTeX bundle.
The help file for the bundle is here, in markdown format: (http://
macromates.com/svn/Bundles/trunk/Bundles/Latex.tmbundle/Support/
help.markdown). From within TextMate this can be accessed through the
Bundle's help command.
Hm, perhaps I should explain what Bundles are very briefly. There is
a core TextMate program, which offers the ability to extend it by
creating Bundles, which are collections of rules, commands and
preferences on how TextMate should act in particular languages. In
some sense a lot of the power of TextMate is in these bundles. The
bundles have a very open license (http://macromates.com/svn/Bundles/
trunk/LICENSE), and are being maintained by a large group of
volunteers. The list of languages supported is quite extensive
(http://macromates.com/svn/Bundles/trunk/Bundles/). The success of
TextMate is largely due to this power it provides to the bundle. It
is easy for people to add functionality to TextMate, in a similar way
as one would add functionality to emacs or vi, with the difference
that it is a lot easier for "newbies" to add functionality.
Ok, on to the bundle then. First of all, you don't need any
customizing to begin with. Dragging a LaTeX document onto the
TextMate icon should just open it with TextMate and set you to LaTeX
mode. To start a new document, you can use the Templates found under
the file menu, or you can start from a scratch file. The moment you
save the file with extension .tex, TextMate will recognize it as a
LaTeX file and color it accordingly.
1. Now first of all, creating environments. TextMate has a command
called "Insert Environment Based On Current Word", triggered by
command-{ (which is command-shift-[ in US keyboards, (command
key=apple key)). You can even use this without a word and it will
offer you a list of environments to insert. If you type in a word
first, then TM creates an environment based on this word. For
instance, typing "en" or "enum" and then the command trigger (cmd-{)
will insert:
\begin{enumerate}
\item
\end{enumerate}
and place the caret right after the \item thing. When you are done
with the first item, pressing Enter (fn-return on laptops) inserts a
newline and a new \item entry. Similar behavior for "it", "item" for
itemize etc. You can further customize this list to your heart's
content by using the "Edit Configuration File" command in the LaTeX
Bundle. For me a typical workflow these days is using the exam class.
The "words" "q", "p" and "sol", followed by command-{, produce the
"questions", "parts" and "solution" environments respectively.
2. There is a similar command for inserting common commands, called
"Insert Command Based On Current Word". This is triggered by
command-}, and functions in a similar way. for instance "l" becomes
"\lim_{}" with the caret inside the braces. Once you are done adding
things there, pressing tab takes you out of the braces.
3. The LaTeX bundle offers context-sensitive completion, via the
common "esc" key. For instance, when typing a command, it will
complete only with respect to commands, and not every word in the
text. It will use any commands you have introduced before, as well as
a stock list of commands. For instance typing "\dis" and pressing
escape converts it to "\displaystyle". Typing "\di" and pressing
escape multiple times cycles through all commands starting with \di.
On the other hand, if you are inside a \ref{}, then it completes with
respect to all keys found in \label{} commands within the current
document or any tex file included in your "root document" (called
master document in TM). Similarly, inside a \cite{} it will offer
completion with respect to all bibliography keys in your bib file and/
or any \bibitem's in your document. Also, option-esc will offer you a
popup of all completion matches, similar to the BibDesk completion
plugin that BibDesk offers (though I think that plugin is a lot
closer to XCode style completion, anyway...).
4. Image drag and drop. You can drag and drop any image into the
text, and an appropriate figure environment will be created, with the
accompanying \includegraphics command. By pressing modifier keys,
option or shift in this instance, you can adjust whether you want the
entire figure environment, or just a simple \begin{center}
\includegraphics...\end{center} thing, or the \includegraphics by
itself. And these can to some extend be customized.
5. Table conversion. You can create a table by first typing the
entries into rows, with columns separated by tabs, like so:
one two three
four five six
and select it and run a command, and it will become:
\begin{tabular}{ccc}
\hline
one & two & three\\
\hline
four & five & six\\
\hline
\end{tabular}
Similarly, you can create a new table with a prescribed number of
rows and columns.
6. Wrapping things. You can tell TextMate to wrap the current
selection in a command. Suppose for instance you just typed the
sentence "foo bar" and what to higlight it, so to include it in
\emph. In TextMate, you would select it by pressing opt-left arrow
twice, and then press ctrl-shift-w. This results in:
"\emph{foo bar}" with the emph selected, so that you can type another
command in its place. Pressing tab instead moves you past the
closing }. There is a similar functionality for wrapping the
selection in a begin-end environment pair.
7. Changing environments. Suppose you are inside a split environment,
and decide to change it to aligned. In TM, you would press ctrl-
option-E, and then just type in the environment name, and both \begin
and \end entries get fixed. Similarly, there is a command to toggle
the presence of a * in the environment, like turning {equation} to
{equation*} and back.
8. Project Outline command. I recently added this command. It offers
you an HTML, clickable outline of your project, much like a table of
contents. Clicking on any section title takes you to the
corresponding section.
9. Special Beamer setting. You can set the language grammar to LaTeX
Beamer, which causes some commands to have particular behavior
related to beamer. For instance, the commands inserting a new \item
also add an overlay specification to it.
10. You can quickly turn a list of of lines into an itemize or
enumerate environment, by selecting them and running the command ctrl-
shift-L.
11. This is a general feature of TextMate that I found worth
mentioning, it's very useful. It has a columnar editing mode, where
you can for instance select a bunch of lines and add the same text at
the beginning of each line. For instance with the three lines:
foo
bar
baz
we could move the caret at the beginning of the first line, then
shift-down twice, and then press option for columnar insertion. Now
typing "\item " adds it to all three lines.
Ok, this is probably enough for now, but I would be happy to answer
any other questions you have about TextMate. And you can usually find
me in the irc channel, (irc://irc.freenode.net/#textmate). It is
populated almost all the time by extremely helpful and great people
(I would in fact say it is one of the great things TM has going for it).
More information about the textmate
mailing list