I write a lot of LaTeX. In plain text mode, sequences like 123 in are highlighted in red. That is a space, a digit string, a space, and then the specific word in. Such things as a1 in are not highlighted.

Since in plain text this string has no significance that I am aware of - I would like to know what Vim thinks it is doing. And also would like to know how to stop it.

(I suppose it has something to do with highlighting groups, but I have no idea which one is involved.)

1 Answer 1


You can find out what syntax item applies by positioning the cursor and using something like:

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

Because that's quite a mouthful it might be useful to map that to a command:

command! SynName echo synIDattr(synID(line("."), col("."), 1), "name")

For TeX files, this gives texLength as a result. You can remove this with:

:syn clear texLength

In your vimrc, you'd put that in an autocmd, to make sure it gets loaded after the tex syntax file is loaded:

autocmd Syntax tex syn clear texLength

Also see How can I add additional syntax highlighting rules in my local vimrc? for more details on adding local syntax rules.

As for why that is highlighted, I'm not familiar with (La)TeX, but judging from the syntax file it's used for some length measurements:

" TeX Lengths:
syn match texLength "\<\d\+\([.,]\d\+\)\=\s*\(true\)\=\s*\(bp\|cc\|cm\|dd\|em\|ex\|in\|mm\|pc\|pt\|sp\)\>"

This matches any number followed by a unit measurement such as "cm", "pt", and "in" (presumably for "inch"), with optional spaces between the number and unit.

I think this may be a bug in the syntax file that it matches anywhere in the document, and that it should have contained in the definition to make it only match in some places, but like I said: I'm not familiar with TeX at all so I don't know the syntax.

  • 2
    Unfortunately, a length can indeed appear in lots of places: "foo \hskip 1 in bar" gives "foo", then a one-inch space, then "bar". It's probably not doable to perfectly tell the "a length" and "not a length" cases apart with no context, so the syntax file errs this way. Commented Jul 13, 2022 at 9:23
  • 2
    Rather than autocmd Syntax, use ~/.vim/after/syntax/tex.vim
    – D. Ben Knoble
    Commented Jul 13, 2022 at 13:56
  • Thanks. You definitely hit the mark as to where to look. And yes, definitely a bug - since it is highlighting in normal text. In fact, it is a bit of a toss up as to whether highlighting normal text or not highlighting the lengths is the bigger problem. But, I think I will go with not highlighting the lengths - as what is a length is usually obvious to me and highlighting the plain text is jarring.
    – Bruce
    Commented Jul 14, 2022 at 0:11
  • @D.BenKnoble I am not sure what you are getting at here partly because ~/.vim/ is empty in my installation.
    – Bruce
    Commented Jul 14, 2022 at 0:15
  • 1
    Using the after/ directory is the same as an autocmd @Bruce; it just splits things up a bit in different files, which some people prefer. Personally, I prefer to put everything in my vimrc file – it's just a matter of personal preference. Also see How can I add additional syntax highlighting rules in my local vimrc? for more details Commented Jul 14, 2022 at 2:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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