> 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/it/base-di-conoscenza/127-set-main-document.md).

# Imposta documento principale

Il documento principale in Overleaf è il file che LaTeX verrà istruito a compilare per primo. È il file principale del progetto, nel quale verranno inclusi tutti gli altri elementi (classi, pacchetti, capitoli, ecc.). Quando questo non è impostato manualmente, Overleaf sceglierà nel progetto un documento che include il **`\documentclass[...]{...}`** comando. Per questo motivo, se hai un file separato per il preambolo, è meglio non includere il **`\documentclass[...]{...}`** comando nel file del preambolo, ma piuttosto all'inizio del documento principale. Se non lo fai, verrà compilato solo il preambolo. Per impostare il documento principale in un progetto, fai semplicemente clic nel menu nell'angolo in alto a sinistra:

![MenuSinistro.PNG](/files/05b2a68a5001ac5a539b2daff063a59df2aa2413)

e vai su **Documento principale**:

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

Vedi [qui](/latex/it/struttura-del-documento/07-management-in-a-large-project.md) per saperne di più sulla gestione di progetti di grandi dimensioni in LaTeX.

## Compilazione di più documenti nello stesso progetto

Per consentirti di compilare rapidamente documenti diversi nello stesso progetto, Overleaf compilerà come documento principale il file che è aperto nell'editor non appena include il **`\documentclass[...]{...}`** comando. Questo è particolarmente comodo per modificare con i [**`subfiles`** pacchetto](/latex/it/struttura-del-documento/08-multi-file-latex-projects.md#the-subfiles-package).

## Problemi con la selezione del file principale

Il file principale dovrebbe sempre trovarsi nella directory radice (al di fuori di qualsiasi cartella), per assicurare che tutti i passaggi di compilazione vengano eseguiti nella directory corretta e che i file ausiliari richiesti siano disponibili, ad esempio quando [si aggiunge un indice](/latex/it/struttura-del-documento/04-indices.md). Vedi alcuni suggerimenti su come riorganizzare il tuo progetto per compilarlo su Overleaf [qui](/latex/it/domande-e-risposte/77-my-main-file-is-in-a-subfolder-but-this-is-not-allowed-on-overleaf.-but-i-don-t-want-to-change-my.md).

Se il file principale selezionato si trova in una cartella e nella directory radice c'è un file con lo stesso nome, verrà compilato il file con quel nome nella directory radice invece della selezione. Ad es., se `version1/main.tex` è impostato come file principale ma `main.tex` è presente anche nel progetto, `main.tex` verrà compilato. Questo problema è dovuto al modo in cui Latexmk viene eseguito su Overleaf. Per evitare problemi, assegna a tutti i file che vorrai compilare su Overleaf un nome univoco.


---

# 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/it/base-di-conoscenza/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.
