# \include vs \usepackage [duplicate]

I have some doubt about the correct approach to document modularity. Main main doubt is about the usage of custom packages in the creation of a complex structure document. In my first LaTeX work I made a custom package (.sty) with structure / commands definitions and other global settings. This allowed me to fix several compilation issues I had placing everything in a single file but I soon noticed some negative drawbacks about such approach:

• the custom .sty package referenced trough \usepackage directive is not found/recognized by TeXstudio editor (altough it is correctly compiled by LaTeX).

• compilation errors in custom package are 'mitigated' and anyway is often difficult to find the correct reference to the error.

• the templates / sample files I read learning LaTeX did not use such approach but often use \inlcude \input directives.

This's my document structure:

\documentclass[dvipsnames,a5paper,twoside,openright,italian,12pt]{memoir}

\usepackage{defines}

\author{The Author}
\date{2016}
\title{The Title}
\editor{The Editor}

\begin{document}

\frontmatter

\mytitle

\tableofcontents

\include{Preface}

\mainmatter

\include{Chapter01}

\include{Chapter02}

\end{document}


and this is my custom package (the name is defines.sty):

\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage[T1]{fontenc}
\usepackage{verse}
\usepackage{background}
\usepackage[object=vectorian]{pgfornament}
\usepackage{svg}
\usepackage{wallpaper}
\usepackage[osf]{libertine}

\usetikzlibrary{backgrounds, calc}

\newcommand{\editor}[1]{
\def\@editor{#1}
}

\newcommand{\theeditor}{
\@editor
}

\newcommand{\eachpageornament}{
\begin{tikzpicture}[remember picture, overlay, color=LimeGreen]
\transparent{0.75}{
\node[anchor=north west](CNW) at (current page.north west){
\pgfornament[width=2cm]{61}};
\node[anchor=north east](CNE) at (current page.north east){
\pgfornament[width=2cm,symmetry=v]{61}};
\node[anchor=south west](CSW) at (current page.south west){
\pgfornament[width=2cm,symmetry=h]{61}};
\node[anchor=south east](CSE) at (current page.south east){
\pgfornament[width=2cm,symmetry=c]{61}};
\pgfornamenthline{CNW}{CNE}{north}{87}
\pgfornamenthline{CSW}{CSE}{south}{87}
\pgfornamentvline{CNW}{CSW}{west}{87}
\pgfornamentvline{CNE}{CSE}{east}{87}
}
\end{tikzpicture}
}

\newcommand{\plogo}{
\includegraphics[width = 30mm]{logo.png}
}

\newcommand{\psignature}{
\begin{flushright}
\def\svgwidth{40mm}
\input{signature.pdf_tex}
\end{flushright}
}

\newcommand{\mytitle}{
\thispagestyle{empty}
\ThisCenterWallPaper{1.1}{sfondo}

\begin{tikzpicture}[remember picture, overlay]
{\transparent{0.95}\node [rectangle, rounded corners, fill=LimeGreen, anchor=south west, minimum width=6cm, minimum height=8cm] (box) at (-0.5,-10) (box){};}
\node[anchor=west, xshift=-2.0cm, yshift=-1cm, text width=4cm] at (box.north){\large \textit{\theeditor}};
\node[anchor=west, xshift=-2.0cm, yshift=-3.5cm, text width=4cm] at (box.north){\huge \thetitle};
\node[anchor=west, xshift=-2.0cm, yshift=-6cm, text width=4cm] at (box.north){\large \theauthor};
\end{tikzpicture}

\newpage
}

\backgroundsetup{
contents={
\if@mainmatter
\eachpageornament \thepage
\else
\ifnum\value {page}=1
\else
\eachpageornament \thepage
\fi
\fi
},
position=current page.north east,
angle=0,
scale=1,
opacity=1
}

\renewcommand{\poemtoc}{section}
\renewcommand{\poemtitlefont}{\normalfont\large\itshape\centering}

\pagestyle{plain}

\setcounter{tocdepth}{2}


If I rename the package in .tex and include it (trough \include or \input) I got several errors.

I have another doubt about the use of memoir class instead book ... If I use the second instead the first one I got a number of errors regarding references to commands defined in the custom package.

• If you load TeX code (extension .sty) via \usepackage then @ will be treated as ordinary letter and can appear in macro names, which is used to defined internal macros that shouldn't be used by the user. If you load the same code (extension .tex) using \input, you will have to surround the \input statement by \makeatletter and \makeatother. If you don't do it, you will get lots of errors and unusable code. – gernot Aug 19 '16 at 7:57
• Regarding the difference between \input and \include, see When should I use \input vs. \include? – gernot Aug 19 '16 at 8:02
• Of course you get errors when replacing the memoir class by book. Both define document classes for large documents, but the first one is an extension of the second one with many more options; see the memoir documentation for details. You cannot expect that the extensions still work when going back to book. – gernot Aug 19 '16 at 8:10
• @weirdgyn I'd use .sty so as not having to bother with \makeatletter. But there's not really a big difference, except that \usepackage{defines} will not load again the file, even if issued more than once. – egreg Aug 19 '16 at 9:16