> 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/shen-du-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` 的配置/初始化（RC）文件，它被 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 上运行纯 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://ayakaleaf-pro.ayaka.space/latex/zh-cn/shen-du-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.
