11

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
  • 6
    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
6

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
  • Both solutions doesn't work for me :( – Mr. D Apr 3 '18 at 14:08
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.