6

I hope that everyone is safe and all right with the health crisis we're facing.

My question today is maybe a elementary one but let's go :

Some months ago, one among us has said, in an answer to a question of mine, that my preamble was messy, that we couldn't know where you're going with this, what you try to do with it.

I would like first to thank him a lot for it and ask the question :

How to organize a preamble ? I've had a few classes about using LaTeX but nobody did care about presenting us a way to efficiently organize the preamble so we could read and re-read it later.

I'm actually facing problems myself in figuring where some things are just because I don't feel there 's any structure to it (but maybe it's a more general problem about me).

Here below, I show you my preamble (with screenshots, it's easier for me to not get the whole messy copy/paste I then did when that good user made the remarks about it).

%-----(A CORRIGER)-----%
% corriger la hauteur des "en-têtes" pour permettre l'insertion des en-têtes intermédiaires qui reprennent les titres de chapitres/section". (cf log triangle jaune) --> solution trouvée avec les titres courts => \chapter [titre court] {titre long}%

%--------------------------%
%-----(BEGIN PREAMBLE)-----%
%--------------------------%
\documentclass[a4paper,12pt ,twoside ,openright ,extrafontsizes]{memoir}
\raggedbottom
%[twoside] est utilisé pour indiquer que le document sera imprimé recto-verso.%
%[openright] est utilisé pour indiquer que tout nouveau chapitre doit commencer sur un recto.%
%[extrafontsizes] est utilisé pour permettre, si l'on veut, le recours à des tailles de polices d'écritures dépassant les 25pt.


%-----( BEGIN PACKAGEs)-----%
%---------------------------%
\usepackage[utf8]{inputenc} %obligatoire%
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{xcolor}%pour surligner du texte (la commande en cours de frappe est  : \colorbox{couleur}{texte  à surligner}%
\usepackage{soulutf8} %la commande pour surligner est : \texthl{texte à surligner}
\usepackage{ulem}


%-----(BEGIN MACRO)-----%
%-----------------------%

 %enclenche le style de chapitre utilisé (pour d'autres exemples compatibles, voir "the memoir class (2018) p.385 et sq.)
\newcommand*{\sclabel}[1]{\normalfont\scshape #1} %à voir si je conserve, permet de personnaliser les étiquettes des items des listes...

\OnehalfSpacing %interligne 1,5

%-----CHAPTER STYLE "ELL" (BEGIN)-----%
\makeatletter %ne pas oublier cette balise lorsque l'on copie/colle un bout de code tel quel%
\makechapterstyle{ell}{%
  \chapterstyle{default}
  \renewcommand*{\chapnumfont}{\normalfont\HUGE\sffamily}
  \renewcommand*{\chaptitlefont}{\normalfont\huge\sffamily}
  \settowidth{\chapindent}{\chapnumfont 111}
  % \renewcommand*{\chapterheadstart}{\begingroup
  %   \vspace*{\beforechapskip}%
  %   \begin{adjustwidth}{}{-\chapindent}%
  %   \hrulefill
  %   \smash{\rule{0.4pt}{15mm}}
  %   \end{adjustwidth}\endgroup}
  \renewcommand*{\printchaptername}{}
  \renewcommand*{\chapternamenum}{}
  \renewcommand*{\printchapternum}{%
    % \begin{adjustwidth}{}{-\chapindent}
    % \hfill
    % \raisebox{10mm}[0pt][0pt]{\chapnumfont \thechapter}%
    %                           \hspace*{1em}
    % \end{adjustwidth}\vspace*{-3.0\onelineskip}
    \chs@ell@helper{\thechapter}%
  }
  \renewcommand\printchapternonum{%
    \chs@ell@helper{}\afterchapternum}
  \renewcommand*{\printchaptertitle}[1]{%
    %\vskip\onelineskip
    \raggedleft {\chaptitlefont ##1}\par\nobreak}}
\makeatother % et ne pas oublier celle-ci pour clore le cadre créé par \makeatletter en début de copier/coller.

%-----CHAPTER STYLE "ELL" (END)-------%
\chapterstyle{ell}%à placer après la section ci-dessus qui reparamètre certains aspects du "chapterstyle ELL". Si on place la commande avant, elle chargera la configuration d'origine au lieu de prendre encompte les modifications ci-dessus.


 \setsecnumdepth{section}%indique à partir de quel niveau de titre on numérote
 \maxsecnumdepth{subsubsection}%indique jusqu'à quel niveau de titre on numérote

\setlength{\headheight}{15.5pt}

%-----(END MACRO)-----%
%---------------------%


%--------------------------%
%------(END PREAMBLE)------%
%--------------------------%

I only ask for advice on how to do the things.

I use the memoir class as you can see and I've maybe wrongly named my sections. Because I realize now that the entire " 'ELL' chapter style code" I copied/pasted from the memoirclass source file is not a "macro" in any way.

Anyway, I would like to thank that person and all of you who will come by, read me and maybe provide me some advice,

Thanks again and stay safe !

Elrad

  • 3
    Real quick: Did you see the posting Best practice on organising your preamble? – Mico Apr 02 '20 at 09:47
  • 3
    Never post images of code, what are we suppose to do with them. I always advide to make the comments above the macros, package what ever, not after as it becomes hard to read on small sceens (fx editors with source and preview next to each other. – daleif Apr 02 '20 at 09:48
  • After going through your previous questions I stumbled upon this one to which I suppose you refer to in this question. If I am not mistaken, daleif here expresses that the representation of the code in the question is quite messy, not necessarily that the code itself is messy. – leandriis Apr 02 '20 at 10:24
  • 2
    For most of the questions that one might ask on this site, a complete minimal working example (MWE) is extremely helpful. This is a complete small example doument that others just need to copy-paste and compile to reproduce the output/error message/issue that is described in the question. If one just posts code fragments as opposed to a complete small example document, others might add different cod to make it compilable resulting in an entirely different outputs, resulting in a lot of queries. – leandriis Apr 02 '20 at 10:24
  • 3
    Regarding the visual representation of code specifically on this site: Instead of adding a screenshot of the code, please alsways copy-paste the code itself. To get it neatly formatted, select the code and press the button with {} on it in the editor or ctrl + k on your keyboard. For more information on that see How do I mark code blocks?. – leandriis Apr 02 '20 at 10:25
  • 5
    Regarding the actual code itself: To make sure a preamble is not "messy", first of all make sure, you only load packages once. Make sure, you know why you load a package (does it provide a useful command,...) and load only packages that you actually need for this specific document. Group packages, for example everything related to math or tables,... Add comments to why you load a package/what it does. Keep in mind the correct load order of packages such as hyperref, cleveref and some others. Probably add a comment on that as well. – leandriis Apr 02 '20 at 10:25
  • Hello everyone, I did edit the post to correctly present the code itself.

    I thank everyone for your answers :

    @Mico : no I didn't I'll do it.

    – Elradsoldier Apr 02 '20 at 11:13
  • @leandriis Thanks for your comments and advice – Elradsoldier Apr 02 '20 at 11:33
  • @daleif : I edited the post – Elradsoldier Apr 02 '20 at 11:33

1 Answers1

1

I hate the big and mostly messy code bevor the \begin{document}, too. I started every new project with copying all this code and pasting it and i think this isn't ellegant. My solution:

Make a .sty file, where you put the preamble. Then you just have to import that .sty to your Code. When you start a new project you just have to copy and paste that .sty.

I made a folder with different .sty, each .sty has a different style. All i do now is import the right .sty from that folder ( The best part is, i made a interface, which is the same in every .sty. So i can compile the same documen with different style just by importing a different .sty. That's pretty funny when you're writting a thesis and want to see how i looks in DnD style )

That no exactly a way to clean up a messy code, but i hope i gave you an idea of how to make it look better for you, and work better with already cleaned up preambles. c:

Titanlord
  • 541