> 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/overleaf-learn-latex-pt/erros-do-latex/16-latex-error-missing-begin-document.md).

# Erro LaTeX: Falta \begin document

Este erro aparece quando se esqueceu de incluir **`\begin{document}`** no seu documento. Também pode aparecer se não tiver escrito **`\documentclass[...]{...}`** no início do seu documento principal.

## Causas comuns

**Esquecer-se de incluir \begin{document}:**

A causa mais básica deste erro ocorre quando se esqueceu de escrever **`\begin{document}`** depois do preâmbulo no seu documento principal. Se cometer este erro, irá gerar a mensagem de erro mostrada abaixo:

main.tex, linha 5

Erro LaTeX: Falta \begin{document}.

Consulte o manual do LaTeX ou o LaTeX Companion para uma explicação. Escreva H para ajuda imediata. ... Está em apuros aqui. Tente escrever para prosseguir. Se isso não funcionar, escreva X para sair.

Para resolver este erro, certifique-se simplesmente de que incluiu **`\begin{document}`** depois do preâmbulo no seu documento principal. Veja [aqui](/latex/overleaf-learn-latex-pt/nocoes-basicas-de-latex/01-learn-latex-in-30-minutes.md) para saber mais sobre como estruturar documentos em LaTeX.

**\documentclass\[...]{...} no local errado:**

Outra causa comum deste erro é se **`\documentclass[...]{...}`** estiver escrito no local errado. Isto tem de ser escrito no início do documento principal. Se tiver um ficheiro separado para o seu preâmbulo, você **não pode** incluir **`\documentclass[...]{...}`** nesse ficheiro. Ainda assim, tem de aparecer no topo do ficheiro principal do projeto, caso contrário apenas o ficheiro do preâmbulo será compilado.

**Documento principal definido incorretamente:**

Este erro também pode aparecer se tiver definido incorretamente o documento principal no menu da esquerda. Isto pode acontecer se **`\documentclass[...]{...}`** estiver escrito no local errado, por isso deve corrigir isto primeiro, se necessário. Para alterar a escolha do documento principal, abra o menu da esquerda:

![Lefthandmenu.PNG](/files/a8af31dc784f41f7c2c5ddce586b9cf21c08cde5)

e vá para o *Documento principal* menu pendente:

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


---

# 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/overleaf-learn-latex-pt/erros-do-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.
