> 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-tw/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` 的設定／初始化（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 中應會顯示指定時區的當地值。

A `latexmkrc` 檔案對於偵錯有致命錯誤的專案非常有用；請在 [編譯逾時說明頁面](/latex/zh-tw/zhi-shi-ku/038-fixing-and-preventing-compile-timeouts.md#fatal-compile-errors-blocking-the-compilation).

### 我可以在哪裡找到更多 latexmkrc 指令的範例？

首先，請查看我們說明頁面中的以下範例：

* [Overleaf 如何編譯我的專案？](/latex/zh-tw/zhi-shi-ku/064-how-does-overleaf-compile-my-project.md)
* [我可以在 Overleaf 上執行純 TeX 嗎？](/latex/zh-tw/wen-yu-da/05-can-i-run-plain-tex-on-overleaf.md)
* [Overleaf 支援 pTeX 嗎？](/latex/zh-tw/wen-yu-da/09-does-overleaf-support-ptex.md)
* [找出阻礙編譯的致命編譯錯誤](/latex/zh-tw/zhi-shi-ku/038-fixing-and-preventing-compile-timeouts.md#fatal-compile-errors-blocking-the-compilation)
* [我有很多 .cls、.sty、.bst 檔案，想把它們放到一個資料夾裡，讓我的專案看起來更整潔。但我的專案找不到它們，因此無法正確編譯。](/latex/zh-tw/wen-yu-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-tw/zhi-shi-ku/033-cross-referencing-with-the-xr-package-in-overleaf.md)
* [我要如何讓 \today 依照我的時區顯示日期？](/latex/zh-tw/wen-yu-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-tw/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.
