Spellcheck on Tex-Files

88 views
Skip to first unread message

bas...@gmail.com

unread,
Jan 15, 2008, 2:35:06 PM1/15/08
to v...@vim.org
Hi!
I am using the built in spellcheck for vim 7 and I want to use it with
Latex-files. There are some fillips which are irritating me.
So, for example if I have a table defined as:

\begin{tabular}{c}
...

The c in the brackets is highlighted as a missspelled word.

Another one:

%\usepackage{...}

Usepackage is highlighted as a missspelled word.
I'd like to turn off the spelling correction in comments, for it is not important for Latex-documents, because that's not to see for the reader afterwards and I'd like to have the highlighting of the column setup in the tabular-statement fixed.

How to do these?

Tanks in advance,
surgeon

Zsolt Udvari

unread,
Jan 15, 2008, 2:36:01 PM1/15/08
to vim...@googlegroups.com
> Usepackage is highlighted as a missspelled word.
Check untex!
$ whatis untex
untex (1) - strip LaTeX comands from input

ftp://ftp.thp.uni-duisburg.de/pub/source/untex-1.3.tar.gz (or use your
distros package management ;) ).

Andreas Müller

unread,
Jan 16, 2008, 2:00:26 PM1/16/08
to vim...@googlegroups.com
Hi ...

this can be done via contains=@Spell and contains=@NoSpell in the syntax
file (see :help spell-syntax).

For tabular, and usepackage, this already seems to be ok (with
vim-7.1.123), some others I have defined myself, e.g. for texttt:

syn region texZone start="\\texttt{" end="}\|%stopzone\>" contains=@NoSpell

(one line)

Regards, Andreas


bas...@gmail.com schrieb:

> --~--~---------~--~----~------------~-------~--~----~
> You received this message from the "vim_use" maillist.
> For more information, visit http://www.vim.org/maillist.php
> -~----------~----~----~----~------~----~------~--~---
>


signature.asc

skeept

unread,
Oct 1, 2012, 5:34:08 PM10/1/12
to vim...@googlegroups.com, v...@vim.org, bas...@gmail.com
I am having problems with misspells in tabular and multicolumn commands.
So for example in
\begin{tabular}{rl}
one & two \\
\multicolumn{2}{c}{what?}
\end{tabular}

rl and c are marked as spelling errors, but when using an array in math this does not result in an error.

I checked the tex syntax file and it is version 73 from April 24.

Any idea on how this can get fixed?

Thank you.

Charles Campbell

unread,
Oct 16, 2012, 11:51:12 AM10/16/12
to vim...@googlegroups.com
Vim is not a LaTeX parser. I could fix this by providing syntax rules
for tabulars (the syntax highlighting engine is more lexical than
syntactic), but there're many other places where LaTeX accepts things
that are not regular text and would be flagged as spelling errors. The
syntax/tex.vim file is already over 1200 lines long; I don't think I
will be implementing any fixes for this.

If this seriously annoys you, you could probably put additional syntax
highlighting rules in a .vim/after/syntax/tex.vim file and have it
recognize the tabulars (and whatever else you want recognized).

Regards,
C Campbell

skeept

unread,
Oct 16, 2012, 12:17:27 PM10/16/12
to vim...@googlegroups.com, charles.e...@nasa.gov
Thanks for your reply,

I understand your point, but it seems that vim already tries not to check spelling in a variety of locations when editing latex files (labels, citations, \ commands...)
I mentioned these because in my documents they are the only place left where I think the spelling should not be done, but I am sure there a a lot more for commands I am not using that would have to be added so that would be really hard.

I would gladly put the specific rules in my after/ftplugin, but unfortunately I don't know exactly what to put there.
Could you please tell me what specifically I would put there or point me for some files with specific examples?

Thank you for the help.

Jorge.

Charles Campbell

unread,
Oct 16, 2012, 3:10:27 PM10/16/12
to vim...@googlegroups.com
> I would gladly put the specific rules in my after/ftplugin, but
unfortunately I don't know exactly what to put there. Could you please
tell me what specifically I would put there or point me for some files
with specific examples?

You need to recognize the regions and use add=@NoSpell with them.

:help syn-region

syntax/tex.vim has a number of "syn region" usages that you could use as
an example. See "syn region DocZone" for example. You'll probably want
to contains=@texFoldGroup, in the text region.

Regards,
C Campbell

skeept

unread,
Oct 16, 2012, 10:47:54 PM10/16/12
to vim...@googlegroups.com, charles.e...@nasa.gov
What I put in my after/ftplugin/tex.vim is
syn region texTabularPos matchgroup=texSection start='\\begin\s*{\s*tabular\s*}{' end='}' fold contains=@texFoldGroup,@texDocGroup

but it doesn't seem to work (I still see the the word marked as a miss spell).

I also defined the following map
map <F10> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
from
http://vim.wikia.com/wiki/Identify_the_syntax_highlighting_group_used_at_the_cursor

and when I use it in the region I am interested I see
hi<texSectionZone> trans<

so I guess the region is not correctly defined.
Any input is appreciated.

Regards,

Jorge

xxx

unread,
Oct 24, 2012, 10:05:00 PM10/24/12
to vim...@googlegroups.com, charles.e...@nasa.gov


I would really appreciate a specific example on how to acomplish this.
My last try is
syn region texComment matchgroup=texStatement start='{tabular}{' end='}'
\ contains=@NoSpell

but it doesn't work...

Charles E Campbell Jr

unread,
Oct 31, 2012, 5:45:57 PM10/31/12
to vim...@googlegroups.com
xxx wrote:
> I would really appreciate a specific example on how to acomplish this.
> My last try is syn region texComment matchgroup=texStatement
> start='{tabular}{' end='}' \ contains=@NoSpell but it doesn't work...
You almost had it earlier; you need to have your new region contained in
texDocZone:

syn region texTabularPos matchgroup=texStatement
start='\\begin\s*{\s*tabular\s*}{' end='}' fold
contains=@texFoldGroup,@texDocGroup,@NoSpell containedin=texDocZone

That may not be the only region that it needs to be contained in, however.

I use my :HLT! command available with my plugin hilinks.vim:
http://www.drchip.org/astronaut/vim/index.html#HILINKS

Then you can move your cursor around and determine which syntax region
is currently active under the cursor.

Regards,
C Campbell

skeept

unread,
Nov 1, 2012, 11:43:29 PM11/1/12
to vim...@googlegroups.com

Thank you very much!
With the help of your plugin HILINKS and your last suggestion I was finally able to get it to work.
The version I have in my config file (which I would not be able to write without your plugin) is:

syn region texTabularPos matchgroup=texStatement
\ start='\\begin\s*{\s*tabular\s*}[^}]*{' end='}' fold
\ contains=@texFoldGroup,@texDocGroup,@NoSpell
\ containedin=texDocZone,texChapterZone,texSectionZone,texSubSectionZone

Since I got this far, I would ask a related question.
Some authors names are first classified as bad spelling. For some names, say
Al-Faiz both words Al and Faiz are spelling errors. They are actually a name but unless they appear together this should be a bad spelling.
An idea I have is to define a command
\nospell and then when writing the name I would just write \nospell{Al-Faiz} and then I could instruct vim not to spell that region, using a technique similar to the above one.
Any idea on this?

Thanks!

Charles Campbell

unread,
Nov 2, 2012, 9:50:42 AM11/2/12
to vim...@googlegroups.com
skeept wrote:
> Thank you very much! With the help of your plugin HILINKS and your
> last suggestion I was finally able to get it to work. The version I
> have in my config file (which I would not be able to write without
> your plugin) is: syn region texTabularPos matchgroup=texStatement \
> start='\\begin\s*{\s*tabular\s*}[^}]*{' end='}' fold \
> contains=@texFoldGroup,@texDocGroup,@NoSpell \
> containedin=texDocZone,texChapterZone,texSectionZone,texSubSectionZone
> Since I got this far, I would ask a related question. Some authors
> names are first classified as bad spelling. For some names, say
> Al-Faiz both words Al and Faiz are spelling errors. They are actually
> a name but unless they appear together this should be a bad spelling.
> An idea I have is to define a command \nospell and then when writing
> the name I would just write \nospell{Al-Faiz} and then I could
> instruct vim not to spell that region, using a technique similar to
> the above one. Any idea on this? Thanks!
Glad you could get it to work.

If you can live with "-" signs in your keyword (see :help 'isk'), then
making names part of a keyword list (and contains=@NoSpell) should
work. Keywords are the fastest (using a hashing method for recognition)
plus have top priority (so you won't need to worry about the
containedin=... list).

Regards,
Chip Campbell

skeept

unread,
Nov 3, 2012, 3:28:04 PM11/3/12
to vim...@googlegroups.com, charles.e...@nasa.gov
Thanks for the suggestion, I have thought about that before but I prefer not to add - to iskeyword. I did add : which makes completion for references easier (so I can type eqn:<C-N> and have a list of possible words starting with eqn:)

Regards,
Jorge Rodrigues

Reply all
Reply to author
Forward
0 new messages