11.11.05

TextMate Rocks

Posted in computers, TextMate, LaTeX at 10:15 pm by Haris

It’s time to once again rave about my all time favorite editor TextMate. Since a picture is worth a thousand words, here’s how TextMate looks like when I have my thesis project open: textmate screenshot

First of all, notice the wonderful coloring scheme. It is fully customizable through the Preferences menu, and there are lots of custom themes made by users. Now look closer. You will notice that the window is slightly transparent! You can adjust the transparency level as you see fit, or disable it altogether.

Take a look at the bottom line the document, full with wonderful information. First you see, as is standard, your location in the document by line and column. Then, right next to it, is the language button, which allows you to choose what language set for the document. Perhaps not extremely useful since you don’t often change languages, but it sure is useful to have available the information of what the current language is, and once that’s there, you might as well allow the change. The useful tool is the one right next to it, the one that looks like a wheel. This contains access to all sorts of wonderful commands, snippets and macros related to LaTeX: textmate2a

For instance there is a snippet that will insert an almost complete figure environment. You can easily create environments as follows: type theorem and press Command-Shift-<, and it will be converted to

\begin{theorem}

\end{theorem}

And the cursor is placed in the empty line in-between. You could also very easily create your own snippets, so that for instance when you type thm and then press tab, then it gets expanded to the same block as above. I could go on for quite some time describing such commands, but it is better if you explore them yourselves.

Continuing with the information on the bottom line of the document, there is another pop-up which contains a “symbols list”. Depending on what language is loaded, this may vary. In LaTeX, this contains all \section and \subsection commands. Selecting a symbol from the pop-up will take you to the corresponding section in the document.

Now time to turn our attention for a moment to the drawer next to the document. This contains a list of all the documents in the project, and clicking on one of them takes you there. There is actually a faster way to navigate to other files, through the awesome window that shows up when you press Command-T. This brings up a search field where you can easily navigate through your files. The best way to describe this window is by another screenshot of how it looks after I’ve typed ste:

textmate3a

Another really cool feature of TextMate is that it can nest the syntax coloring: Again, a screenshot says it all. This is from a MediaWiki file, and in the MediaWiki syntax (which is kind of lame because I created it myself in a short amount of time) I instructed TextMate to recognize anything enclosed in <math> tags as being LaTeX. What this means is that all syntax coloring shortcuts and commands of the LaTeX bundle can be used whenever you are inside the math tags, while the rest of the file is still handled according to the MediaWiki syntax: textmate4

Please, tell me if other editors do that.

And now, for the part that all our Linux friends out there are waiting for: TextMate has a wonderful integration with the command line. First of all, you can feed the entire document, or a selection, as the input on any unix command, and use the output in the current document, or a new document etc. The TextMate bundles use this all over the place to do a lot of cool stuff that I won’t even begin to describe. Another cool feature is that you can quickly ask TextMate to execute a line as if it were in the command line, and input the result right where you are. For instance if I type in an empty line echo "24*24"|bc, and then press Control-R, the next line will become 576. Actually this is not a good example, since there is actually a command in TextMate that would only require me to type 24*24. A better example would have been to use date, which would have output, in my case: right now Fri Nov 11 22:59:55 CST 2005 — In fact that’s what I just used.

And now we come to the final feature for today, the wonderful plugin called TmCodeBrowser, developed by Gerd Knopps. This is that panel that you can see in the first screen, all the way on the left, and it is used for navigation. The cool thing about it is that you can customize it with whatever you want basically. As it is, as far as LaTeX files are go at least, it picks up all sections and labels, as you can see in the picture. The nice thing is that you can customize it to do whatever you want it to, if you know a little bit of regular expressions, since it uses Exuberant ctags. For instance, using the following lines:

--langdef=markdown
--langmap=markdown:.markdown
--regex-markdown=/^#[ \t]+(.*)/\1/h,heading1/
--regex-markdown=/^##[ \t]+(.*)/\1/h,heading2/
--regex-markdown=/^###[ \t]+(.*)/\1/h,heading3/

will create a list of all the headings in your markdown document, for easy navigation. I am currently using it with a file containing the list of 80 colleges I am applying to.

Ok, I lied, that was not the last feature I will mention. TextMate comes with a command line tool, called mate, which you can use to open files in TextMate when you are in the command line. Very helpful with hidden files et al. I think I’ll stop for now.

Later

12 Comments »

  1. Andrea said,

    January 8, 2006 at 6:13 am

    As you can see here http://macromates.com/wiki/Main/Bundles someone (I for one) would love to have your Mediawiki syntax coloring file.
    Thanks!

  2. Haris said,

    January 8, 2006 at 6:17 pm

    Andrea,

    the bundle is really not much as it stands, but you are welcome to use it and improve it. You can find it here:
    http://skiadas.dcostanet.net/uploads/mediawiki.zip

  3. Andrew said,

    April 13, 2006 at 1:40 am

    Hi,

    Do you know if there’s an easy way to typeset your “master.tex” (the one that includes all other chapters) while you’re editing another chapter tex-file?
    I don’t know yet if macro’s can record something like: switch to master.tex, typeset, switch back.

  4. Haris said,

    April 13, 2006 at 6:33 am

    Andrew,

    assuming you are working with a project, you can set project specific environment variables. If you create such a variable with name TM_LATEX_MASTER and value the full path to your master.tex file, then that file will be the one that always gets compiled.

    Btw, I believe this information is in the Help file that comes with the LaTeX bundle, which can be seen by running the Help command in the LaTeX bundle. If you find the Help file lacking in any way, let us know.

  5. duus said,

    July 18, 2006 at 7:32 pm

    hello haris–just a general comment on your site–Thanks! Very helpful info about TextMate!

  6. Haris said,

    July 18, 2006 at 8:29 pm

    Thanks duus! It’s great seeing that people find it a useful resource. It encourages me to keep it up!

  7. Jenny said,

    July 19, 2006 at 6:31 pm

    Thanks for all the helpful advice on TextMate. It has made my life so much easier!

    I have something simple to offer you and your readers. I recently discovered that you can replace \section in Latex with \begin{section} and \end{section}. This, of course, means you can easily collapse or expand sections in TextMate.

    I also asked Gerd Knops to modify the code of his TmCodeBrowser so that sections, subsections, etc, are an optional list. He kindly obliged, and gave me permission to type up his instructions (put together from several emails) for you to disseminate, if you wish.

    1. Download the file default_ctags.txt in case you need it.

    2. Install TextMate’s terminal support (TextMate/Help/Terminal
      Usage…)

    3. Start Terminal.app and enter the command
      mate ~/.ctags.tmcodebrowser

    4. A custom configuration file should be at ~/.ctags.tmcodebrowser (~
      being your home directory), though it may not exist on your
      system and in any case it will be invisible to the Finder.
      That will open the (possibly empty) custom configuration file.
      If it is empty, paste in default_ctags.txt.

    Either way, your current ~/.ctags.tmcodebrowser file currently contains
    these lines near the end:

    –langdef=latex
    –langmap=latex:.tex
    –regex-latex=/\label{([^} \t]+)[ \t]}/\1/l,label/
    –regex-latex=/^\(sub)section*?{(.)}/\2/s,section/

    Behind these, add this line:

    –regex-latex=/\begin{(sub)section}[ \t]({(.)})/\1-\3/s,section/

    and save.

    Now your sections should show it they are formatted as follows:

    \begin{section}{YOUR SECTION TITLE}

    \end{section}

    Gerd tells me this should also work if you use the more standard

    \section{YOUR SECTION TITLE}

    but this won’t fold automatically in TextMate.

  8. Haris said,

    July 19, 2006 at 8:14 pm

    Jenny,

    Thank you very much, I was in fact not aware of the \begin{section} form! This is indeed great for folding, though it will not show by default on the symbol list. I’ll see if I can fix that.

    Of course, if it is just folding you want to accomplish, it would probably be possible to have foldings occur between a \section command and some special marker, like %endsection. The problem with the folding markers now is that there is no natural thing to use to signal the end of the \section command, but one could artificially change the grammar, by for instance a convention like %endsection. I haven’t actually tried it, but I don’t think it would be too hard.

    The main way in which I would like to improve the LaTeX bundle right now is as far as support for large projects goes, with better support for \include’d files. For instance, there should be a command that shows you the section structure of the entire document, and allows you to move to any section with one click. Most of the programming has already been done for the enhanced labeling command anyway.

    I am rather on the busy side for the next couple of weeks, but after that I’ll write a post containing your comment and see if I can add support for this style of sections in the language.

    Thanks again for the very detailed comment. It’s always great to see a fellow mathematician use TextMate and its LaTeX bundle. Please feel free to mention any wishes you have from the bundle, any things you would like it to do. I’m afraid it will never be able to make coffee or prove theorems though.

  9. Jenny said,

    July 22, 2006 at 9:20 am

    Haris,

    Thanks for your response and offer to help, but coffee is the most important feature I need!

    This \begin{section}/\end{section} is not yet well developed. It seems to be missing control over numbering. At least, I can’t figure it out. For example, I would like to use an equivalent to \section*, but nothing obvious works. Also, TOC does not understand this mode. I just wrote the LaTeX3 development group about this, and hope they will agree this should developed as part of the upgrade. Your idea of using something like %endsection could be a temporary fix.

    Once this is settled, I wonder if CodeBrowser would be able to produce lists that are hierarchical for chapter,section,subsection,subsubsection. Then, dreaming on, we would want to be able to move a section title in the CodeBrowser list and have the corresponding section move in the TextMate source. This would give TextMate some outlining power it is missing. I will pass this along to Gerd, although it may be too much to ask.

    Jenny

  10. Jenny said,

    July 22, 2006 at 3:28 pm

    Actually, you can use \begin{section}{Name} and that works the same as \section. TOC works with this mode, too.

  11. Jenny said,

    July 22, 2006 at 7:39 pm

    Somehow, the star symbol was omitted from my previous message when it showed up on your webpage. I will spell it out
    You can use either
    \begin{section}”star”{Name} (with \end{section}, of course)

    or

    \section”star”{Name} to omit the section number.

  12. Haris said,

    July 22, 2006 at 9:45 pm

    Hi Jenny,

    all the comments pass through the Markdown filter, so stars are interpreted as italization, if two of them appear unescaped. You can try escaping them, but it doesn’t work very well with the new Wordpress version that I am running. It’s a big pain, big enough that I consider moving to a different platform.

    This is very interesting. So the star needs to go outside the {section} part, instead of the much more customary form of all other environments, where the star appears inside? This is very peculiar I must say, I don’t see why they would program it this way. It breaks pretty much any convention I’ve seen in LaTeX.

Leave a Comment