> 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/pl/baza-wiedzy/127-set-main-document.md).

# Ustaw dokument główny

Główny dokument w Overleaf to plik, który LaTeX zostanie poinstruowany, aby skompilować jako pierwszy. Jest to główny plik projektu, do którego będą wczytywane wszystkie inne części (klasy, pakiety, rozdziały itp.). Gdy nie zostanie to ustawione ręcznie, Overleaf wybierze w projekcie dokument, który zawiera **`\documentclass[...]{...}`** polecenie. Z tego powodu, jeśli masz osobny plik na preambułę, lepiej nie umieszczać w nim **`\documentclass[...]{...}`** polecenia w pliku preambuły, lecz raczej na początku głównego dokumentu. Jeśli tego nie zrobisz, skompilowana zostanie tylko preambuła. Aby ustawić główny dokument w projekcie, po prostu kliknij menu w lewym górnym rogu:

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

i przejdź do **Główny dokument**:

![Maindocument.PNG](/files/2f4357894571993ff26c70a6d96bb383f70b0df3)

Zobacz [tutaj](/latex/pl/struktura-dokumentu/07-management-in-a-large-project.md) aby dowiedzieć się więcej o zarządzaniu dużymi projektami w LaTeX-u.

## Kompilowanie kilku dokumentów w tym samym projekcie

Aby umożliwić szybkie kompilowanie różnych dokumentów w tym samym projekcie, Overleaf skompiluje jako główny dokument ten plik, który jest otwarty w edytorze, gdy tylko zawiera on **`\documentclass[...]{...}`** polecenie. Jest to szczególnie wygodne podczas edycji z użyciem [**`subfiles`** pakietu](/latex/pl/struktura-dokumentu/08-multi-file-latex-projects.md#the-subfiles-package).

## Problemy z wyborem głównego pliku

Główny plik powinien zawsze znajdować się w katalogu głównym (poza jakimikolwiek folderami), aby zapewnić, że wszystkie kroki kompilacji zostaną wykonane w odpowiednim katalogu oraz że wymagane pliki pomocnicze będą dostępne, na przykład podczas [dodawania indeksu](/latex/pl/struktura-dokumentu/04-indices.md). Zobacz kilka wskazówek dotyczących reorganizacji projektu, aby kompilować go w Overleaf [tutaj](/latex/pl/pytania-i-odpowiedzi/77-my-main-file-is-in-a-subfolder-but-this-is-not-allowed-on-overleaf.-but-i-don-t-want-to-change-my.md).

Jeśli wybrany główny plik znajduje się w folderze, a w katalogu głównym istnieje plik o tej samej nazwie, zostanie skompilowany plik o tej nazwie z katalogu głównego, a nie wybrany. Np. jeśli `version1/main.tex` jest ustawiony jako główny plik, ale `main.tex` jest również w projekcie, `main.tex` zostanie skompilowany. Problem ten wynika ze sposobu, w jaki Latexmk jest uruchamiany w Overleaf. Aby uniknąć związanych z tym problemów, nadaj wszystkim plikom, które chcesz kompilować w Overleaf, unikalną nazwę.


---

# 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/pl/baza-wiedzy/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.
