GeneralCombining or merging several TEX files into one document?

LaTeX specific issues not fitting into one of the other forums of this category.
Jay
Posts: 2
Joined: Tue May 06, 2008 8:48 pm

Combining or merging several TEX files into one document?

Post by Jay »

To start: I'm using TexLive2007 on OS X 10.5.2 and TeXShop as my environment. I'm a noob at this first month using LaTex andmy first try at a large document. I've google searched the heck out of this problem and looked in all the FAQs and textbooks. I can't find anything. An earlier post on this forum suggest the same approach should work that I've used.

I'm using a file called "Main.tex". Within this file is the code below. I have approx. 15 tex files (named here as file1 ... file4). I'd like to only have Main.tex call up these Tex files and typeset them into one PDF. All the Tex files 1 through 15 work correctly and the document looks fine. No errors.

You'll see that I've commented out several lines, which comprise of "\include{} statements. I've tried to combine the files using both \input and \include (substituting out the commented lines) and doing this in the preamble and after the \begin{document}. None of it works. The only think I've accomplished so far is to get file one to "typeset" into PDF - even when \input{file2} is included. I've also removed the \begin and \end statments and it seems to work even without the \usepackage{combine} but it only typesets

Code: Select all

%\usepackage{combine}
%\documentclass[final]
\input{file1}
\input{file2}
\begin{document}
%\pagestyle{combine}
%\include{file3}
%\include{file4}
%\begin{document}
\input{file1}
\input{file2}
%\include{file3}
%\include{file4}
\end{document}
I should add, from some of the references I've seen, to use the \input or \include commands, you need to call up the combine package. This doesn't seem to be included in TexLive so I downloaded it from CTAN and installed it in my ~....texmf/tex/latex directory.

Again, I'm a noob at this. Perhaps there's another way to combine the files? Sorry for length. I know sometimes posts aren't detailed enough and it doesn't help anybody. :) I would greatly appreciate any feedback.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Combining or merging several TEX files into one document?

Post by gmedina »

Jay wrote:

Code: Select all

%\usepackage{combine}%this line should not be here
%\documentclass[final]%final is not a document class file
\input{file1}%this line should not be here
\input{file2}%this line should not be here
\begin{document}
%\pagestyle{combine}%??
%\include{file3}
%\include{file4}
%\begin{document}%more than one \begin{document}!!
\input{file1}
\input{file2}
%\include{file3}
%\include{file4}
\end{document}
If I correctly understood your question then you do not need the combine package.

Try this simple example:
Main.tex:

Code: Select all

\documentclass{book}
\usepackage{lipsum}% automated generation of text 

\begin{document}
\include{file1}
\include{file2}
\end{document}
file1.tex:

Code: Select all

\chapter{First chapter}
\lipsum[1-20]
file2.tex:

Code: Select all

\chapter{Second chapter}
\lipsum[1-20]
As you can see, the preamble goes in Main.tex and not in the subsidiary files.

Process Main.tex only.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Jay
Posts: 2
Joined: Tue May 06, 2008 8:48 pm

Combining or merging several TEX files into one document?

Post by Jay »

I've gotten it to work! The problem, and it wasn't specified in the sites/documentation I read was that only the Main.tex (in this example) should have the \begin{document} .... \end{document} tags as well as all the preamble.

Your suggestion of:
As you can see, the preamble goes in Main.tex and not in the subsidiary files.
was a real save. Thank you, Thank you, Thank you! :) I spent 8 hours working on this.

Now my documents are being Typeset correctly. There's some errors, mostly it looks like 'hbox badness' and bibcite problems. I have a lot of references in these documents using the APA and MLA formats. I'm just using \bibitem{1} .... Bibliography information for document ...... and on for the rest of the citations. I think its because if its a longpiece:(of)text,likethis which is sometimes how the bibs have to be written (without spaces), it will foobar the bibitem. If I just hit return it continues to Typeset correctly. I'll continue onwards unless someone has a quick-easy suggestion to fix.

Thanks again gmedina.
User avatar
tripwire45
Posts: 129
Joined: Thu Apr 10, 2008 4:35 am

Re: Combining or merging several TEX files into one document?

Post by tripwire45 »

Sorry to bring this thread "back from the dead", but it's a subject that's just been presented to me here at my work.

I maintain a user manual for a specific product that includes several step-by-step exercises. The output is in PDF format which works fine, since the user manual is distributed in both PDF and hardcopy.

The primary interface for our product is web-based and the developers want to be able to take just the exercises I've created (and not the other content in the user manual) and use them to create HTML help pages. They propose that I create each step-by-step exercise as a series of separate .tex files that they can then "pull" from subversion (where all our content is committed) generate as HTML, and insert in the product's web interface as help pages.

I can certainly create the exercises as separate files and then use the \include tag to insert the exercises at the required points in the user manual. However, will the developers be able to use the individual exercises files as I've described, or is there a better way to accomplish this task?

Thanks.

-Trip
User avatar
tripwire45
Posts: 129
Joined: Thu Apr 10, 2008 4:35 am

Re: Combining or merging several TEX files into one document?

Post by tripwire45 »

:bump:

Any ideas?

Thanks.
User avatar
T3.
Posts: 208
Joined: Fri Mar 14, 2008 12:58 pm

Combining or merging several TEX files into one document?

Post by T3. »

Hi Trip,

Look at tex4ht and latex2html for html generation from latex sources. As a bare bones solution you could do the following:

Code: Select all

echo \input{preamble.tex}\begin{document}\input{exercise.tex}\end{document}>test.tex
htlatex test.tex
Of course you will need some extra code to 'pull' .tex files from subversion as needed but I hope you get the idea. Simply generate automatically latex files with required fragments of your manual and convert them to html.

Cheers,

Tomek
User avatar
tripwire45
Posts: 129
Joined: Thu Apr 10, 2008 4:35 am

Re: Combining or merging several TEX files into one document?

Post by tripwire45 »

Thanks, Tomek. The "powers-that-be" are still discussing how they want to do this and I can certainly present this as one solution. I've already looked at tex4ht and latex2html as you've suggested. Cheers. :)

-Trip
pankajgpatel
Posts: 1
Joined: Fri Feb 12, 2010 5:33 am

Re: Combining or merging several TEX files into one document?

Post by pankajgpatel »

Hello Friends:
I am new to using Latex. I need to make a book out of the 20 chapters (with tex files that are working fine individually).I have been given working compiled 20 chapters with tex files written in Latex that I need to combine in one file. I tried the way described earlier.I made a master.tex where I have preamble, begin, include{chapter1}, include{chapter2}......etc. and end statement. Each chapter compiles fine in Latex and produces perfect output when I compile individually (each chapter is having its own preamble, begin and end statements). But when I compile master.tex, it gives me lots of errors. What is the best way to invoke all these chapters without removing anything from individual chapters. I shall really appreciate your help.

Thanks a lot,
PAT
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Combining or merging several TEX files into one document?

Post by localghost »

Try the combine class.


Best regards and welcome to the board
Thorsten
scharbag
Posts: 1
Joined: Sun Mar 20, 2011 4:09 pm

Combining or merging several TEX files into one document?

Post by scharbag »

I know this is a late answer but...

The combine class is not required to do this. The errors that you are seeing are likely a result of too much preamble information, that is what I ran into. My setup has each chapter in a separate folder within the main folder.

What I did was use the following preamble in each sub document

Code: Select all

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Chapter 7
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\include{header}

\chapter{CONCLUSIONS}
... %text here

\include{footer}
The header.tex file consisted of:

Code: Select all

\documentclass[12pt]{RCH}
\usepackage{natbib,graphicx,setspace}
\newcommand{\chapsevenpath}{./}
  %this is used when referencing figures etc which are located in the local directory
\begin{document}
\setcounter{chapter}{6}
and the footer.tex file consists of:

Code: Select all

{
\renewcommand{\baselinestretch}{1}\normalsize
\renewcommand{\bibname}{References} 
\bibliographystyle{els}
\bibliography{../RCHBibliography.bib}
}

\end{document}
This way, when I typeset each chapter, they show the proper chapter number and their own bibliography. With the use of ../RCHBibliography.bib, I only have to maintain one BIB file in the root project folder.

Now the main file has the following IN THE TEX file:

Code: Select all

\documentclass[12pt]{RCH}
\usepackage{natbib,graphicx,setspace,multirow,lscape,hhline,longtable,array}

\newcommand{\chaponepath}{chapter1/}
\newcommand{\chaptwopath}{chapter2/}
\newcommand{\chapthreepath}{chapter3/}
\newcommand{\chapfourpath}{chapter4/}
\newcommand{\chapfivepath}{chapter5/}
\newcommand{\chapsixpath}{chapter6/}
\newcommand{\chapsevenpath}{chapter7/}

... % all the information here for the front matter 

begin{document}

% Typeset the title page
\maketitle

% Typeset the frontmatter.  
\frontmatter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CHAPTERS OF THESIS GO HERE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\input{chapter1/chapter1.tex}
\input{chapter2/chapter2.tex}
\input{chapter3/chapter3.tex}
\input{chapter4/chapter4.tex}
\input{chapter5/chapter5.tex}
\input{chapter6/chapter6.tex}
\input{chapter7/chapter7.tex}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% REFERENCE SECTION 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

{
\renewcommand{\baselinestretch}{1}\normalsize
\renewcommand{\bibname}{References} 
\bibliographystyle{els}
\bibliography{RCHBibliography}
\addcontentsline{toc}{chapter}{References}
}

\end{document}
In the main directory, you still need header.tex and footer.tex files but they are blank.

As you can see, I have redefined the locations of each chapter in the main document (which were in the header and footer) so when typesetting, Latex knows where to find the files in the directories. This way, you can work on individual chapters and typeset with the references and figures looking proper and when you want to see the whole thing, you can typeset the main file! A bit of work to set it up but once done, it works great.

Cheers,
Post Reply