Jakub M.
Jakub M.

Reputation: 33827

vim spell checking - comments only in LaTeX files

I use gvim to edit LaTex .tex file. I noticed that it checks spelling on the fly only for the commented text. If I have a mistake in a regular text - no underline. If I comment this text with % , the misspell is underlined immediately. What is wrong? Is there any strange option turned on?

Upvotes: 28

Views: 11015

Answers (8)

Jordan Mackie
Jordan Mackie

Reputation: 2406

None of the answers here worked for me, but I could see if I typed syntax spell as a command in vim it would work.

It turns out it was because syntax wasn't being set for the tex filetype automatically, and I found the solution here.

vim only spell checking in TeX comments

Editing a LaTeX document with vim, I noticed it was only spell-checking comments. I fixed this by add this to my ./vimrc:

autocmd FileType plaintex,tex,latex syntax spell toplevel

Upvotes: 0

thepith
thepith

Reputation: 67

This problem often occurs when working with files which are included by a master document.

If you are opening a TeX file which will be included and does not contain a section, chapter, \begin{document}, ... you can mark it by adding %begin-include at the top of the file. This way vim recognizes the file content as being part of the texDocZone region, which enables spellchecking.

With %end-include you can set the end of the texDocZone.

This behavior seems not to be documented, but is described in the vim syntax file: https://github.com/vim/vim/blob/master/runtime/syntax/tex.vim

tl;dr: Add %begin-include to the top of your tex file.

Upvotes: 3

Marek Stepanek
Marek Stepanek

Reputation: 139

I found the same problem, but a different solution to it. In some .tex files the spell-check was working as expected others not (documentclass{scrlttr2}). Only in the comments words were underlined ... So I compared the headers of one working and one not working .tex document. I found a surprisingly texblock, which were hindering the spell check in the document itself:

\usepackage{array}
\newenvironment{Conditio}
  {\par\vspace{\abovedisplayskip}\noindent\begin{tabular}{>{$}l<{$} @{${}={}$} l}}
  {\end{tabular}\par\vspace{\belowdisplayskip}}

And this code was only an "hangover" of a different juridical text, I edited before. Commenting it out, set the normal spell-check with high-lighted texts in the letter document. (MacVim 8.1 latex-suite macOS 10.13.6 vim-latex v1.10.0)

Upvotes: 0

Jan
Jan

Reputation: 5162

tldr; don't put \section commands in your master .tex document

I made the same observation and I also would insist on "before, it worked and I didn't change anything".

Then I observed that this unwanted behaviour only occurred in .tex documents where I have a master.tex that includes chapters as separate chapterx.tex files. Moreover, everything works fine if all the \section definitions are in the chapterx.tex's and NOT in the master.tex.

Otherwise, as I think, the vim syntax and spell checking routines have a hard time determining in which region they are, cf. this question Vim spellcheck not always working in .tex file. Check region in Vim

Upvotes: 0

Bill Dimm
Bill Dimm

Reputation: 341

I encountered the same problem -- the .tex file for the first chapter of my book spell checked normally, but the file for the second chapter would only spell check the comments. This apparently happens because vim isn't looking at enough lines of context and gets confused. Ingo Karkat's solution here fixed it for me. Specifically, I used:

syn sync maxlines=2000
syn sync minlines=500

in ~/.vim/after/syntax/tex.vim

Upvotes: 0

sehe
sehe

Reputation: 392929

The latex ft plugin conveniently defines this behaviour.

SpellChecker : Spell check text including LaTeX documents

Using latexmk, vim spell checking and vim latex-suite

There is an option that appears to come close:

:syntax spell [toplevel | notoplevel | default]

Update

Also

:he ft-tex-syntax

has very useful tidbits, like

Don't Want Spell Checking In Comments? ~

Some folks like to include things like source code in comments and so would
prefer that spell checking be disabled in comments in LaTeX files.  To do
this, put the following in your <.vimrc>: >
      let g:tex_comment_nospell= 1

You'll have to figure out whether you can use that/extrapolate from there

Upvotes: 17

digitaldingo
digitaldingo

Reputation: 519

I had the same problem (VIM 7.3), but this post at the vim-latex-devel mailing list provided the clue. To get the spell checking working, I had to put

syntax spell toplevel

in my ~/.vimrc, but it has to be declared after

syntax enable

or

syntax on

for it to work.

Upvotes: 17

Herb
Herb

Reputation: 76

I don't whether this is a crude hack and the intended solution, but I created a file called .vim/after/syntax/tex.vim containing the single line:

syn match texText "\<\w\+\>" contains=@Spell

Now vim spell checks the normal text between the commands and the text passed as parameters, because you cannot differentiate them syntacticly:

\frametitle{TextToBeChecked}
\pgfuseimage{VariableNotToBeChecked}

Hence, it checks way too much in my preamble. But I have it located in another file, so I don't really care.

Upvotes: 5

Related Questions