> 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/wen-da/05-can-i-run-plain-tex-on-overleaf.md).

# 我可以在 Overleaf 上运行 plain TeX 吗？

是的——你可以按照下面描述的设置步骤，将项目配置为使用 plain TeX 进行编译。

1. 在 Overleaf 编辑器中，点击 **菜单** 按钮，并将 **编译器** 选项设置为 `LaTeX`——从下拉列表中选择 `LaTeX` ，如下方视频片段所示：

{% embed url="<https://www.filepicker.io/api/file/Iw9UYRbxRBy3Bk61YKqj>" %}

3. 向你的项目添加一个空白文件，并将其保存为 `latexmkrc`——它不应有任何文件扩展名（如果你的项目已经有一个 `latexmkrc` 文件）的话，你可能不需要添加这个。
4. 将下面这一行添加到你的 `latexmkrc` 文件中：

```
$latex = 'tex %O %S';
```

#### 这个 latexmkrc 文件到底做什么？

不展开细节来说，Overleaf 的服务器使用一个名为 [`latexmk`](https://mg.readthedocs.io/latexmk.html) 的程序来运行和控制基于 TeX/LaTeX 的排版。 `latexmk` 该程序允许 Overleaf 用户通过添加一个名为 `latexmkrc`的配置文件来影响他们项目的排版。希望进一步了解的读者可以阅读 `latexmkrc` 配置文件，位于 [该 `latexmk` 网站](https://mg.readthedocs.io/latexmk.html#configuration-files).

#### 示例

该 `latexmk` 程序是用 [Perl 编程语言](https://www.perl.org/) 编写的，它使用井号（#）作为注释符号（很像 TeX/LaTeX 通常使用百分号（%））。如果你想尝试使用不同的 TeX 引擎来处理 plain TeX，你可以创建一个 `latexmkrc` 文件，并将下面的文本复制/粘贴到其中：

```
# $latex = 'tex %O %S'; # 使用 Knuth 最初的 TeX 引擎
# $latex = 'pdftex %O %S'; # 使用 pdfTeX 引擎
# $latex = 'luatex %O %S'; # 使用 LuaTeX 引擎
# $latex = 'xetex %O %S';  # 使用 XeTeX 引擎
```

要使用某个特定的 TeX 引擎，请取消该引擎对应行的注释（删除开头的 '#' 字符）。例如，要运行 XeTeX，你需要取消最后一行的注释，这样你的 `latexmkrc` 文件看起来如下所示——注意最后一行并不以 '#' 字符开头，因此它会被执行/运行，以便使用 XeTeX 对你的 plain TeX 文档进行排版：

```
# $latex = 'tex %O %S'; # 使用 Knuth 最初的 TeX 引擎
# $latex = 'pdftex %O %S'; # 使用 pdfTeX 引擎
# $latex = 'luatex %O %S'; # 使用 LuaTeX 引擎
$latex = 'xetex %O %S';  # 使用 XeTeX 引擎
```

下面这段简短视频展示了以上 `latexmkrc` 文件被有选择地编辑，从而依次运行每个 TeX 引擎——从 XeTeX 开始。此示例中使用的 plain TeX 源代码借用了 [D. R. Wilkins 的一篇文章](https://www.ntg.nl/doc/wilkins/pllong.pdf).

{% embed url="<https://www.filepicker.io/api/file/9PVmkgTSSny7gjNliTdt>" %}

### 延伸阅读

我们还有两个相关的帮助条目，可能会让希望更好理解 Overleaf 如何使用 `latexmk` 和 `latexmkrc`:

* [Overleaf 如何编译我的项目？](/latex/zh-cn/zhi-shi-ku/064-how-does-overleaf-compile-my-project.md)
* [如何在 Overleaf 中使用 latexmkrc：示例与技巧](/latex/zh-cn/shen-ru-wen-zhang/28-how-to-use-latexmkrc-with-overleaf.md)


---

# 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/wen-da/05-can-i-run-plain-tex-on-overleaf.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.
