1

I have a question. I try to include from one .tex file to another My first file

\documentclass{beamer}


\mode<presentation>
{
    \usetheme{Warsaw}
    \setbeamercovered{dynamic}
    \usefonttheme[onlymath]{serif}
}

\include{presentation1}

My second file

\mode<presentation>
{
  \usetheme{Warsaw}
  \setbeamercovered{dynamic}
  \usefonttheme[onlymath]{serif}
}
\usepackage{pgf,pgfarrows,pgfnodes,pgfautomata,pgfheaps,pgfshade}
\usepackage[UTF8]{inputenc}
\usepackage[polish]{babel}
\usepackage[OT4]{fontenc}
\usepackage{graphicx}
\usepackage{beamerthemesplit}
\usecolortheme{default}
\usepackage{url}
\usepackage{color}
\usepackage{multimedia}



\begin{document}


\end{document}

When I put \documentclass{beamer} in my second file

\documentclass{beamer}

\mode<presentation>
{
  \usetheme{Warsaw}
  \setbeamercovered{dynamic}
  \usefonttheme[onlymath]{serif}
}
\usepackage{pgf,pgfarrows,pgfnodes,pgfautomata,pgfheaps,pgfshade}
\usepackage[cp1250]{inputenc}
\usepackage[polish]{babel}
\usepackage[OT4]{fontenc}
\usepackage{graphicx}
\usepackage{beamerthemesplit}
\usecolortheme{default}
\usepackage{url}
\usepackage{color}
\usepackage{multimedia}



\begin{document}


\end{document}

I have an errors one I run my first file (file with include) like ! LaTeX Error: Two \documentclass or \documentstyle commands. Package pgfarrows Warning: This package is obsolete. pgf.sty will load arrow ma etc

So when I use include I must always delete preamble from a source file or do something else?

4
  • 1
    You only have to ensure the commands used in the included file are all defined by the preamble of the main file.
    – Bernard
    Apr 6, 2021 at 18:26
  • 2
    The class should be loaded only once.
    – Sigur
    Apr 6, 2021 at 18:27
  • 4
    \include acts as if contents of the entire included file appear at the include point. If you want to include a file that has its own preamble, take a look at the subfiles package.
    – Teepeemm
    Apr 6, 2021 at 18:28
  • 4
    also are you sure you want \usepackage[cp1250]{inputenc} almost all editors will default to UTF-8 now. anyone copying your example from this site would need to change that as all text on this site is UTF-8. Apr 6, 2021 at 18:31

1 Answer 1

2

It is not necessary to delete the preamble in the included file, instead you can use the subfiles package to ignore the preamble.

This way you can include files which themselves have \documentclass{} etc, but you will need to also load all packages and other settings in your main file. They won't be inherited from the included file.

\documentclass{beamer}

\usepackage{subfiles}

\begin{document}
    
\subfile{document}
    
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .