0

I have a thesis class that has the following tex file as a main file and it is called: thesis.tex

    %------------------------ Preamble and bibliography resources
    \documentclass[12pt,oneside]{book}[usenames,dvipsnames,svgnames,table]
\usepackage{style/title}[PhD]
\input{frontmatter/preamble} 

\makenomenclature \usepackage{multicol} \usepackage{graphicx} \usepackage{dirtytalk} \usepackage{titlesec} \usepackage{xpatch} % for \xpatchcmd \usepackage{lipsum} % for \lipsum to produce dummy texts \usepackage{bibentry}

% Add your bibtex file here \addbibresource{references.bib}

%------------------------ Main Document -------------------------- \begin{document} \newcommand{\coo}{\ensuremath{\mathrm{CO_2}}} \newcommand{\chh}{\ensuremath{\mathrm{CH_4}}} \newcommand{\wv}{\ensuremath{\mathrm{H_2O}}} \newcommand{\radiance}{\ensuremath$\mathrm{Wm^{-2} sr^{-1}\mathrm{\mu m^{-1}}}$} \newcommand{\oo}{\ensuremath{\mathrm{O_2}}} \newcommand{\nn}{\ensuremath{\mathrm{N_2}}} \newcommand{\oz}{\ensuremath{\mathrm{O_3}}}

%-------------- Information For The Title Page
\title{thesis title}
\author{name}


%-------------- Front Matter
\frontmatter
\maketitle

\include{frontmatter/abstract}
\include{frontmatter/acknowledgments}
 \include{frontmatter/declaration}
\include{frontmatter/publications}

%-------------- Table of contents
\cleardoublepage
\phantomsection \pdfbookmark[0]{Contents}{Contents} 
\tableofcontents
\addcontentsline{toc}{chapter}{\listfigurename}
\listoffigures
\addcontentsline{toc}{chapter}{\listtablename}
\listoftables


%-------------- Chapters \cleardoublepage \mainmatter \titleformat{\chapter}[display]{\sffamily\huge\bfseries}{\filleft\chaptername \ \thechapter}{4ex}{}[{\titlerule[1.5pt]}]

\include{Chapters/chapter1} \include{Chapters/chapter2} \include{Chapters/chapter3} \include{Chapters/chapter4} \include{Chapters/chapter5}

%-------------- Bibliography

\cleardoublepage \phantomsection \addcontentsline{toc}{chapter}{References}

\printbibliography

%-------------- Appendices
\cleardoublepage
\appendix
\include{appendices/Papers}
\include{appendices/Optica-template}
\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{Appendices}


\end{document}

This produces a pdf file of the thesis file that ends with the appendices.

I have a research paper that has a different class and style. The main tex file for the journal paper is called: Optica-template.tex and looks like this:

\documentclass{optica-article}

\journal{opticajournal} % for journals or Optica Open

\articletype{Research Article}

\usepackage{lineno}

%%%%%%%%%%%%%%%%%Added packages %%%%%%%%%%%%%%%%% \usepackage{float} \usepackage{tikz}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\linenumbers % Turn off line numbering for Optica Open preprint submissions.

\begin{document}

body

\bibliography{references1} \end{document}

Now, my question is: How can i compile the these two classes to have a one pdf file where the paper is places at the end of the thesis in the appendices?

It throws errors like this one:

LaTeX Error: Can be used only in preamble.
You have used a command in the main body of your document which should be used in the preamble. Make sure that \documentclass[…]{…} and all \usepackage{…} commands are written before \begin{document}.
Learn more

See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ...

l.1 \documentclass {optica-article} Your command was ignored. Type I <command> <return> to replace it with another command, or <return> to continue without it.

! Undefined control sequence. l.3 \journal {opticajournal} % for journals or Optica Open The control sequence at the end of the top line of your error message was never \def'ed. If you have misspelled it (e.g., \hobx'), typeI' and the correct spelling (e.g., `I\hbox'). Otherwise just continue, and I'll forget about whatever was undefined.

and does not recognize the references (i named the references tex files differently for the thesis and the paper).

I would appreciate your guidance.

  • 4
    Nesting different classes is always a bad idea. You can use pdfpages package or even several \includegraphics to include the pdf of the article "as is", or just use a tool as pdftk to join two pdf,. If you need active cross-references, and change the style of the article does not matter, alternatively you can include only the contents of the article before \end{document}, and then add to the preamble of the thesis just the minimal parts of the article preamble to avoid undefined command errors, taking care of load each package only once. – Fran Oct 26 '23 at 06:19
  • Thank you, @Fran , for the reply and suggestion. It worked exactly like i needed. It was the \usepackage{pdfpages} with command \includepdf[pages=-]{appendices/file.pdf} which included all the pages in my pdf file.

    How can I accept your comment as an answer to this question?

    – Naif Alsalem Oct 26 '23 at 11:04
  • 1
    You are welcome. The comments can be upvoted (not sure if you need some reputation for this) but not as answers or accepted. I will not make an answer, but vote to close this question because essentially is a duplicate of older questions with answers making what you have found as a good solution. – Fran Oct 26 '23 at 13:28

0 Answers0