3

I must say I've been using LaTeX for only a couple of months, so you could say I'm still a beginner.

I have a large project that has many modifications applied to it. Every single time I wanted to change something about my document's look and feel, I searched it up on the internet and copy-pasted it in my document. So, you can say it has gone pretty large, and I'm curious if it's a bad thing, and if there is any room for optimization (ex: I did something using a package, but I could've done it using another package I already had included). Basically, I'd like to see what someone with more LaTeX experience than me has to say about what I've thrown together, and any suggestions, improvements, way to organize better etc.

Here's the modifications I've done:

\documentclass[
 12pt,                       % Font size
 a4paper                     % Paper type
]{book}

% Packages \usepackage[ margin=2.7cm, % Margin size marginparwidth=2cm, % Margin note size marginparsep=3mm, % Space between margin and text headheight=15pt % Header height (fix that stupid warn from fancyhdr) ]{geometry} \usepackage[romanian]{babel} % Romanian characters support \usepackage{indentfirst} % Add paragraph indentation even after a section \usepackage{marginnote} % Notes on the margins of a document (more advanced \marginpar) \usepackage{titlesec} % Customize titles \usepackage{hyperref} % Hyperlink support \usepackage{graphicx} % Image support \usepackage{xcolor} % Custom colors \usepackage{fancyhdr} % Custom headers \usepackage[titles]{tocloft} % Customize ToC

% Image path \graphicspath{ {../img/} }

% Hyperlink configuration \hypersetup{ colorlinks=true, urlcolor=black, linkcolor=black % ToC links color }

% Colors (for chapter) \definecolor{gray75}{gray}{0.75}

% Custom format for titles, sections etc. \titleformat{\part}[display] {\Huge\scshape\filright} {\partname~\thepart:} {20pt} {\thispagestyle{empty}}

\titleformat{\chapter}[hang] {\Large} {\thechapter \ifnum\value{chapter} > 9 {\hspace{7pt}}\else{\hspace{15pt}}\fi \textcolor{gray75}{|}\hspace{15pt}} {0pt} {\thispagestyle{chapterfancystyle}\Large}

\renewcommand{\thesection}{\arabic{section}} \titleformat*{\section} {\large\bfseries}

\titleformat{\subsection} {\normalfont\normalfont\bfseries} {} {1.5em} {}

% Custom commands % Format: \newcommand{\command}[variable]{action #variable} \newcommand{\rom}[1]{\uppercase\expandafter{\romannumeral #1\relax}} % Roman numerals \newcommand{\textbfit}[1]{\textbf{\textit{#1}}} % combine bold and italic \newcommand{\operatitle}{} % to not get errors \newcommand{\operaauthor}{} % to not get errors

% Customize \marginnote font \renewcommand\marginfont{\ttfamily\footnotesize}

% Make \ttfamily hyphenate words for the margin notes \DeclareFontFamily{OT1}{cmtt}{\hyphenchar\font=-1} \DeclareFontFamily{\encodingdefault}{\ttdefault}{\hyphenchar\font=`-} \DeclareFontFamily{T1}{cmtt}{\hyphenchar\font=45}

% ToC customization \setcounter{tocdepth}{0} % Make only chapters appear in ToC \renewcommand{\cftdot}{} % Remove ToC dots

% Disable bold in ToC \addtocontents{toc}{\string\renewcommand{\protect\cftchappagefont}{\protect\normalfont}} \addtocontents{toc}{\string\renewcommand{\protect\cftchapfont}{\protect\normalfont}} \addtocontents{toc}{\string\renewcommand{\protect\cftchapleader}{\protect\normalfont\protect\cftdotfill{\protect\cftsecdotsep}}}

% Custom fancy styles \fancypagestyle{chapterfancystyle}{ \fancyhf{} \fancyfoot[LE,RO]{\thepage} \renewcommand{\headrulewidth}{0pt} \renewcommand{\footrulewidth}{1pt} }

\fancypagestyle{plain}{ \fancyhf{} \fancyhead[LE]{\small\textsc{Esee pentru bacalaureat}} \fancyhead[RO]{ \begingroup \small \let\textbfit\relax % smart thing to use \textsc in header but keep it bfit everywhere else \textsc{\operatitle\ -- \operaauthor} \endgroup } \fancyfoot[LE,RO]{\thepage} \renewcommand{\headrulewidth}{2pt} \renewcommand{\footrulewidth}{1pt} }

% Use empty pagestyle on blank pages between chapters \makeatletter \def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else \hbox{}\thispagestyle{empty}\newpage\if@twocolumn\hbox{}\newpage\fi\fi\fi} \makeatother

\begin{document} \input{titlepage.tex} % Import the title page

% Use empty pagestyle for the entirety of the ToC \addtocontents{toc}{\protect\thispagestyle{empty}} \clearpage { \pagestyle{empty} \fancypagestyle{plain} % create temporary plain pagestyle { \fancyhf{} \renewcommand{\headrulewidth}{0pt} \renewcommand{\footrulewidth}{0pt} } \tableofcontents % actually generate the ToC \thispagestyle{empty} } \pagestyle{plain} % revert to plain pagestyle

[...]

\end{document}

Also, here's the entire TeX document, if there is more context needed

EDIT: Thanks to everyone's suggestions, I made small changes, and also made everything into my own custom documentclass. This brings the actual document down to only:

\documentclass{eseuri_bac_romana}

\begin{document} \maketitle % Insert the custom title page \CustomToC % Insert the custom ToC

[...]

\end{document}

And here is the .cls file:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{eseuri_bac_romana}[2022/03/25 My custom class for the essay book]

\LoadClass[ 12pt, % Font size a4paper % Paper type ]{book}

% Packages \RequirePackage[ margin=2.7cm, % Margin size marginparwidth=2cm, % Margin note size marginparsep=3mm, % Space between margin and text headheight=15pt % Header height (fix that stupid warn from fancyhdr) ]{geometry} \RequirePackage[romanian]{babel} % Romanian characters support \RequirePackage{indentfirst} % Add paragraph indentation even after a section \RequirePackage{marginnote} % Notes on the margins of a document (more advanced \marginpar) \RequirePackage{titlesec} % Customize titles \RequirePackage{graphicx} % Image support \RequirePackage{xcolor} % Custom colors \RequirePackage{fancyhdr} % Custom headers \RequirePackage[titles]{tocloft} % Customize ToC \RequirePackage{hyperref} % Hyperlink support, keep last in package list!

% Image path \graphicspath{ {../img/} }

% Hyperlink configuration \hypersetup{ colorlinks=true, urlcolor=black, linkcolor=black % ToC links color }

% Colors (for chapter) \definecolor{gray75}{gray}{0.75}

% Custom format for titles, sections etc. \titleformat{\part}[display] {\Huge\scshape\filright} {\partname~\thepart:} {20pt} {\thispagestyle{empty}}

\newcommand{\DetermineHSpaceSize}{\ifnum\value{chapter} > 9 {\hspace{7pt}}\else{\hspace{15pt}}\fi} % Make the hspace that goes between chapter number and line smaller if number is past 10 \titleformat{\chapter}[hang] {\Large} {\thechapter\DetermineHSpaceSize\textcolor{gray75}{|}\hspace{15pt}} {0pt} {\thispagestyle{chapterfancystyle}\Large}

\renewcommand{\thesection}{\arabic{section}} % Remove chapter number from section \titleformat*{\section} {\large\bfseries}

\titleformat{\subsection} {\normalfont\normalfont\bfseries} {} {1.5em} {}

% Custom commands % Format: \newcommand{\command}[variable]{action #variable} \newcommand{\rom}[1]{\uppercase\expandafter{\romannumeral #1\relax}} % Roman numerals \newcommand{\textbfit}[1]{\textbf{\textit{#1}}} % combine bold and italic \newcommand{\operatitle}{} % to not get errors \newcommand{\operaauthor}{} % to not get errors

\newcommand{\CustomToC} % command to generate ToC with empty pagestyle { \addtocontents{toc}{\protect\thispagestyle{empty}} \clearpage % new page to ensure it switched to empty pagestyle { \pagestyle{empty} \fancypagestyle{plain} % create temporary plain pagestyle { \fancyhf{} \renewcommand{\headrulewidth}{0pt} \renewcommand{\footrulewidth}{0pt} } \tableofcontents % actually generate the ToC \thispagestyle{empty} } \pagestyle{plain} % revert to plain pagestyle }

% Customize \marginnote font \renewcommand\marginfont{\ttfamily\footnotesize}

% Make \ttfamily hyphenate words for the margin notes \DeclareFontFamily{OT1}{cmtt}{\hyphenchar\font=-1} \DeclareFontFamily{\encodingdefault}{\ttdefault}{\hyphenchar\font=`-} \DeclareFontFamily{T1}{cmtt}{\hyphenchar\font=45}

% ToC customization \setcounter{tocdepth}{0} % Make only chapters appear in ToC \renewcommand{\cftdot}{} % Remove ToC dots \addtocontents{toc}{\string\renewcommand{\protect\cftchappagefont}{\protect\normalfont}} \addtocontents{toc}{\string\renewcommand{\protect\cftchapfont}{\protect\normalfont}} \addtocontents{toc}{\string\renewcommand{\protect\cftchapleader}{\protect\normalfont\protect\cftdotfill{\protect\cftsecdotsep}}} % Disable bold in ToC

% Custom fancy styles \fancypagestyle{chapterfancystyle}{ \fancyhf{} \fancyfoot[LE,RO]{\thepage} \renewcommand{\headrulewidth}{0pt} \renewcommand{\footrulewidth}{1pt} } % style for chapter page

\fancypagestyle{plain}{ \fancyhf{} \fancyhead[LE]{\small\textsc{Eseuri pentru bacalaureat}} \fancyhead[RO]{ \begingroup \small \let\textbfit\relax % smart thing to use \textsc in header but keep it bfit everywhere else \textsc{\operatitle\ -- \operaauthor} \endgroup } \fancyfoot[LE,RO]{\thepage} \renewcommand{\headrulewidth}{2pt} \renewcommand{\footrulewidth}{1pt} } % style for the rest of the document

% Use empty pagestyle on blank pages between chapters \makeatletter \def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else \hbox{}\thispagestyle{empty}\newpage\if@twocolumn\hbox{}\newpage\fi\fi\fi} \makeatother

% Create custom title \renewcommand{\maketitle} { \begin{titlepage}

[...]

\end{titlepage} }

Andy3153
  • 361
  • 4
    I would avoid any LaTeX programming after \begin{document}. If you need to design a complicated title page you can put that in commands in the preamble. Otherwise this is a pretty typical preamble for a document with customizations. – musarithmia Mar 25 '22 at 14:24
  • 4
    When mine get this long I put them in a package (.sty) file so I can keep my focus on the writing in the main document. You just start with \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{mystyle}[2022/03/25 custom style], then put everything you have here but write \RequirePackage instead of \includepackage, and end with \endinput. Then in the main document you just have \includepackage{mystyle}. – musarithmia Mar 25 '22 at 14:24
  • @musarithmia I was able to move "Disable bold in ToC" in the preamble, like in the edit, but not the empty pagestyle for ToC part (since it generates the ToC as part of it). Any suggestions for that/a different way to have a ToC with the empty pagestyle? – Andy3153 Mar 25 '22 at 14:52
  • 5
    If you don't want to worry about programming a .sty file as @musarithmia suggested, you can also just copy all the lines from your preamble, paste them into a header.tex file, and issue \input{header.tex}. But honestly, the amount of stuff you have is pretty tame. It is only long because you opted for legibility (otherwise a lot of newlines can be suppressed). If you find scrolling past the preamble annoying, try to see if you can set up some sort of folding in your text editor. – Willie Wong Mar 25 '22 at 15:35
  • 2
    It would be a different issue if you plan to produce many documents with the same styling; in that case creating a personal .sty file can be worth the time. – Willie Wong Mar 25 '22 at 15:37
  • 4
    Move hyperref further down your package list. It should typically be loaded last (with the exception of very few packages which need to be loaded after it). – Skillmon Mar 25 '22 at 15:45
  • @WillieWong Actually, in that repo with the .tex source file, for every single document that gets included, I have a .tex file that generates them separately, and that has a preamble made in the style you were talking about: another .tex file that I am just \input-ing. One question though, for creating an .sty file. Would I put even stuff like the documentclass inside it? Or is it up to me to choose? – Andy3153 Mar 25 '22 at 20:45
  • 1
    Documentclass is not included in a package. If you need to control the documentclass, then make a .cls class file. This starts with \NeedsTeXFormat{LaTeX2e} \ProvidesClass{myclass}[2022/03/25 my class] and then something like \LoadClass[12pt]{article} and the rest of your stuff, same as in a package file. – musarithmia Mar 25 '22 at 20:54
  • 1
    @musarithmia I actually ended up making my own class file, since I thought it fit the requirements better. I added it in an edit of the original post – Andy3153 Mar 25 '22 at 22:26

0 Answers0