15

I'm using vim to write my thesis. It's a multi-document project, with most tex files in subdirectories from the master-document. I've set up a couple of \newcommands to replace the use of \section*{} in the Introduction, but when writing the sections, misspelt words aren't highlighted.

I thought it was a problem with vim-latexsuite, so I've just uninstalled it, but still, spell-checking functionality doesn't work in these sections.

For example, a MWE with the following files:-

thesis.tex
thesis.tex.latexmain
Classes/Thesis.cls
Intro/intro.tex

thesis.tex :

\documentclass[twoside,openany,titlepage,12pt]{Classes/Thesis}

\pagenumbering{roman}
\begin{document}

\include{Intro/intro}

% ...

\end{document}

Classes/Thesis.cls :

\ProvidesClass{Classes/Thesis}[2014/07/14 v1.2 Thesis template]

\LoadClass[pdftex, a4paper]{report}

\usepackage[pdftex,
            plainpages = false,
            pdfpagelabels,
            bookmarks,
            bookmarksopen = true,
            bookmarksnumbered = true,
            breaklinks = true,
            linktocpage,
            pagebackref,
            colorlinks = true,
            % Colour settings from::
            % http://tex.stackexchange.com/questions/30243
            linkcolor=NavyBlue,
            citecolor=BrickRed,
            filecolor=black,
            urlcolor=BrickRed,
            hyperindex = true,
            hyperfigures
            ]{hyperref}

\usepackage{tocbibind}
\usepackage{bookmark}
\usepackage[english]{babel}
\usepackage{times}
\usepackage[a4paper]{geometry}
\usepackage{pdfpages}


\newcommand\chapwtoc[1]{%
  \phantomsection
  \chapter*{#1}
  \addcontentsline{toc}{chapter}{#1}
  \markboth{#1}{}
}

\newcommand\secwtoc[1]{%
  \phantomsection
  \section*{#1}%
  \markright{#1} % Get the Section name in headnotes
  \addcontentsline{toc}{section}{#1}
}

Intro/intro.tex :

\chapwtoc{First chapter}

this is a msisisspelt word. Some mnore mis-spellings.


\secwtoc{First section}

some more misskjkpellings.

% vim: spell spelllang=en_gb

thesis.tex.latexmain is an empty file, as suggested in the latexsuite documentation for Multiple file LaTeX projects

How do I get spell-checking to work in the intro.tex sections? Using vim 7.4 on Linux

  • Are you sure it's not just a colour scheme issue? With the default colour scheme “this” and “some” are highlighted, not so “chapwtoc” and “missdklkjpllings”. When I change the colour scheme to e.g. desert then all misspellings are highlighted. – Marco Sep 27 '13 at 11:14
  • I'm just using the default colorscheme, but no difference with desert, or others... – Alex Leach Sep 27 '13 at 11:17
  • The only highlighted words in intro.tex are in the vim settings line: spelllang and gb. If I use \chapter* and \section*, then it works as expected.. – Alex Leach Sep 27 '13 at 11:23
  • 1
    As yours worked, I had a look in my ~/.vimrc, and I found the culprit: let g:tex_flavor = "latex". Removing that fixes it – Alex Leach Sep 27 '13 at 11:25
  • oww, well that fixed it for the MWE, but not my actual thesis intro. – Alex Leach Sep 27 '13 at 11:41
  • Then start with a minimal working .vimrc and add your custom configuration line by line (or do a bisect). Then you'll find the offending line or setting. – Marco Sep 27 '13 at 11:44
  • It doesn't seem to be a problem with my .vimrc now, but the content of my actual introduction.tex. I just copied it over to the MWE - it doesn't work - so i'm cutting stuff out of it to see if I can the problem... – Alex Leach Sep 27 '13 at 11:52
  • Seems to be a filetype detection problem.. I opened the two intro's side-by-side and noticed that the commands were highlighted in different colours. Where spell-checking doesn't work, set filetype returns tex, whereas when it does work, it detects plaintex.. Guess I'll have to add the filetype to the settings line.. – Alex Leach Sep 27 '13 at 11:59
  • 8
    Indeed, seems to be a bug in tex documents, as opposed to plaintex docs. In the MWE, set filetype=tex breaks spell-checking. In my actual thesis, set filetype=plaintex fixes it. – Alex Leach Sep 27 '13 at 12:08

2 Answers2

9

You can force spell checking for tex documents by putting the following into .vim/after/ftplugin/tex.vim or .vim/after/ftplugin/tex/spelling.vim:

set spelllang=en_gb spell

Your approach to do it with modeline magic

% vim: spell spelllang=en_gb

should work too, but you need to explicitly enable modelines. (They can be a security issue.) To do so, put the following into your .vimrc:

set modeline
bodo
  • 6,228
1

Enable file type plugin:

echo -e 'filetype plugin on' >> ~/.vimrc
or
echo -e 'filetype plugin indent on' >> ~/.vimrc

Enable spell check for tex files and disable syntax:

mkdir -p ~/.vim/ftplugin/
echo -e 'set spell\nsyntax off' >> ~/.vim/ftplugin/tex.vim

To temporarily enable syntax, execute in vim:

:syn on
anask
  • 111