# document management system

I am writing technical documents with math/diagrams/plots/code etc. I want to compile them into a single document and also must be able to run each of them independently. These technical documents belonging to each topic are in their floders. Can someone guide me how to manage it better and also make it portable? Like I work on the same documents on Mac OSX/MS Windows.

-

If I understand the question correct, then a solution could be using the package subfiles.

Say that main.tex is your main file, and file1.tex, file2.tex, and file3.tex are the ones you want to include. Then your main document would look something like:

main.txt:

\documentclass[a4paper]{article}
\usepackage{subfiles}

\begin{document}

\subfile{file1}

\subfile{file2}

\subfile{file3}

\end{document}


where you are allowed to put text everywhere you like, just as if you where using \include or \input instead of \subfile. The contents of file1.tex would then look something like

file1.tex

\documentclass[main.tex]{subfiles}
\begin{document}

\end{document}


The same structure should apply to the files file2.tex and file3.tex.

Now when you compile main.tex then the contents of the files, that is, what I indicated by <your document goes here> will be included in your document, and if you compile, say file1.tex, then the contents of file2.tex will be compiled as if it had the documentclass specifications and preamble of main.tex.

So now all the files in the project can be compiled seperately, but to compile one the subfiles you will need to have main.tex in the same directory.

documentation and installation of the package

I am not sure whether subfiles comes as a standart package. It did not for me, so depending on how experienced you are with installing packages I wanted to say that the pacakges can be found at

http://www.ctan.org/tex-archive/macros/latex/contrib/subfiles/

where there also is a documentation of the package, namely the pdf document subfiles.pdf. If you don't know how to handle .ins and .dtx files then there is a small guide at

http://en.wikibooks.org/wiki/LaTeX/Packages/Installing_Extra_Packages

and if you want you can put the files subfiles.cls and subfiles.sty which are generated while building the package in the same directory as main.tex, so that you are not depending on the fact that the next system on which the files need to be compiled has the package subfiels installed.

EDIT

I have three levels of directory, 1 - toplevel which has rootfile.tex, 2- chapter level which has the main file of each chapter, 3- section level which has the actual contents of that chapter. I am instantiating 3 in 2 using \include{./Sections/part1}. How can manage such a system using subfiles? – avlsi

Suppose that you have the files

./rootfile.tex
./chapter/chap1.tex
./chapter/chap1/section1.1.tex
./chapter/chap1/section1.2.tex
./chapter/chap2.tex
./chapter/chap2/section2.1.tex
./chapter/chap2/section2.2.tex
./chapter/chap3.tex
./chapter/chap3/section3.1.tex
./chapter/chap3/section3.2.tex


and you want to include the files sectionX.1.tex and sectionX.2.tex in the file chapX.tex for X=1,2 and still be able to compile both your section files, your chapterfiles and your root file. This can be done by letting your files look something like:

rootfile.tex:

\documentclass[a4paper]{article}
\usepackage{subfiles}

\def\dirlevel{../}

\begin{document}
\def\dirlevel{}

\subfile{./chapter/chap1}
\subfile{./chapter/chap2}
\subfile{./chapter/chap3}

\end{document}


chapX.tex:

\documentclass[./../rootfile.tex]{subfiles}
\begin{document}

\subfile{./\dirlevel chap/chapX/sectionX.1}
\subfile{./\dirlevel chap/chapX/sectionX.2}

\end{document}


sectionX.Y.tex:

\documentclass[./../../rootfile.tex]{subfiles}
\begin{document}


The trick is that \def\dirlevel{} is only read if you compile rootfile.tex, whilst \def\dirlevel{../} is read no matter which of the files you compile, so no matter which file you compile LaTeX will still be able to find your files.
@avlsi Do you actually need to compile your section files individually? If not then I belive that you can just replace the path ./images/basic.ps with ./\dirleve chap1/images/basic.ps, but I don't believe that you will be able to compile your section files correctly then. –  Kristian Aug 19 '12 at 9:00