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
.stypackage referenced trough\usepackagedirective is not found/recognized byTeXstudioeditor (altough it is correctly compiled byLaTeX).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
LaTeXdid 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.
.sty) via\usepackagethen@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\inputstatement by\makeatletterand\makeatother. If you don't do it, you will get lots of errors and unusable code. – gernot Aug 19 '16 at 07:57\includeshould not be abused for mere code loading – Aug 19 '16 at 07:59\usepackagedirective is not found/recognized by TeXstudio"? Secondly, in.styfiles loaded with\usepackagecommands with @ are automatically enabled, which doesn't happen with\input. Thirdly, you should never use\includefor loading macro definitions. – egreg Aug 19 '16 at 08:00\inputand\include, see When should I use \input vs. \include? – gernot Aug 19 '16 at 08:02memoirclass bybook. 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 tobook. – gernot Aug 19 '16 at 08:10\usepackagedirective itselft .. in short it recognize\usepackagebut it 's not finding the file... but this maybe it's just a problem ofTeXstudioinsteadLaTeXitself. – weirdgyn Aug 19 '16 at 09:04\newcommand\foo{ a }is not the same as\newcommand\foo{a}so if you do not want a space in the output do not add spaces or newlines at that position. (or if you do add linebreaks just to indent the source, you need to comment them out with%) – David Carlisle Aug 19 '16 at 09:13.styso 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 09:16\includev\usepacakgebut there are no cases where there is a possibility of choosing between those two,.\includedoes not work before\begin{document}and\usepackagegives an error if used after\begin{document}– David Carlisle Aug 19 '16 at 09:17\includeand\usepackageare reasonable commands to use at that point. The contexts where they may be used have no overlap. – David Carlisle Aug 19 '16 at 09:21\includeand\usepackagehave different scopes .. correct.. that's literature (that's good). TheLaTeXway prescribe different contexts where to apply such directives... my doubt can be resumed in this question: "What's the correct way to do what I need to do? I have to use\include? I have to use\usepackage.. I have to put everything in the same.texfile?" – weirdgyn Aug 19 '16 at 09:27