Home Download Buy Blog Forum Support

Word wrapping in LaTeX files (ST, ST2)

Word wrapping in LaTeX files (ST, ST2)

Postby Marciano on Sat Mar 05, 2011 9:30 pm

Hi all,

this question applies to both ST and ST2. It has to do with the line-breaking algorithm when working with word wrapping on, as is the case for LaTeX files.

Suppose the cursor is at the last line position in the window, and you want to type, e.g., "sublime". You type the s, which appears on the current line; then you type the u, and both the s and the u are moved to the following line. All is well---it's what you want to happen.

However, suppose you want to type a LaTeX command instead, e.g. \emph, starting from the same position as before. You type the \, then you type the e, and nothing special happens: the \ remains on the first line, and the appears in the following line. The same is true if you use e.g. a brace ("{") or the inline math symbol "$".

This is undesirable, as it makes the document harder to read. TextMate does not have this issue: \'s, $'s, {'s etc. all move to the next line if necessary. Is there a setting to control this anywhere?

Thanks!
M

PS: I'm slowly porting the LaTeX plugin to ST2. I'll post an announcement when I have something useable.
Marciano
 
Posts: 146
Joined: Fri Sep 18, 2009 2:55 am

Re: Word wrapping in LaTeX files (ST, ST2)

Postby guillermooo on Sat Mar 05, 2011 9:50 pm

Maybe this?:

Code: Select all
   // Characters that are considered to separate words
   "word_separators": "./\\()\"'-:,.;<>~!@#$%^&*|+=[]{}`~?",
guillermooo
 
Posts: 723
Joined: Thu Jul 23, 2009 9:06 am

Re: Word wrapping in LaTeX files (ST, ST2)

Postby Marciano on Sat Mar 05, 2011 10:15 pm

Hm... that does not seem to do it. I created a LaTeX.sublime-settings file with the line you indicated, OMITTING the \ and $ signs, but I observed the same behavior. Thanks though!
Marciano
 
Posts: 146
Joined: Fri Sep 18, 2009 2:55 am

Re: Word wrapping in LaTeX files (ST, ST2)

Postby guillermooo on Sat Mar 05, 2011 10:40 pm

I'm probably missing something, but I do get the behavior you expect with the default settings: sequences like "\emph" are pushed to the next line as a unit if typed at the end of a line with word wrap on. Tried with a plain txt file, though, no LaTeX.
guillermooo
 
Posts: 723
Joined: Thu Jul 23, 2009 9:06 am

Re: Word wrapping in LaTeX files (ST, ST2)

Postby Marciano on Sat Mar 05, 2011 10:53 pm

Weird! I just tried it, and indeed, with a newly created file, I get the behavior I would like. Yet, in a .tex file, I don't get it.

So, it must be some .tex-specific setting, but I have no .sublime-settings file in the LaTeX package directory... any other ideas?
Marciano
 
Posts: 146
Joined: Fri Sep 18, 2009 2:55 am

Re: Word wrapping in LaTeX files (ST, ST2)

Postby guillermooo on Sat Mar 05, 2011 11:06 pm

Completely unfounded idea: maybe Sublime uses the tmLanguage to make assumptions about where to split the text? What you describe does happen in *.py files too. I would be confused what the purpose of the option mentioned above would be then, and why Sublime would need to disambiguate in some cases.
guillermooo
 
Posts: 723
Joined: Thu Jul 23, 2009 9:06 am

Re: Word wrapping in LaTeX files (ST, ST2)

Postby Marciano on Sat Mar 05, 2011 11:10 pm

I thought about that, too. However, I am not smart enough to figure out where this happens :-)

Also, this issue does not arise with TextMate, and I'm guessing that the LaTeX.tmLanguage file is the same as TextMate's (there are references to TeXshop. a popular Mac TeX editor). Of course, ST2 and TM could be interpreting the same file in different ways...

Hopefully Jon can shed some light on the issue.
Marciano
 
Posts: 146
Joined: Fri Sep 18, 2009 2:55 am

Re: Word wrapping in LaTeX files (ST, ST2)

Postby jps on Sun Mar 06, 2011 4:22 am

guillermooo is correct: the tmLanguage is used to tokenise the text, and these tokens are used as word wrapping units. The reasons for this are largely historical, but I won't be in a position to change this until the Shiny New Text Buffer work gets underway, which won't be happening until well after the stable version of 2 is released.

word_separators are used for other things, such as navigating by words.
jps
Site Admin
 
Posts: 3062
Joined: Wed Mar 19, 2008 12:33 pm

Re: Word wrapping in LaTeX files (ST, ST2)

Postby Marciano on Sun Mar 06, 2011 5:12 am

OK, thanks for the clarification. Do you think it would be possible to tweak the tmLanguage file so as to not break things, but still ensure that backslashes stay with their associated command (e.g \emph etc.)? WHere should I look? Thanks!
Marciano
 
Posts: 146
Joined: Fri Sep 18, 2009 2:55 am

Re: Word wrapping in LaTeX files (ST, ST2)

Postby jps on Sun Mar 06, 2011 5:16 am

As an example, the '\' and the 'emph' are assigned different scopes by LaTeX.tmLanguage, which causes Sublime Text to treat them as two separate tokens. If you changed the regex to not assign the '\' its own scope, then it would be placed in the same token.
jps
Site Admin
 
Posts: 3062
Joined: Wed Mar 19, 2008 12:33 pm

Next

Return to General Discussion

Who is online

Users browsing this forum: Google [Bot] and 40 guests