> 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/loi-latex/16-latex-error-missing-begin-document.md).

# Lỗi LaTeX: Thiếu \begin document

Lỗi này xuất hiện khi bạn quên bao gồm **`\begin{document}`** trong tài liệu của bạn. Nó cũng có thể xuất hiện nếu bạn chưa viết **`\documentclass[...]{...}`** ở phần đầu của tài liệu chính.

## Nguyên nhân thường gặp

**Quên bao gồm \begin{document}:**

Nguyên nhân cơ bản nhất của lỗi này xảy ra khi bạn quên viết **`\begin{document}`** sau phần lời mở đầu trong tài liệu chính của bạn. Nếu bạn mắc lỗi này, bạn sẽ tạo ra thông báo lỗi hiển thị bên dưới:

main.tex, dòng 5

Lỗi LaTeX: Thiếu \begin{document}.

Xem hướng dẫn LaTeX hoặc LaTeX Companion để được giải thích. Gõ H để được trợ giúp ngay lập tức. ... Bạn đang gặp rắc rối ở đây. Hãy thử gõ để tiếp tục. Nếu không được, gõ X để thoát.

Để khắc phục lỗi này, chỉ cần đảm bảo rằng bạn đã bao gồm **`\begin{document}`** sau phần lời mở đầu trong tài liệu chính của bạn. Xem [ở đây](/latex/vi/kien-thuc-co-ban-ve-latex/01-learn-latex-in-30-minutes.md) để tìm hiểu thêm về cách cấu trúc tài liệu trong LaTeX.

**\documentclass\[...]{...} ở sai vị trí:**

Một nguyên nhân phổ biến khác của lỗi này là nếu **`\documentclass[...]{...}`** được viết sai vị trí. Nó phải được viết ở đầu tài liệu chính. Nếu bạn có một tệp riêng cho phần lời mở đầu của mình, bạn **không thể** bao gồm **`\documentclass[...]{...}`** trong tệp đó. Nó vẫn phải xuất hiện ở đầu tệp dự án chính, nếu không thì chỉ tệp lời mở đầu sẽ được biên dịch.

**Tài liệu chính được đặt không đúng:**

Lỗi này cũng có thể xuất hiện nếu bạn đã đặt tài liệu chính không đúng trong menu bên trái. Điều này có thể xảy ra nếu **`\documentclass[...]{...}`** được viết ở sai vị trí, vì vậy bạn nên sửa điều này trước nếu cần. Để thay đổi lựa chọn tài liệu chính, hãy mở menu bên trái:

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

và đi tới *Tài liệu chính* menu thả xuống:

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


---

# 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/loi-latex/16-latex-error-missing-begin-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.
