> 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/shen-ru-wen-zhang/28-how-to-use-latexmkrc-with-overleaf.md).

# 如何在 Overleaf 中使用 latexmkrc

如果你听说过，请举手 `latexmkrc` 文件？现在如果你知道它有什么作用，请继续举手。现在如果你自己写过一个，也请继续举手。到现在手还举着的人——你大概不需要读这篇文章的其余部分了。

为什么会对 `latexmkrc`？最近我们收到不少用户联系，询问如何在 Overleaf 中完成某些操作，我们的回答已经开始变成：“首先，在你的项目中创建一个自定义的 `latexmkrc` 文件……”。鉴于这并不是 LaTeX 中最直观的部分，而且网络上的文档（尤其是示例）相当稀少，我们想在这里更详细地探讨一下。

### 什么是 latexmkrc 文件？

如果你以前从未见过， `latexmkrc` 文件是用于 [`Latexmk` 宏包](https://www.ctan.org/pkg/latexmk). `Latexmk` 被 Overleaf 用来控制将你的 LaTeX 源文档编译成最终排版好的 PDF 文件。通过使用一个名为 *`Latexmk`* 的自定义配置文件，你可以覆盖默认的编译命令，使 Overleaf 能以特殊方式编译你的文档。

### 为什么我要使用 latexmkrc 文件？

嗯，举个例子，你知道 Overleaf 上编译生成的 PDF 里的所有日期和时间默认都是服务器的日期和时间吗？如果你想改用本地日期/时间呢？

要显示与你所在时区一致的日期/时间，你可以修改 `TZ` （时区）环境变量，使用自定义的 `latexmkrc` 文件：

1. 在项目编辑器窗口中，点击文件树面板顶部的“上传”图标。
2. 选择“新建文件”，并将文件命名为 `latexmkrc`.
3. 向文件中添加以下一行 `latexmkrc`:

   ```perl
   $ENV{'TZ'}='Canada/Central';
   ```

   或所需的其他时区。这里有一个 [支持的时区列表供参考](http://php.net/manual/en/timezones.php).

日期和时间（例如 `\today` 和 `\currenttime` 来自 `datetime` 包）在 PDF 中应当会给出指定时区的本地值。

一个 `latexmkrc` 文件对于调试存在致命错误的项目非常有用；有关更多内容，请参见 [编译超时帮助页面](/latex/zh-cn/zhi-shi-ku/038-fixing-and-preventing-compile-timeouts.md#fatal-compile-errors-blocking-the-compilation).

### 在哪里可以找到更多 latexmkrc 命令的示例？

首先，请查看我们帮助页面中的以下示例：

* [Overleaf 如何编译我的项目？](/latex/zh-cn/zhi-shi-ku/064-how-does-overleaf-compile-my-project.md)
* [我可以在 Overleaf 上运行 plain TeX 吗？](/latex/zh-cn/wen-da/05-can-i-run-plain-tex-on-overleaf.md)
* [Overleaf 支持 pTeX 吗？](/latex/zh-cn/wen-da/09-does-overleaf-support-ptex.md)
* [查找阻止编译的致命编译错误](/latex/zh-cn/zhi-shi-ku/038-fixing-and-preventing-compile-timeouts.md#fatal-compile-errors-blocking-the-compilation)
* [我有很多 .cls、.sty、.bst 文件，想把它们放到一个文件夹里，以保持项目整洁。但我的项目找不到它们，导致无法正确编译。](/latex/zh-cn/wen-da/59-i-have-a-lot-of-.cls-.sty-.bst-files-and-i-want-to-put-them-in-a-folder-to-keep-my-project-unclut.md)
* [我怎样才能让 xr 宏包在 Overleaf 上正常工作？](/latex/zh-cn/zhi-shi-ku/033-cross-referencing-with-the-xr-package-in-overleaf.md)
* [如何让 \today 按照我的时区显示日期？](/latex/zh-cn/wen-da/32-how-do-i-make-today-display-the-date-according-to-my-time-zone.md) （该示例在上文中重复使用）

如果这些都没有帮助，请随时 [联系我们页面](https://www.overleaf.com/contact) 或者试试广受欢迎的 [TeXStackExchange](http://tex.stackexchange.com) 和 [LaTeXCommunity](http://latex-community.org/) 论坛。


---

# 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/shen-ru-wen-zhang/28-how-to-use-latexmkrc-with-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.
