I use TexStudio with a nested structure, in other words I have many files in many folders to help keep things tidy. The problem happens when I have to import another document.

    \usepackage{float, newfloat}
    \usepackage{amsmath, mathrsfs, amsfonts, amsbsy, amsthm}
    \usepackage{graphicx, epstopdf}
    \usepackage[lmargin=2.5cm, rmargin=2.5cm, tmargin=2.5cm, bmargin=2.5cm]{geometry}
    % Definition of some commands
    % FONTS
    % WORDS
        \newcommand{\eto}{\ensuremath{\, \mathrm{e}}}
        \newcommand{\tento}[1]{\ensuremath{ \times 10^{#1}}}
        % Importing the title and the introduction =========================================================================
        \ \thispagestyle{empty}
        \ \clearpage
        % Importing the various chapters ==============================================================
        \import{./Chapter 1/}{basics}

Usually I can make the program 'run' from imported files (by pressing F5) but when creating a new file to import I can no longer do that. And the program gives me the error:

Missing \begin{document}. \subsection*

The program works fine if I make the script run from the main.tex file and from every other file that I've created before. What can I do?

I'll add some screenshots to explain better: This is what happen when I run the program from the main file Instead this is what happen when I run the program from the imported file

The first shows what happens when I run the program from the main file, and the second instead what happen when I run the program from the imported file.

  • 1
    I'm not familiar with TeXstudio, but I would instead \import rather use include command. Both should be independent from used editor (both are LaTeX commands).
    – Zarko
    Nov 18, 2021 at 12:15

1 Answer 1


You should define a master document and pay attention while creating new files with Ctrl + Click in TeXstudio. From your screenshots, it seems you don't use the Structure at the left side, so I'm not sure where your files are stored.

I created a new file within the command import and it was created in the same folder as document.tex. Compiling will return an error: File section1/input_file_from_folder.tex' not found. \import{section1/}{input_file_from_folder}` .

enter image description here

Moving it inside the folder section1, will work if you compile (F5) from document.tex, but not from the imported file.

enter image description here

Defining document.tex as master document (explicit root) solves the issue.

enter image description here

Please, notice that a symbol at the left side of document.tex has added. This symbol means that document is the root. It will always be present at the top.

enter image description here


  1. I'm using TeXstudio version 3.1.2, but this feature is older than this version and works at the newer versions.
  2. Documents on the left panel named Structure change colors and show when TeXstudio recognizes/finds them and when not, but it doesn't mean the compilation process will or will not work. It should be so, but this feature behaves a little bit strange.
  3. Setting the master document works with inputs, includes and (sub)imports.

Suggestions to read:

Edit: document.tex:


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .