> For the complete documentation index, see [llms.txt](https://ayakaleaf-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://ayakaleaf-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://ayakaleaf-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.
