Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've read about the import package and am now trying to use it in my document, but I only run into errors. I have a main file named /ProjectPath/header.tex which loads all packages, etc. Additionally, some further customisations are located in /ProjectPath/header/ and are loaded by /ProjectPath/header.tex.

Now I have several chapters like /ProjectPath/chap1/ etc. Usually, I had all my files (the header files, the chapter files, the subchapter files, etc.) in one single folder and could easily compile Chapter1:

\input{header}

\begin{document}
    …
\end{document}

To get more clarity it is of course useful to put the files into folders. I've read the documentation about the import package but I do not understand how to use the \import command.

Lets say I have following configuration:

/ProjectPath/header.tex             %% main file
/ProjectPath/header/custom1.tex     %% is loaded by header.tex
/ProjectPath/header/custom2.tex     %% is loaded by header.tex

/ProjectPath/chap1/part1.tex
/ProjectPath/chap1/part2.tex
/ProjectPath/chap1/part3.tex
/ProjectPath/chap1/part4.tex
/ProjectPath/chap1/chapter1.tex     %% whole first chapter, can be compiled separately

/ProjectPath/chap2/part1.tex
/ProjectPath/chap2/part2.tex
/ProjectPath/chap2/part3.tex
/ProjectPath/chap2/part4.tex
/ProjectPath/chap2/chapter2.tex     %% whole second chapter, can be compiled separately

/ProjectPath/Document.tex           %% whole document, includes both chapters

Of course, now I can't use \input{../header.tex} in /ProjectPath/chap1/chapter1.tex. I am sure, I can get this fixed with the import package, but how?

Any suggestions would be much appreciated!


Edit: Sorry for missing MWE. Here it is:

In the simplest case I have the following files:

/header.tex
/header/custom.tex   %% is imported by header.tex
/chap1/part1.tex     %% loads header.tex

Contents:

%% header.tex
\documentclass{article}
\usepackage{import} 
\subimport{header}{custom}

%% part1.tex
\input{../header}
\begin{document}
    Text.
\end{document}

Compiling part1.tex yields in:

! LaTeX Error: File `custom.tex' not found.

Latex Error: ../header.tex:4 Emergency stop.

What's wrong? I'm a bit slow today, I still don't get the correct use of the import package…

share|improve this question
    
Try switching the use of \input and \subimport (cf. my answer). –  dgs Jun 4 '12 at 12:46
add comment

2 Answers

Here is an example showing the import of a higher-level file by a file in a subfolder, which is what I understood you want to achieve with the header file. A file chapter1.tex is located in a /subfolder. It loads two files: part1.tex, which is located in the same /subfolder, and partA.tex from the home folder. partA.tex also loads part1.tex; it therefore corresponds to the header file in the example you've added.

Using subimport{}{} is necessary for partA.tex to let it use its own path to find part1.tex. Since the latter does not make any further imports, it can always be included by means of input.

main.tex    
partA.tex              %your header.tex
subfolder/chapter1.tex
subfolder/part1.tex    %your custom.tex

%main.tex
\documentclass{article} 
\usepackage{import}
\usepackage{lipsum}

\begin{document}
    \subimport*{subfolder/}{chapter1}
\end{document}

%subfolder/chapter1.tex
\section{Chapter 1}

\input{part1}
%\input{../partA}   %doesn't work
\subimport*{../}{partA}

%/subfolder/part1.tex
\subsection{Part 1}
\lipsum[1]

%partA.tex
\subsection{Part A} 
\lipsum[2]

\input{subfolder/part1}

enter image description here

share|improve this answer
add comment

According to the import package description, the \subimport command is your friend. You can use it like this:

\subimport{subdirectory}{filename}

or, a few examples in your case:

\subimport{header}{custom1}
...
\subimport{chap1}{part1}

...and so on. Apparently the extension of the file is not required

share|improve this answer
    
My header file includes: \usepackage{import} \subimport{header}{custom1} \subimport{header}{custom2} Now, chapter1 includes: \input{../header} \begin{document} … I got the error message "custom1.tex not found". What's wrong? –  Pete Jun 4 '12 at 10:06
1  
That's pretty confusing... Why don't you post a MWE? –  Count Zero Jun 4 '12 at 10:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.