3

I have the following main tex file and I wish to place the \usepackage commands in a different usepackage.tex file and compile it on main tex file. How can I do that. I tried but keep getting error as if it does not know where to find the file usepackages. (Pardon me for the messy packages, I know it is a disaster, I am trying to fix it now.)

\documentclass[12pt,a4paper,twoside]{report}
\setlength{\textwidth}{16cm}
\setlength{\oddsidemargin}{0pt}
\setlength{\evensidemargin}{0pt}
\setlength{\parskip}{3mm}
\setlength{\parindent}{0mm}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\graphicspath{{images/}}
\usepackage{setspace}
%\usepackage{biblatex}
%\usepackage{url}
\usepackage{epsfig}
\usepackage{filecontents}
\usepackage{xparse,nameref}
%\usepackage{hyperref}
\usepackage{mathrsfs}
\usepackage[nokeyprefix]{refstyle}
\usepackage{mathtools}
\usepackage{thmtools}
\usepackage{enumerate}% http://ctan.org/pkg/enumerate
\usepackage{enumitem}
\usepackage{thm-restate}
\usepackage{cleveref}
\usepackage{amsmath}
\usepackage{url}
\usepackage{amsthm}
\DeclareMathOperator{\lcm}{lcm}
\DeclareMathOperator{\ord}{ord}
\usepackage{cellspace}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}
\usepackage{booktabs}
\setlength\defaultaddspace{2ex}
\usepackage{graphicx}
\usepackage{array}
\usepackage{tabularx,ragged2e,booktabs,caption}
\usepackage[figuresleft]{rotating}
\usepackage{rotating}
\newcolumntype{C}{>{\Centering\arraybackslash}X}
\newcommand\swb{{\scriptstyle\Box}} % "small white box"
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}
\setcounter{secnumdepth}{3}
\usetikzlibrary{shapes.multipart}
\usepackage{tabu}
\usepackage{amssymb,bm}
\usepackage{framed}
\usepackage{upgreek} %use uptau greek letter
\usepackage{comment} %choose parts not to compile
\usepackage{tikz}
\tikzset{mynode/.style={fill=white,text=black,font=\tiny,inner sep=1pt}}
\usepackage[toc,page]{appendix}
\addtolength{\topmargin}{-.875in}
\newenvironment{numberlists}[1][3\parindent] %for long numberlist command
 {\begin{list}{}{%
   \leftmargin=#1\relax
   \rightmargin=\leftmargin
   \itemsep=\jot
   \parsep=0pt
   \partopsep=0pt
   \labelsep=0pt}}
 {\end{list}}
\newcommand\numlist[2]{%
  \item[]\makebox[0pt][r]{$#1=\lbrack$}%
  \begingroup
  \begingroup\lccode`~=`,\lowercase{\endgroup\def~}{\mathcomma\penalty0 }%
  \mathcode`,="8000
  \thinmuskip=6mu plus 6mu minus 2mu
  $#2\rbrack$%
  \endgroup
}
\mathchardef\mathcomma=\mathcode`, %end of numberlist command
\setlength{\oddsidemargin}{-1in}   \setlength{\evensidemargin}{-1in}
\addtolength{\oddsidemargin}{25mm}\addtolength{\evensidemargin}{20mm}
\setlength{\marginparwidth}{40pt} \setlength{\marginparsep}{10pt}
\setlength{\topmargin}{-5mm}      \setlength{\headsep}{0.5in}
\setlength{\textheight}{227mm}    \setlength{\textwidth}{165mm}
\renewcommand\floatpagefraction{0.8} %   Default = 0.5
\usepackage{listings}
\usepackage{color}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\lstset{
  language=Java,
  aboveskip=3mm,
  belowskip=3mm,
  showstringspaces=false,
  columns=flexible,
  basicstyle={\small\ttfamily},
  numbers=none,
  numberstyle=\tiny\color{gray},
  keywordstyle=\color{blue},
  commentstyle=\color{dkgreen},
  stringstyle=\color{mauve},
  breaklines=true,
  breakatwhitespace=true,
  tabsize=3
}

\allowdisplaybreaks % allow page breaks
\begin{document}
\begin{titlepage}
\begin{center}
\includegraphics[width=0.70\textwidth]{logo} \\[2cm]

{ \large \bfseries Perfect Triangles : Rational points on Elliptic Curves }\\
Shahrina Ismail \\
\{Candidate's academic degrees\} \\[7cm]
{\em A thesis submitted for the degree of Doctor of Philosophy at\\
The University of Queensland in 2016} \\
School of Mathematics and Physics

\end{center}
\end{titlepage}

\pagenumbering{roman}

\theoremstyle{definition}

\begin{abstract}
here...
\end{abstract}

\tableofcontents

\listoffigures

\listoftables

\newpage
\pagenumbering{arabic}
\onehalfspacing
\chapter{Introduction}
\input{chapters/Introduction}

\onehalfspacing
\chapter{Background and Methodology}\label{chap:2}
\input{chapters/chapter2}


\onehalfspacing
\chapter{Values of $\delta(\mu)$}\label{chap:3}
\input{chapters/chapter3}

\end{document}
  • @Mico. Sorry I will edit this. I actually has already deleted that instruction. – shahrina ismail Nov 19 '16 at 10:17
  • 1
    Move all the code lines that you want in a preamble.tex file and than put \input{preamble.tex} in your main file. – CarLaTeX Nov 19 '16 at 10:19
  • @CarLaTeX. Thank you it worked. the mistake i did before this was that I placed the premable.tex in the chapters folder, but wrote \input{preamble.tex} – shahrina ismail Nov 19 '16 at 10:27
  • 1
    You're welcome! Indeed \input{somefile.tex} can be put everywhere, but if somefile.tex contains \usepackage{...} must be put before \begin{document}. – CarLaTeX Nov 19 '16 at 10:32
  • apart from placing it in a file, don't load epsfig, don't load both enumerate and enumitem , your \floatpagefraction setting looks a very strict default, makes it very hard for latex to avoid sending all floats to the end of the document. (if you have two consecutive floats both 75% of page height then it will be impossible to set any floats and they will all stack up until flushed by \clearpage) It's a bad habit to use numbers in labels like \label{chap:3} (even though it works), not need to load amsmath if you have mathtools (which you have twice) also have booktabs twice – David Carlisle Nov 19 '16 at 12:19
4

I suggest you

  • Place all preamble instructions -- other than the \documentclass instruction, of course -- in a separate file, to be called (say) sharina.sty. (Note the filename extension). Save the file in the directory where your main tex file is located.

  • Place the single instruction

    \usepackage{sharina}
    

    in the preamble of your tex file. Observe: No filename extension.

    With this change, the document preamble should consist of only the following two lines:

    \documentclass[12pt,a4paper,twoside]{report}
    \usepackage{sharina}
    

Then, do please take the time to clean up and simplify the instructions contained in the file sharina.sty.

  • Thank you so much Mico. This worked so well. And sharina.sty really really need some grooming.. Thanks again. – shahrina ismail Nov 19 '16 at 10:29
  • 3
    Or even a class can be made sharina-thesis.cls. Then the document just starts with \documentclass{sharina-thesis}\begin{document}. Both the package solution and the class solution have the advantage, that options can implemented for the case, the document needs processing with different settings. – Heiko Oberdiek Nov 19 '16 at 10:34

Your Answer

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

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