0

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.

Johannes_B
  • 24,235
  • 10
  • 93
  • 248
weirdgyn
  • 163
  • 1
    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 07:57
  • \include should not be abused for mere code loading –  Aug 19 '16 at 07:59
  • What do you mean by the ”\usepackage directive is not found/recognized by TeXstudio"? Secondly, in .sty files loaded with \usepackage commands with @ are automatically enabled, which doesn't happen with \input. Thirdly, you should never use \include for loading macro definitions. – egreg Aug 19 '16 at 08:00
  • 4
    Regarding the difference between \input and \include, see When should I use \input vs. \include? – gernot Aug 19 '16 at 08:02
  • 1
    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 08:10
  • Maybe your problems have mainly to do with TeXstudio. TeX usually has no problems finding files, and in the log output it is also quite clear to which files the line numbers refer since the opening and closing of processed files is indicated. My feeling is that integrated TeX environments that hide what's going on underneath are for standard users. If you plan to handle complex documents distributed over many files, it is maybe better to switch to a LaTeX-sensitive editor and to work from the command line for complex things. – gernot Aug 19 '16 at 08:20
  • @egreg nope ... as I wrote the error is related to the referenced file not the \usepackage directive itselft .. in short it recognize \usepackage but it 's not finding the file... but this maybe it's just a problem of TeXstudio instead LaTeX itself. – weirdgyn Aug 19 '16 at 09:04
  • 1
    @weirdgyn see the form in the comment where line breaks appear as spaces, that is also what tex does. \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
  • 1
    @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 09:16
  • 1
    but your question is still not very clear, the title is \include v \usepacakge but there are no cases where there is a possibility of choosing between those two,. \include does not work before \begin{document} and \usepackage gives an error if used after \begin{document} – David Carlisle Aug 19 '16 at 09:17
  • "literature"? I mean that in any latex document that there are no contexts where both \include and \usepackage are 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
  • @DavidCarlisle ok I got the point.. you meant that \include and \usepackage have different scopes .. correct.. that's literature (that's good). The LaTeX way 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 .tex file?" – weirdgyn Aug 19 '16 at 09:27
  • sorry I think unless you can clarify your question to actually have a question I think that closing as unclear is the only option (or as a duplicate of http://tex.stackexchange.com/q/246/110998) it is not really answerable in its current form – David Carlisle Aug 19 '16 at 09:54
  • Comments are not for extended discussion; this conversation has been moved to chat. – Stefan Kottwitz Aug 19 '16 at 11:01

0 Answers0