[TxMt] Fwd: Latex Bundle Useability (and patch)

Charilaos Skiadas cskiadas at gmail.com
Mon Nov 5 11:52:25 UTC 2007


Hi Peter,
On Nov 5, 2007, at 2:23 AM, Peter Gerdes wrote:

> So I'm working on writing up my (mathematical logic) thesis and  
> I've been using textmate to do it.  Unfortunately I've ran into  
> some serious usability issues with the latex bundle in textmate and  
> unsurprisingly have been wasting time trying to fix them.  I  
> figured I would post the issues to this list along with some of the  
> hacks that seem to help for me and see if people who know more  
> about the textmate stuff can help make this bundle more useable for  
> intense mathematics.
>
> First of all I'm attaching a simple patch for PyTeXdoc.py so it  
> queries kpsewhich to look for included/inputed files if it fails to  
> find them.  Since I keep some general purpose includes in my tex  
> directory this makes a difference.
> <PyTexdoc.py.patch>
>   Note that this is patched from the tree updated earlier today.

Thanks, I'll let Brad have a look at this, since he is our Python  
expert.

> Now for some harder issues that I can only gesture at solving.
>
> Useability Issues:
>
> 1) Typing commands inside $$ causes wacky highlighting flip-flops.
>
> Often I will be editing an existing tex file and need to add  
> something like $\Gamma_{\alpha+1}(\sigma)\concat\tau$.  This causes  
> issues since you have to pass through $$ $\$, $\Gamma_{\}$  and  $ 
> \Gamma_{\alpha+1}(\sigma)\concat\$ on the way each of which flips  
> the syntax highlighting for the ENTIRE rest of the document.  Not  
> only is this annoying it causes unacceptable slowdowns as the rest  
> of the doc is rehighlighted.

Have you tried using the "Insert Symbol based on Current Word"  
command? For instance, instead of typing \ followed by Gamma, you type:
G
and then press cmd-\ in my case, and it becomes \Gamma.

Of course it won't work for other commands, but for most of those  
(those you use frequently that is) you can set them up for the  
shortcuts in the "Insert Label Based On Current Word" command. For  
instance already typing: "ds" followed by cmd-shift-[ leads to  
"\displaystyle".

> My personal collection of hacks to deal with this problem is as  
> follows (some of these are old so i apologize if it was fixed in  
> the bundle and I missed it):
> 	
> a) Elimate the $$   $$ notation for display math.  It is considered  
> bad form to use the old $$ $$ approach rather than the new \[ \]  
> notation.  I realize doing something like this would be  
> controversial in the default language grammar but I'd rather have  
> the right way of doing things be useable rather than correctly  
> hightlighting the wrong way.  But maybe there is another way to  
> deal with the issue.

As you say, it would be quite controversial to replace this,  
especially thinking of people working with collaborators or on old  
latex files. I personally have made a set of three commands, kept in  
a separate grammar, that help me with this:

a) "Inline Math", a command bound to the key equivalent $, with scope  
selector text.tex.latex and doing an Insert Snippet with command text:

#!/usr/bin/env ruby
require ENV['TM_SUPPORT_PATH'] + '/lib/escape.rb'
if ENV['TM_SELECTED_TEXT'].nil? then
   print "\\( $1 \\)"
else
   print "\\( #{e_sn ENV['TM_SELECTED_TEXT']} \\)"
end

b) "Move out of Math", a macro bound to the key equivalent $ but with  
scope selector "text.tex.latex string.other.math.latex", that  
effectively does a search for a \) or \] and takes you right after  
it. This is particularly nice, since it will take me out of the  
environment regardless of whether I am at its end or not, and  
regardless of whether I'm doing a new math equation or revisiting an  
old one (at which point the smart pair is not active anyway).

c) "Insert dollar sign", a snippet bound to ctrl-4 that simply  
inserts an escaped dollar sign: "\\\$".

I've attached the three commands if you want to give them a try (hope  
the files go through).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Insert dollar sign.tmSnippet
Type: application/octet-stream
Size: 542 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20071105/8d9a24fb/attachment.tmSnippet>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Inline math.tmCommand
Type: application/octet-stream
Size: 930 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20071105/8d9a24fb/attachment.tmCommand>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Move out of math.tmMacro
Type: application/octet-stream
Size: 1027 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20071105/8d9a24fb/attachment.tmMacro>
-------------- next part --------------

I think these should alleviate most of the problems mentioned below.  
I have often thought of making these part of the official bundle, but  
keep on thinking of the people who would have issues with it, and  
haven't found a nice way to cause them less problems.

> b) Require $ to be escaped as {\$}.  Once again not a good general  
> solution but for me this works since I rarely use a real dolsign.   
> Perhaps a better trick would be to require this weird special  
> escaping only when in math mode.  Once again I'm puzzled about how  
> to do this correctly but as it stands it causes serious problems.
>
> c) I used to have problems with $\Gamma_{\}$ letting the braces  
> spill over but it is either fixed now I or I changed something  
> locally I don't remember.
>
> 2) Typing { when the caret is before a slash causes smart typing  
> pairs to insert {\} instead of {} because it thinks we are trying  
> to escape the {.  This can be fixed by changing the match for  
> constant.character.escape.tex to start with a positive backref of (? 
> <=\\) instead of just (\\).  It seems weird to me that having a  
> caret in front of the string causes it to be grabbed but go figure.
>
> 3) Often I need to insert math inside an already written  
> paragraph.  So I start with a line like
> 	If $x$ is a blah then blah2
> and need to fix it to
> 	If $x$ is a blah and $math stuff$ then blah2
> which one naturally does by simply putting the caret in front of  
> the t in then and starting to type.  Unfortunately the smart typing  
> pairs for $ fail to activate when you are in front of a character.   
> I have no idea why this is (seems to work for {) but the best fix I  
> could come up with was a hack to define meta.in-front-of-char.latex  
> and create a snippet for this situation assigning it to $.  If I  
> knew how to insert true smart typing pairs from a snippet (or  
> command) a general purpose solution that works could be found.
>
If you use the above commands, that should not be a problem I don't  
think.

> On the other hand probably anyone who knows textmate well enough  
> will see how to do this in an elegant fashion.
>
> 4) SPEED
>
> This is a big one.  Frequently I will type a long paragraph filled  
> with many many math commands and my powerbook G4 1Ghz will slow  
> enough to make typing difficult if I am inserting anything inside  
> the paragraph.  If I actually hard wrap the lines this stops  
> happening but since textmate doesn't support hard wrapping well  
> this isn't really an option.
>
> I noticed in the language definition there are many syntax elements  
> (like meta.function.embedded.java.latex) whose matches begin with  
> something like:  (?:\s*)((\\)begin) .....  I can't figure out what  
> sense this makes at all.  Why match the spaces if they can just  
> happen anywhere in the line?  Maybe I am just missing something  
> obvious and I'm deluding myself but when I changed these all to (?:^ 
> \s*)((\\)begin) .... everything seemed to keep working and things  
> seemed to speed up considerably.  Then again maybe it was an  
> unrelated bundle update.

That would probably work in fact. I am puzzled however. This should  
be slowing you down only if you have many begin-end blocks on the  
same line, and I don't tend to see that often. What begin-end blocks  
are you using? If you use the "Insert Environment Based On Current  
Word" command to generate them, then they will span multiple lines  
instead.

> Still before I keep screwing with this I figured I would toss this  
> out there and see if it was a well known problem.

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College






More information about the textmate mailing list