I want to provide some structure for my thesis source files. I decided to use nested directories. Every directory contains main.tex index file to be imported by a file in the parent directory.

From Path to External Files in Nested \input I learned about import package, however it is not working for me.

For the simplest case

+- main.tex: |\documentclass{report}
|            |\usepackage{import}
|            |\begin{document}
|            |main
|            |
|            |\subimport{a}{main.tex}
|            |\end{document}
+- a/
    +- main.tex: |a main

I expect to have result like:


a main

Instead, I get the following error during compilation:

$ pdflatex main
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian)
 restricted \write18 enabled.
entering extended mode
LaTeX2e <2011/06/27>
Babel <3.9h> and hyphenation patterns for 5 languages loaded.
Document Class: report 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/import/import.sty) (./main.aux)

! LaTeX Error: Can be used only in preamble.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.

l.1 \documentclass

\subimport{a}{main} nor \subimport{a/}{main} neither works.

How can I tell the import package not to look for import files in the root directory? Also I wonder, if the issue won't occur in subdirectories too (at the moment I was unable to cause it).

  • The best way is to have unique names ... – Zarko Feb 8 '17 at 20:49
  • why use \import at all? just use \input{a/main} but i see no advantage in giving multiple files the same name. – David Carlisle Feb 8 '17 at 21:00
  • @Zarko: names are unique within a directory – abukaj Feb 8 '17 at 21:04
  • @DavidCarlisle: imagine length of a path for file in sub-sub-subdirectory, all directories with meaningful names. Then imagine that for some reason I may want to move/rename one of the directories with minimal effort. – abukaj Feb 8 '17 at 21:08
  • 2
    the input all need to be relative to the working directory – David Carlisle Feb 8 '17 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.