> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 新增 LaTeX 相依檔案

如果您的專案中有 `.cls`、`.sty`、`.bst` 檔案，除非這些檔案放在最上層，否則 Overleaf 的編譯程序將無法找到它們。

然而，為了整理專案，您可能會希望將這些檔案放進資料夾中，方便尋找，也避免專案最上層顯得雜亂。

好消息是，我們可以透過 `latexmkrc` 檔案指定自訂的 `TEXINPUTS` 目錄，讓 Overleaf 知道需要在該目錄中搜尋套件檔案。

具體做法如下：假設您已將這些套件檔案放在名為 `tex/` 的資料夾中，並將參考文獻樣式檔放在名為 `bst/` 的資料夾中：

1. 點選專案側邊欄上方的「新增檔案」。
2. 選擇「空白檔案」，並將檔名儲存為 `latexmkrc`（若尚未存在）。
3. 在 `latexmkrc` 中加入以下內容：

   ```perl theme={null}
   $ENV{'TEXINPUTS'}='./tex//:' . $ENV{'TEXINPUTS'}; 
   $ENV{'BSTINPUTS'}='./bst//:' . $ENV{'BSTINPUTS'};
   ```

   （或改成您專案中對應的資料夾名稱）

現在 Overleaf 會先搜尋 `tex/` 資料夾，再搜尋系統的 `TEXINPUTS` 來尋找套件檔案；並會先搜尋 `bst/` 資料夾，再搜尋系統的 `BSTINPUTS` 來尋找參考文獻樣式檔。

（來源：[https://tex.stackexchange.com/a/50847](https://tex.stackexchange.com/a/50847)）

<Info>
  您的主文件檔案與 `latexmkrc` 檔案必須保留在專案的最上層，不能放在資料夾中。
</Info>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.