vim 拼写检查 - 仅在 LaTeX 文件中添加注释

发布于 2024-11-04 09:46:54 字数 117 浏览 8 评论 0原文

我使用 gvim 编辑 LaTex .tex 文件。我注意到它只检查注释文本的拼写。如果我在常规文本中出现错误 - 没有下划线。如果我用 % 注释此文本,拼写错误会立即带有下划线。怎么了?是不是有什么奇怪的选项被打开了?

I use gvim to edit LaTex .tex file. I noticed that it checks spelling on the fly only for the commented text. If I have a mistake in a regular text - no underline. If I comment this text with % , the misspell is underlined immediately. What is wrong? Is there any strange option turned on?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

烂人 2024-11-11 09:46:54

Latex ft 插件方便地定义了这种行为。

SpellChecker : 拼写检查文本,包括 LaTeX 文档

使用 Latexmk、vim 拼写检查和 vim Latex-suite

有一个选项似乎很接近:

:syntax spell [toplevel | notoplevel | default]

Update

Also

:he ft-tex-syntax

has very important tidbits ,就像

Don't Want Spell Checking In Comments? ~

Some folks like to include things like source code in comments and so would
prefer that spell checking be disabled in comments in LaTeX files.  To do
this, put the following in your <.vimrc>: >
      let g:tex_comment_nospell= 1

你必须弄清楚是否可以使用它/从那里推断

The latex ft plugin conveniently defines this behaviour.

SpellChecker : Spell check text including LaTeX documents

Using latexmk, vim spell checking and vim latex-suite

There is an option that appears to come close:

:syntax spell [toplevel | notoplevel | default]

Update

Also

:he ft-tex-syntax

has very useful tidbits, like

Don't Want Spell Checking In Comments? ~

Some folks like to include things like source code in comments and so would
prefer that spell checking be disabled in comments in LaTeX files.  To do
this, put the following in your <.vimrc>: >
      let g:tex_comment_nospell= 1

You'll have to figure out whether you can use that/extrapolate from there

冧九 2024-11-11 09:46:54

我有同样的问题(VIM 7.3),但是 vim-latex-devel 邮件列表中的这篇文章 提供了线索。为了让拼写检查工作,我必须放入

syntax spell toplevel

我的 ~/.vimrc,但是它必须在之后声明

syntax enable

才能

syntax on

工作。

I had the same problem (VIM 7.3), but this post at the vim-latex-devel mailing list provided the clue. To get the spell checking working, I had to put

syntax spell toplevel

in my ~/.vimrc, but it has to be declared after

syntax enable

or

syntax on

for it to work.

ゝ偶尔ゞ 2024-11-11 09:46:54

我不知道这是否是一个粗略的黑客和预期的解决方案,但我创建了一个名为 .vim/after/syntax/tex.vim 的文件
包含单行:

syn match texText "\<\w\+\>" contains=@Spell

现在 vim 拼写检查命令之间的普通文本和作为参数传递的文本,因为你无法在语法上区分它们:

\frametitle{TextToBeChecked}
\pgfuseimage{VariableNotToBeChecked}

因此,它在我的序言中检查太多。但我把它放在另一个文件中,所以我不在乎。

I don't whether this is a crude hack and the intended solution, but I created a file called .vim/after/syntax/tex.vim
containing the single line:

syn match texText "\<\w\+\>" contains=@Spell

Now vim spell checks the normal text between the commands and the text passed as parameters, because you cannot differentiate them syntacticly:

\frametitle{TextToBeChecked}
\pgfuseimage{VariableNotToBeChecked}

Hence, it checks way too much in my preamble. But I have it located in another file, so I don't really care.

橘寄 2024-11-11 09:46:54

处理主文档中包含的文件时经常会出现此问题。

如果您打开的 TeX 文件将被包含并且不包含节、章节、\begin{document}...,您可以通过添加 %begin-include< 来标记它/code> 在文件顶部。这样,vim 会将文件内容识别为 texDocZone 区域的一部分,从而启用拼写检查。

使用%end-include,您可以设置texDocZone的结尾。

此行为似乎没有记录,但在 vim 语法文件中进行了描述: https://github.com/vim/vim/blob/master/runtime/syntax/tex.vim

tl;dr: 添加 %begin-include< /代码>到你的 tex 文件的顶部。

This problem often occurs when working with files which are included by a master document.

If you are opening a TeX file which will be included and does not contain a section, chapter, \begin{document}, ... you can mark it by adding %begin-include at the top of the file. This way vim recognizes the file content as being part of the texDocZone region, which enables spellchecking.

With %end-include you can set the end of the texDocZone.

This behavior seems not to be documented, but is described in the vim syntax file: https://github.com/vim/vim/blob/master/runtime/syntax/tex.vim

tl;dr: Add %begin-include to the top of your tex file.

初心 2024-11-11 09:46:54

我遇到了同样的问题——我的书第一章的 .tex 文件拼写检查正常,但第二章的文件只会对注释进行拼写检查。发生这种情况显然是因为 vim 没有查看足够多的上下文行并感到困惑。 Ingo Karkat 的解决方案此处为我解决了这个问题。具体来说,我使用了:

syn sync maxlines=2000
syn sync minlines=500

在 ~/.vim/after/syntax/tex.vim 中

I encountered the same problem -- the .tex file for the first chapter of my book spell checked normally, but the file for the second chapter would only spell check the comments. This apparently happens because vim isn't looking at enough lines of context and gets confused. Ingo Karkat's solution here fixed it for me. Specifically, I used:

syn sync maxlines=2000
syn sync minlines=500

in ~/.vim/after/syntax/tex.vim

放我走吧 2024-11-11 09:46:54

tldr;不要将 \section 命令放入您的主 .tex 文档

我也做了同样的观察,我也会坚持“以前,它有效,但我没有”不改变任何东西”。

然后我观察到,这种不需要的行为仅发生在 .tex 文档中,其中我有一个 master.tex包含 章节作为单独的 chapterx .tex 文件。此外,如果所有 \section 定义都在 chapterx.tex 中并且 NOTmaster.tex 中,则一切正常

否则,正如我所想,vim语法和拼写检查例程很难确定它们位于哪个区域,参见。这个问题 Vim 拼写检查并不总是在 .tex 文件中工作。检查 Vim 中的区域

tldr; don't put \section commands in your master .tex document

I made the same observation and I also would insist on "before, it worked and I didn't change anything".

Then I observed that this unwanted behaviour only occurred in .tex documents where I have a master.tex that includes chapters as separate chapterx.tex files. Moreover, everything works fine if all the \section definitions are in the chapterx.tex's and NOT in the master.tex.

Otherwise, as I think, the vim syntax and spell checking routines have a hard time determining in which region they are, cf. this question Vim spellcheck not always working in .tex file. Check region in Vim

沉鱼一梦 2024-11-11 09:46:54

我发现了同样的问题,但解决方案不同。在某些 .tex 文件中,拼写检查按预期工作,而其他文件则不然 (documentclass{scrlttr2})。只有在评论中的单词才带有下划线......因此我比较了一份工作和一份不工作的 .tex 文档的标题。我发现了一个令人惊讶的 texblock,它阻碍了文档本身的拼写检查:

\usepackage{array}
\newenvironment{Conditio}
  {\par\vspace{\abovedisplayskip}\noindent\begin{tabular}{>{$}l<{$} @{${}={}$} l}}
  {\end{tabular}\par\vspace{\belowdisplayskip}}

而这段代码只是我之前编辑过的不同司法文本的“残留”。将其注释掉,在信件文档中设置正常的拼写检查并突出显示文本。 (MacVim 8.1 Latex 套件 macOS 10.13.6 vim-latex v1.10.0)

I found the same problem, but a different solution to it. In some .tex files the spell-check was working as expected others not (documentclass{scrlttr2}). Only in the comments words were underlined ... So I compared the headers of one working and one not working .tex document. I found a surprisingly texblock, which were hindering the spell check in the document itself:

\usepackage{array}
\newenvironment{Conditio}
  {\par\vspace{\abovedisplayskip}\noindent\begin{tabular}{>{$}l<{$} @{${}={}$} l}}
  {\end{tabular}\par\vspace{\belowdisplayskip}}

And this code was only an "hangover" of a different juridical text, I edited before. Commenting it out, set the normal spell-check with high-lighted texts in the letter document. (MacVim 8.1 latex-suite macOS 10.13.6 vim-latex v1.10.0)

情话墙 2024-11-11 09:46:54

这里的答案都不适合我,但我可以看到如果我在 vim 中输入 syntaxpell 作为命令,它会起作用。

事实证明,这是因为没有自动为 tex 文件类型设置语法,我找到了解决方案

vim 仅在 TeX 注释中进行拼写检查

用 vim 编辑 LaTeX 文档,我注意到它只是拼写检查注释。我修好了这个
将其添加到我的 ./vimrc 中:

autocmd FileType plaintex,tex,latex 语法拼写顶级

None of the answers here worked for me, but I could see if I typed syntax spell as a command in vim it would work.

It turns out it was because syntax wasn't being set for the tex filetype automatically, and I found the solution here.

vim only spell checking in TeX comments

Editing a LaTeX document with vim, I noticed it was only spell-checking comments. I fixed this
by add this to my ./vimrc:

autocmd FileType plaintex,tex,latex syntax spell toplevel

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文