0

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.

    \documentclass[a4paper,12pt,twoside,openright]{report}
    \usepackage[T1]{fontenc}
    \usepackage[utf8x]{inputenc}
    \usepackage[english]{babel}
    \usepackage{float, newfloat}
    \usepackage{svg}
    \usepackage{import}
    \usepackage{makecell}
    \usepackage{amsmath, mathrsfs, amsfonts, amsbsy, amsthm}
    \usepackage{graphicx, epstopdf}
    \usepackage[lmargin=2.5cm, rmargin=2.5cm, tmargin=2.5cm, bmargin=2.5cm]{geometry}
    \usepackage{setspace}
        \onehalfspacing
    
    % Definition of some commands
    % FONTS
        \newcommand{\definiz}[1]{\textbf{\textit{#1}}}
        \newcommand{\symdef}[1]{\ensuremath{\pmb{#1}}}
        \newcommand{\unit}[1]{\ensuremath{\mathrm{#1}}}
        \newcommand{\code}[1]{\texttt{#1}}
        \newcommand{\important}[1]{\textit{#1}}
        \newcommand{\strangeword}[1]{\textit{#1}}
    
    % WORDS
        \newtheoremstyle{mystyle}{\topsep}{\topsep}{\normalfont}{0pt}{\bfseries}{:}{0.5em}{}
        \theoremstyle{mystyle}
        \newtheorem*{definition}{Definition}
        \newtheorem*{example}{Example}
        \newtheorem*{problem}{Problem}
        
    % MATH SYMBOL
        \newcommand{\eto}{\ensuremath{\, \mathrm{e}}}
        \newcommand{\tento}[1]{\ensuremath{ \times 10^{#1}}}
        \newcommand{\Real}{\ensuremath{\mathbb{R}}}
        
    \begin{document}
        % Importing the title and the introduction =========================================================================
        \import{./Titlepage/}{titlepage}
        \ \thispagestyle{empty}
        \clearpage
        
        \import{./Titlepage/}{introduction}
        \ \clearpage
        
        % Importing the various chapters ==============================================================
        \import{./Chapter 1/}{basics}
        
        
    \end{document}

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
  • 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
    Commented Nov 18, 2021 at 12:15

1 Answer 1

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

Notes:

  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:

\documentclass{article}
\usepackage{import}
\begin{document}
\import{section1/}{input_file_from_folder}
\end{document}

You must log in to answer this question.

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