4

I use a problem set class to type up my problem sets. I often have a main.tex file that looks something like the following.

\documentclass{problemset}

\begin{document}

\input{problem1}

\end{document}

I typically have a different file for each problem. For example, problem1.tex might be as follows.

\begin{problem}
there is a spelling errrrrrrror here
\end{problem}

I would like vim to detect the spelling error in problem1.tex, but unfortunately it does not. As noted in this post, the problem seems to be that vim is not able to identify any syntax region: when I run the command

:echo synIDattr(synID(line("."),col("."),1),"name")

I don't get any output. As another example, if I change problem1.tex to the following, then the spelling error is identified.

\section{dummy section}
\begin{problem}
there is a spelling errrrrror here
\end{problem}

I have tried to create a syntax region for my problem environment, but was unsuccessful. My attempt consisted of creating the following .vim/syntax/tex.vim file.

syntax region texProblem start="\\begin{problem}" end="\\end{problem}" contains=@Spell

Nothing seems to happen when I create this tex.vim file. I used scriptnames to check that that the syntax file is being loaded (the default syntax file is also loaded after mine). I can also get the spelling error to be flagged by setting the filetype to plaintex, as suggested here, but this seems like a terrible hack. It seems like there should be a better way to get spell checking in my problem1.tex file.

Community
  • 1
  • 1
Stirling
  • 391
  • 3
  • 11
  • exactly my problem. Any solutions? – Floyd Feb 03 '15 at 14:28
  • 1
    adding `syntax spell toplevel` to `.vim/syntax/tex.vim` worked in my case – Stirling Feb 21 '15 at 18:27
  • I'm running vim-latexsuite of vim73 under debian wheezy/7.8 and it worked for me too: cp /usr/share/vim/vim73/syntax/tex.vim . add ''syntax spell toplevel'' and spelling errors are now displayed in \include-ed files. Thanks, Stirling! – Floyd Feb 23 '15 at 06:33

2 Answers2

1

The comments above worked for me (syntax spell toplevel) and this setting works for me even when run later (so no need to copy anything from /usr). But I didn't want that setting to be active for all tex files - instead, I customize it for the given file in my .vimrc:

au BufNewFile,BufRead body.tex syntax spell toplevel
0

I used a hack for this problem. Add the following to the top of your file:

\iffalse{}\section{vim-hack}\fi{}

This way, vim's syntax and spell algorithms find some token to get them started, but due to the "if" the section will be ignored by latex itself.

(I did not test whether more specialized editors ignore this dummy section, so there may be more hackery required if you use both vim and an editor.)

HansG
  • 55
  • 4