Merge multiple chapters into one thesis document - latex

I am fairly new to Latex.
I have written my thesis in Latex. I have 6 chapters and have made individual stand-alone files for each chapter. The main \thesis folder has a total pf 8 folders containing chapters 1 to 6, bibliography and acknowledgments, (\thesis\ChapterOne.. so on) for each chapter with all the necessary figures, tables, etc.
I tried to put the thesis together using main.tex
\documentclass[12pt,a4paper,oneside]{report}
\begin{document}
\input{\...\thesis\acknowledgements\cacknowledgements.tex}
\input{\...\thesis\ChapterOne\ChapterOne.tex}
\input{\...\thesis\ChapteroTwo\ChapteroTwo.tex}
.
.
\end{document}
I am not able to compile the file and get this error
Can be used only in preamble. \usepackage
How do I get around this?
I also need help with adding the table of contents and list of figures and tables.
Any help is greatly appreciated.

I managed to do something similar with the subfiles package and a conditional like the one used here:
http://xpt.sourceforge.net/techdocs/language/latex/latex23-Conditioning/ar01s02.html.

Related

How to remove page number locations being added to bibliography entries

I am writing my thesis in Overleaf, using the IEEE reference style and the BibTeX package for the bibliography. The bibliography entries generated have additional text at the end, it would appear it is including which page(s) the particular citation comes from. Any help removing them would be greatly appreciated, and I have included an image of my PDF to show what this looks like. Thank you.
EDIT: The problem has been solved. My includes.tex files uses two packages, backref and pagebackref, which were responsible for adding the "pages" and their numbers for each citation entry. Include these if you want these pages labels, remove them if you do not. Thank you all for your help.
The easiest method is to just edit the .bib file, and remove all lines with "pages = ... ". If the bib file doesn't specify them, then bibtex won't create entries for it.
E.g., in
#article{dubey2014survey,
title={A survey of high level frameworks in block-structured adaptive mesh refinement packages},
author={Dubey, Anshu and Almgren, Ann and Bell, John and Berzins, Martin and Brandt, Steve and Bryan, Greg and Colella, Phillip and Graves, Daniel and Lijewski, Michael and L{\"o}ffler, Frank and others},
journal={Journal of Parallel and Distributed Computing},
volume={74},
number={12},
pages={3217--3227},
year={2014},
publisher={Elsevier}
}
just remove the 'pages' line.
If you want to do it programmatically you'd have to edit the .bst file (IEEEtran.bst if i remember correctly), but that's not for the faint of heart, so I'd recommend the easier method.

Rmarkdown with LaTex-document in appendix?

I need to create an Rmarkdown document in which I have some text and 3 appendices showing 3 different LaTex files. I found many resources showing how to append Rcode in an appenidx, but have been unsuccessful for other kinds of appendices. As a structure, I use a thesisdown-template. The template has several chapters that are all compiled together in the end. There is also an appendix-template but I haven't figured out how to include a LaTex file in there. But given that I can have LaTex code in a Markdown file, it should be possible?
I do not need to use thesis-down, it could also be similar to the following:
Any ideas are welcome!
If I understand correctly, then you are only interested in PDF output. You can embed raw LaTeX commands in R Markdown, so the following should do what you need:
\appendix
## Appendix 1
\input{/path/to/my/LaTeXfile.tex}
## Appendix 2
\input{/path/to/my/other/LaTeXfile.tex}

Conditional Import in LaTeX?

I'm going to be taking a ton of lecture notes, and then compiling them into LaTeX so that I can have excellent documents for future me to look over. I'm trying to organize things so that I can have a bunch of little documents containing the notes from a lecture, and then compile them at the end of the semester into one large document containing all of them. I have used import/include etc. successfully in the past, but I've had to remove the content at the head and foot of the sub-documents before compiling the main document. For example, I would have to remove:
\begin{document}
and
\end{document}
from every sub-document before compiling the main document. This is fine for a report with 5 or so sections, but a pain in the ass for something with 100+. Any recommendations for ignoring the contents of a LaTeX file programmatically when using the import command?
I see two approaches here. Either carefully structure your documents, or use some hacky TeX magic:
The smart way
Break your smaller documents into a header part, a footer part and a content part.
header.tex:
\documentclass{article}
...
\begin{document}
footer.tex:
\end{document}
foo-content.tex:
In this paper, we discuss an new approach to metasyntactic variables...
foo.tex (the small paper version):
\include{header}
\include{foo-content}
\include{footer}
In your .tex for the collected articles document:
\include{foo-content}
The hacky TeX way
Put this in some common include file, used by your individual files:
\ifx\ismaindoc\undefined
\newcommand{\inbpdocument}{\begin{document}}
\newcommand{\outbpdocument}{\end{document}}
\else
\newcommand{\inbpdocument}{}
\newcommand{\outbpdocument}{}
\fi
Use \inbpdocument and \outbpdocument in your individual files, in place of \begin{document} and \end{document}. In your main file, put in a \def \ismaindoc {} before including or importing anything.
Here's another possible approach: if you put magic strings (i.e., "% % BEGIN LECTURE % %" ... "% % END LECTURE % %") in the individual files, you could awk out the guts of the individual files, assemble them using make/sh, and then \include them.
There's another hack you could use, which wouldn't require modifying the individual files... just temporarily redefine the {document} environment (to something benign, i.e. a no-op), \include the individual files, and then restore the {document} environment definition.
If I recall correctly, the commands to do this are \let and \renewenvironment.
Hm. You might also have to temporarily redefine \documentclass and \usepackage, too. It's a hack, yes, but I think it should work.
I haven't used it, but it looks like the "subfiles" package does exactly what you want:
http://en.wikibooks.org/wiki/LaTeX/Modular_Documents#Subfiles_package

Latex, TikZ and separate compilation of chapters and figures

I have fairly large Latex document with a lot of TikZ figures inside. I have a habit of frequent recompilation and it takes forever to compile it using pdflatex. Figures in TikZ take most of the time.
My question is what is the best way to split the document into separate tex files (figures/chapters) to achieve separate compilation of figures and chapters, separate chapter pdfs, and a whole document pdf file ?
Have you tried compiling each picture on its own and then including them in your tex file as pdf rather than the tikz code? You can use the package standalone so that the picture will be the exact size you need. So :
\documentclass{standalone}
\usepackage{tikz,pgf} %and any other packages or tikzlibraries your picture needs
\begin{document}
\begin{tikzpicture}
%your tikz code here
\end{tikzpicture}
\end{document}
The good thing about this is that you can either include the compile this document directly to get a pdf figure to include in your document, or you can use the command \input to include it in your main document as a tikz code by adding
\usepackage{standalone}
in your main document (together with the tikz packages and libraries), and then
\begin{figure}
\input{tikzfile.tex}
\end{figure}
There is a possibly better way (imho) to cache tikz-pictures. Add the following lines in your
preamble:
\usetikzlibrary{external}
\tikzexternalize[prefix=i/]
After a pdflatex-run you'll see all pictures in the subdirectory ./i .
If you update the code of a tikz-picture simply throw away its corresponding pdf-file and it will be regenerated. For more info see the manual of PFG/TikZ section 32.4 Externalizing Graphics
and possibly 32.5 Using External Graphics Without pgf Installed.
How about putting each chapter in a separate file and then using \include to put them into some master file? Then you can use \includeonly to only compile the chapter you're currently working on. That should save some time at least.
I expect some sort of makefile based solution would be even better than this, but I don't know anything about makefiles...
The way I generally do this is to apply Latex to just part of the file: Emacs and several other Latex editors allow you to compiler regions: with Auctex, you can run TeX-pin-region to specify the current chapter, and then TeX-command-region to run Latex on the selected region.
The traditional way to do this is cut parts of the big file into smaller parts that are \included, and then either comment out parts you don't want to work on, or put some macrology at the beginning and end of each file that allows them to be compiled separately.

Parts in pdflatex Table of Contents

I have a thesis in which I want to group some chapters together, using the \part command.
What I would like is to have the following:
Chapter 1
Part I
Chapter 2
Chapter 3
Part II
Chapter 4
Chapter 5
Chapter 6
So the last chapter should again be on the same level as the parts. In the table of contents of the text you can't really detect it, because Parts are on the same level anyway.
The problem is that in the PDF, the chapter 6 is added under Part II.
Does anyone know of a way to change that?
The bookmark package can do this quite nicely, among other things. It also only uses a single pass to embed PDF bookmarks into the document.
\part{...}
\chapter{...}
\bookmarksetup{startatroot}
\chapter{...}
The fact that LaTeX does it wrong probably means that something is wrong with the structure of your document: \part is not meant to group chapters, but to devide the document in parts. The difference is that every chapter should be in a part.
Try 'introduction' or 'preliminaries' as a name for the part containing chapter 1.
It might be possible to work around, but you'd have to redefine command throughout the document. It might be worthwhile to use \chapter* for chapters not in a pat, step the chapter-counter manually, and manually call \addcontentsline with the right argument. However, this is IMHO bad use of LaTeX: for well-structured documents, the standard LaTeX commands should suffice.

Resources