> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/zh-cn/zhi-shi-ku/029-code-check.md).

# 代码检查

Overleaf 编辑器内置语法检查器（称为“Code Check”），会在你输入时高亮显示常见错误。

Code Check 可以发现的错误包括：

* 不匹配的 `\begin` 和 `\end` 命令
* 不匹配的 LaTeX 组分隔符 `{ }`
* 不匹配的 `\left` 和 `\right` 分隔符
* 不匹配的数学模式分隔符 `$..$` 和 `$$..$$`
* 在数学模式之外使用的数学命令
* 在数学模式内使用的文本命令

Code Check 使用启发式方法，并假定文档是典型的 LaTeX，只使用标准命令，例如每个 `\begin{}` 都有相应的 `\end{}`.

## Code Check 的局限性

如果你的项目使用了自定义的 LaTeX 或 TeX 宏，或会改变标准 LaTeX 行为的宏包，你可能会发现需要关闭 Code Check——你可以全局关闭、对单个文件关闭，或对文件的一部分关闭。

特别是，如果你把宏用作标准 LaTeX 环境的快捷方式（例如 `\newcommand{\beq}{\begin{equation}}`）这些不会被展开，你应该禁用 Code Check。

## 全局禁用 Code Check

如果你完全不想使用 Code Check，可以在左侧菜单中将其关闭：点击文件列表面板上方的 Overleaf 菜单图标，然后找到“Settings - Code Check”。

## 为单个文件禁用 Code Check

要为单个文件关闭 Code Check，请在文件顶部添加注释 `%%novalidate` 在文件顶部。（注意：为避免冲突，我们使用双注释符号）。

```latex
%%novalidate

% 复杂的宏定义或 Tikz 图形
% ...
```

## 为文件的一部分禁用 Code Check

你也可以为文件的一部分关闭 Code Check

```latex
文件的这一部分会通过 Code Check 检查

%%begin novalidate
这部分不会被检查
%%end novalidate

这部分也会通过 Code Check 检查
```

## 已知问题

* Url、verbatim 以及其他满足以下条件的命令： `%` 是字面字符时，如果该命令所在行后面还有 LaTeX 代码，可能会产生误报。一个解决方法是在任何 `\url{}` 或其他包含字面 `%` 字符的命令。
* 使用 LaTeX3 语法且宏名中包含下划线的命令。
* 将以下内容分开的自定义命令定义： `\begin{...}` 来自 `\end{...}` 语句


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/zh-cn/zhi-shi-ku/029-code-check.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
