> 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/vi/co-so-tri-thuc/127-set-main-document.md).

# Đặt tài liệu chính

Tài liệu chính trong Overleaf là tệp mà LaTeX sẽ được yêu cầu biên dịch đầu tiên. Đây là tệp chính của dự án, mà tất cả các phần khác (lớp, gói, chương, v.v.) sẽ được đưa vào. Khi không được đặt thủ công, Overleaf sẽ chọn một tài liệu trong dự án có chứa **`\documentclass[...]{...}`** lệnh này. Vì lý do này, nếu bạn có một tệp riêng cho phần tiền đề, tốt hơn là không nên đưa **`\documentclass[...]{...}`** lệnh này vào tệp tiền đề, mà nên đặt nó ở đầu tài liệu chính. Nếu bạn không làm vậy, chỉ phần tiền đề sẽ được biên dịch. Để đặt tài liệu chính cho một dự án, chỉ cần nhấp vào menu ở góc trên bên trái:

![Lefthandmenu.PNG](/files/3d7ee49a57496ccb503a1d67486b53f8321fbbe2)

và đi tới **Tài liệu chính**:

![Maindocument.PNG](/files/e3fb5a75ae52a2cd8a09a82e7dcf403b0d0a31c7)

Xem [ở đây](/latex/vi/cau-truc-tai-lieu/07-management-in-a-large-project.md) để tìm hiểu thêm về cách quản lý các dự án lớn trong LaTeX.

## Biên dịch nhiều tài liệu trong cùng một dự án

Để cho phép bạn nhanh chóng biên dịch các tài liệu khác nhau trong cùng một dự án, Overleaf sẽ biên dịch bất kỳ tệp nào đang mở trong trình soạn thảo làm tài liệu chính khi nó bao gồm **`\documentclass[...]{...}`** lệnh này. Điều này đặc biệt tiện lợi khi chỉnh sửa với [**`subfiles`** gói](/latex/vi/cau-truc-tai-lieu/08-multi-file-latex-projects.md#the-subfiles-package).

## Các vấn đề với việc chọn tệp chính

Tệp chính luôn nên nằm trong thư mục gốc (bên ngoài mọi thư mục con), để đảm bảo tất cả các bước biên dịch sẽ được chạy trong đúng thư mục và để đảm bảo các tệp phụ trợ cần thiết có sẵn, ví dụ, khi [thêm chỉ mục](/latex/vi/cau-truc-tai-lieu/04-indices.md). Xem một số mẹo về sắp xếp lại dự án của bạn để biên dịch trên Overleaf [ở đây](/latex/vi/cau-hoi-and-tra-loi/77-my-main-file-is-in-a-subfolder-but-this-is-not-allowed-on-overleaf.-but-i-don-t-want-to-change-my.md).

Nếu tệp chính được chọn nằm trong một thư mục và có một tệp cùng tên trong thư mục gốc, thì tệp có tên đó trong thư mục gốc sẽ được biên dịch thay vì lựa chọn đã chọn. Ví dụ, nếu `version1/main.tex` được đặt làm tệp chính nhưng `main.tex` cũng có trong dự án, `main.tex` sẽ được biên dịch. Vấn đề này là do cách Latexmk được chạy trên Overleaf. Để tránh các sự cố từ điều này, hãy đặt cho bất kỳ tệp nào bạn muốn biên dịch trên Overleaf một tên duy nhất.


---

# 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/vi/co-so-tri-thuc/127-set-main-document.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.
