Sublime Forum

Word wrapping in LaTeX files (ST, ST2)

#1

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.

0 Likes

Opening parentheis in word wrap
Php variables' names wrapped
#2

Maybe this?:

// Characters that are considered to separate words "word_separators": "./\\()\"'-:,.;<>~!@#$%^&*|+=]{}`~?",

0 Likes

#3

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!

0 Likes

#4

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.

0 Likes

#5

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?

0 Likes

#6

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.

0 Likes

#7

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

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.

0 Likes

#8

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.

0 Likes

#9

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!

0 Likes

#10

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.

0 Likes

#11

Left me wondering too :smile:

0 Likes

#12

I have noticed another issue: in inline math mode ($…$), commands are not kept on a single line (in addition to possibly being separated from their backslash). A picture is worth a thousand words…


0 Likes

#13

Did you ever figure out something to fix this in Sublime Text 2 or 3?

0 Likes