|
19 | 19 | \RequirePackage{tocloft} |
20 | 20 | \RequirePackage{etoolbox} |
21 | 21 | \RequirePackage{fancyhdr} |
| 22 | +\RequirePackage{trimclip} |
| 23 | +\RequirePackage{tabularx} |
22 | 24 |
|
| 25 | +% Define a custom command to set the document title |
| 26 | +% Usage: \settitle{Your Title} sets \title to "Your Title" |
23 | 27 | \newcommand{\settitle}[1]{\renewcommand{\title}{#1}} |
| 28 | + |
| 29 | +% Define a custom command to set the document author |
| 30 | +% Usage: \setauthor{Your Name} sets \author to "Your Name" |
24 | 31 | \newcommand{\setauthor}[1]{\renewcommand{\author}{#1}} |
25 | 32 |
|
26 | | -\settitle{My Recipe Book} |
27 | | -\setauthor{Niklas Hoefflin} |
| 33 | +% Set the actual title and author of the recipe book |
| 34 | +\settitle{My Recipe Book} % Title metadata and reference |
| 35 | +\setauthor{Niklas Hoefflin} % Author metadata and reference |
| 36 | + |
| 37 | +% Load the hyperref package to enable hyperlinks and set PDF metadata |
28 | 38 | \RequirePackage[ |
29 | | - colorlinks=false, |
30 | | - linkcolor=blue, |
31 | | - pdfauthor={\author}, |
32 | | - pdftitle={\title}, |
33 | | - pdfsubject={A collection of delicious recipes}, |
34 | | - pdfkeywords={cooking, recipes, cookbook}, |
35 | | - pdfproducer={LaTeX}, |
36 | | - pdfcreator={pdflatex} |
| 39 | + hidelinks, % Hide link borders and colors (clean look) |
| 40 | + pdfauthor={\author}, % Set PDF metadata author from \author |
| 41 | + pdftitle={\title}, % Set PDF metadata title from \title |
| 42 | + pdfsubject={A collection of delicious recipes}, % Subject metadata |
| 43 | + pdfkeywords={cooking, recipes, cookbook}, % Keywords metadata |
| 44 | + pdfproducer={XeLaTeX}, % Tool used to create PDF |
| 45 | + pdfcreator={XeLaTeX} % Engine used to compile the document |
37 | 46 | ]{hyperref} |
38 | 47 |
|
39 | 48 | % Fonts |
40 | 49 | \setmainfont[ |
41 | | - Path=./fonts/, |
42 | | - UprightFont = *-Regular.ttf, |
43 | | - BoldFont = *-Bold.ttf, |
44 | | - ItalicFont = *-Italic.ttf, |
45 | | - BoldItalicFont = *-BoldItalic.ttf |
| 50 | + Path=./fonts/, |
| 51 | + UprightFont = *-Regular.ttf, |
| 52 | + BoldFont = *-Bold.ttf, |
| 53 | + ItalicFont = *-Italic.ttf, |
| 54 | + BoldItalicFont = *-BoldItalic.ttf |
46 | 55 | ]{PublicSans} |
47 | 56 |
|
48 | 57 | \newfontfamily\fontseasons[ |
49 | | - Path=./fonts/, |
50 | | - UprightFont = *Regular.ttf, |
51 | | - BoldFont = *Bold.ttf, |
52 | | - ItalicFont = *Italic.ttf, |
53 | | - BoldItalicFont = *BoldItalic.ttf |
| 58 | + Path=./fonts/, |
| 59 | + UprightFont = *Regular.ttf, |
| 60 | + BoldFont = *Bold.ttf, |
| 61 | + ItalicFont = *Italic.ttf, |
| 62 | + BoldItalicFont = *BoldItalic.ttf |
54 | 63 | ]{TheSeasons} |
55 | 64 |
|
56 | 65 | \newfontfamily\fontseasonslight[ |
57 | | - Path=./fonts/, |
58 | | - UprightFont = *Light.ttf, |
59 | | - ItalicFont = *LightItalic.ttf, |
60 | | - BoldFont = *Light.ttf |
| 66 | + Path=./fonts/, |
| 67 | + UprightFont = *Light.ttf, |
| 68 | + ItalicFont = *LightItalic.ttf, |
| 69 | + BoldFont = *Light.ttf |
61 | 70 | ]{TheSeasons} |
62 | 71 |
|
63 | 72 | % Layout |
64 | | -\newlength{\picmargin} |
65 | | -\setlength{\picmargin}{15pt} |
66 | | -\newlength{\picwidth} |
67 | | -\setlength{\picwidth}{\paperwidth - 2\picmargin} |
68 | | - |
69 | 73 | \geometry{ |
70 | | - top=0pt, |
71 | | - bottom=2cm, |
72 | | - left=\picmargin, |
73 | | - right=\picmargin |
| 74 | + top=0cm, |
| 75 | + bottom=2cm, |
| 76 | + left=0cm, |
| 77 | + right=0cm |
74 | 78 | } |
75 | 79 |
|
76 | | - |
77 | 80 | \pagestyle{fancy} |
78 | 81 | \fancyhf{} |
79 | 82 |
|
80 | 83 | \fancyfoot[C]{\fontsize{10}{12}\selectfont \thepage} |
81 | 84 |
|
82 | | -\renewcommand{\headrulewidth}{0pt} |
83 | | -\renewcommand{\footrulewidth}{0pt} |
84 | | - |
85 | | -\fancypagestyle{plain}{ |
86 | | - \fancyhf{} |
87 | | -\fancyfoot[C]{\fontsize{10}{12}\selectfont \thepage} |
88 | | - \renewcommand{\headrulewidth}{0pt} |
89 | | - \renewcommand{\footrulewidth}{0pt} |
90 | | -} |
91 | | - |
| 85 | +% Create a section that appears in the Table of Contents, but not visibly in the document |
92 | 86 | \newcommand\invisiblesection[1]{% |
93 | | - \refstepcounter{section}% |
94 | | - \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}% |
95 | | - \sectionmark{#1}} |
| 87 | + \refstepcounter{section}% |
| 88 | + \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}% |
| 89 | + \sectionmark{#1}} |
96 | 90 |
|
97 | 91 | \addto\captionsenglish{% |
98 | | - \renewcommand{\contentsname}{\fontsize{28}{32}\selectfont\fontseasons{Table of Contents}} |
| 92 | + \renewcommand{\contentsname}{\begin{center}\fontsize{28}{32}\selectfont\fontseasons{Table of Contents}\end{center}} |
99 | 93 | } |
100 | 94 |
|
101 | | -\renewcommand{\cftsecfont}{} |
102 | | -\renewcommand{\cftsecpagefont}{\large} |
| 95 | +\renewcommand{\cftsecfont}{\fontsize{16}{20}\selectfont\fontseasons} |
| 96 | +\renewcommand{\cftsecpagefont}{\fontsize{16}{20}\selectfont} |
103 | 97 |
|
104 | 98 | \makeatletter |
105 | | -% Redefine section ToC entry to have dots |
106 | 99 | \renewcommand{\l@section}[2]{% |
107 | | - \@dottedtocline{1}{2pt}{2em}{#1}{#2}% |
| 100 | + \addpenalty{\@secpenalty}% |
| 101 | + \addvspace{1em}% |
| 102 | + \begingroup |
| 103 | + \parindent=0pt |
| 104 | + \centering |
| 105 | + \fontsize{14}{16}\selectfont\fontseasons |
| 106 | + \makebox[\textwidth][c]{% |
| 107 | + \makebox[0.7\textwidth][c]{#1\hfill#2}% |
| 108 | + }% |
| 109 | + |
| 110 | + \par |
| 111 | + \endgroup |
108 | 112 | } |
109 | 113 | \makeatother |
110 | 114 |
|
111 | | -% Colors |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | +% Color used for the ingredients box background |
112 | 121 | \definecolor{bgIngredients}{HTML}{F8EDE9} |
113 | | -\definecolor{textColor}{HTML}{000000} |
114 | 122 |
|
115 | | -% Macros |
116 | | -\newcommand{\recipeTitle}[1]{ |
117 | | - \vspace{0.2cm} |
118 | | - \parbox{\picwidth}{ |
119 | | - \centering |
120 | | - \fontsize{28}{32}\selectfont\fontseasons{\textbf{#1}}} |
| 123 | +% Command to format and display the recipe title nicely |
| 124 | +\newcommand{\recipeTitle}[1]{% |
| 125 | + \vspace{0.2cm} |
| 126 | + \noindent |
| 127 | + \begin{center} |
| 128 | + {\fontsize{28}{32}\selectfont\fontseasons\textbf{#1}} |
| 129 | + \end{center} |
| 130 | + \vspace{0.1cm} |
121 | 131 | } |
122 | 132 |
|
123 | | -% === Recipe metadata === |
124 | | -\newcommand{\recipeName}{} |
125 | | -\newcommand{\servings}{} |
126 | | -\newcommand{\prepTime}{} |
127 | | -\newcommand{\cookTime}{} |
128 | | -\newcommand{\recipeImage}{} |
| 133 | +% Define placeholders for recipe metadata, initially empty |
| 134 | +\newcommand{\recipeName}{} % The title of the recipe |
| 135 | +\newcommand{\servings}{} % Number of servings |
| 136 | +\newcommand{\prepTime}{} % Preparation time |
| 137 | +\newcommand{\cookTime}{} % Cooking time |
| 138 | +\newcommand{\recipeImage}{} % Filename/path of the recipe image |
129 | 139 |
|
| 140 | +% Command to set all recipe metadata in one call |
| 141 | +% Usage: \setRecipeMeta{Title}{Servings}{Prep Time}{Cook Time}{Image Filename} |
130 | 142 | \newcommand{\setRecipeMeta}[5]{% |
131 | | - \renewcommand{\recipeName}{#1}% |
132 | | - \renewcommand{\servings}{#2}% |
133 | | - \renewcommand{\prepTime}{#3}% |
134 | | - \renewcommand{\cookTime}{#4}% |
135 | | - \renewcommand{\recipeImage}{#5}% |
| 143 | + \renewcommand{\recipeName}{#1}% Set the recipe title |
| 144 | + \renewcommand{\servings}{#2}% Set the number of servings |
| 145 | + \renewcommand{\prepTime}{#3}% Set the preparation time |
| 146 | + \renewcommand{\cookTime}{#4}% Set the cooking time |
| 147 | + \renewcommand{\recipeImage}{#5}% Set the path to the recipe image |
136 | 148 | } |
137 | 149 |
|
| 150 | + |
| 151 | +% Macro to define a single ingredient item in the ingredients list |
| 152 | +\newcommand{\ingredient}[1]{\item{#1}} |
| 153 | +% Macro to define a single cooking step in the steps list |
| 154 | +\newcommand{\step}[1]{\item{#1}} |
| 155 | + |
| 156 | + |
| 157 | +% Trick to auto scale recipe images |
| 158 | +% https://tex.stackexchange.com/questions/547621/crop-an-image-to-exact-measurements |
| 159 | +\newcommand\picdims[4][]{% |
| 160 | + \setbox0=\hbox{\includegraphics[#1]{#4}}% |
| 161 | + \clipbox{.5\dimexpr\wd0-#2\relax{} % |
| 162 | + .5\dimexpr\ht0-#3\relax{} % |
| 163 | + .5\dimexpr\wd0-#2\relax{} % |
| 164 | + .5\dimexpr\ht0-#3\relax}{\includegraphics[#1]{#4}}} |
| 165 | + |
138 | 166 | % Recipe environment |
139 | 167 | \newenvironment{recipe}{ |
140 | | -\clearpage |
141 | | -\pagestyle{fancy} |
142 | | -\phantomsection |
143 | | -\refstepcounter{section} |
144 | | -\addcontentsline{toc}{section} |
145 | | -{\protect\numberline{\thesection} \recipeName} |
146 | | - \begin{center} |
147 | | - \makebox[\textwidth]{\includegraphics[width=\paperwidth]{\recipeImage}} |
148 | | - \end{center} |
149 | | - |
150 | | - \vspace{0.6cm} |
151 | | - \hspace{-\picmargin} |
152 | | - \recipeTitle{\recipeName} |
153 | | - |
154 | | - \begin{center} |
155 | | - \begin{tabular}{c c c} |
156 | | - \fontsize{12}{16}\selectfont{SERVINGS: \servings} \hspace{2.5cm} & |
157 | | - \fontsize{12}{16}\selectfont{PREPPING TIME: \prepTime} & |
158 | | - \hspace{.5cm} \fontsize{12}{16}\selectfont{COOKING TIME: \cookTime} |
159 | | - \end{tabular} |
160 | | - \vspace{2pt} |
161 | | - \begin{tikzpicture} |
162 | | - \draw[very thick] (4,0) -- (\linewidth+15pt,0); |
163 | | - \end{tikzpicture} |
164 | | - \end{center} |
165 | | - |
166 | | - \vspace{1cm} % optional vertical spacing before |
167 | | - |
| 168 | + \clearpage |
| 169 | + \pagestyle{fancy} |
| 170 | + \phantomsection |
| 171 | + \refstepcounter{section} |
| 172 | + \addcontentsline{toc}{section}{\recipeName} |
| 173 | + \noindent\makebox[\paperwidth][l]{% |
| 174 | + \picdims[width=\paperwidth]{\paperwidth}{225.75pt}{\recipeImage}% |
| 175 | + } |
| 176 | + \vspace{0.2cm} |
| 177 | + \recipeTitle{\recipeName} |
| 178 | + \begin{center} |
| 179 | + \begin{minipage}{16cm} |
| 180 | + \begin{center} |
| 181 | + \begin{tabularx}{15cm}{@{}lXcXr@{}} |
| 182 | + \fontsize{12}{16}\selectfont SERVINGS: \servings & |
| 183 | + & |
| 184 | + \fontsize{12}{16}\selectfont PREPPING TIME: \prepTime & |
| 185 | + & |
| 186 | + \fontsize{12}{16}\selectfont COOKING TIME: \cookTime |
| 187 | + \end{tabularx} |
| 188 | + \end{center} |
| 189 | + \vspace{-10pt} |
| 190 | + \begin{tikzpicture} |
| 191 | + \draw[very thick] (0,0) -- (16cm,0); |
| 192 | + \end{tikzpicture} |
| 193 | + \end{minipage} |
| 194 | + \end{center} |
168 | 195 | } |
169 | 196 |
|
170 | 197 | % Ingredients environment |
171 | | - |
172 | 198 | \newenvironment{ingredients}{ |
173 | | - \begin{tikzpicture}[remember picture, overlay] |
174 | | - \node[fill=bgIngredients, opacity=1.0, anchor=north west, minimum width=6cm, minimum height=15cm, inner sep=0pt] |
175 | | - at ([xshift=50pt,yshift=-345pt]current page.north west) {}; |
176 | | - \end{tikzpicture}% |
177 | | - \hspace{35pt}% |
178 | | - \begin{minipage}[t]{0.25\textwidth} |
179 | | - \section*{{\fontsize{22}{26}\selectfont\fontseasonslight Ingredients}} |
180 | | - \begin{itemize}[label={}, itemsep=4pt, leftmargin=0pt] |
181 | | -}{ |
182 | | - \end{itemize} |
183 | | - \end{minipage}% |
| 199 | + \vspace{1cm} |
| 200 | + \begin{tikzpicture}[remember picture, overlay] |
| 201 | + \node[fill=bgIngredients, opacity=1.0, anchor=north west, minimum width=6.5cm, minimum height=15cm, inner sep=0pt] |
| 202 | + at ([xshift=50pt,yshift=-350pt]current page.north west) {}; |
| 203 | + \end{tikzpicture}% |
| 204 | + \hspace{70pt}% |
| 205 | + \begin{minipage}[t]{0.25\textwidth} |
| 206 | + \section*{{\fontsize{22}{26}\selectfont\fontseasonslight Ingredients}} |
| 207 | + \begin{itemize}[label={}, itemsep=4pt, leftmargin=0pt] |
| 208 | + }{ |
| 209 | + \end{itemize} |
| 210 | + \end{minipage}% |
184 | 211 | } |
185 | 212 |
|
186 | | - |
187 | 213 | % Steps environment |
188 | 214 | \newenvironment{steps}{ |
189 | | -\hspace{35pt}% |
190 | | -\begin{minipage}[t]{0.45\textwidth} |
191 | | - \section*{{\fontsize{22}{26}\selectfont\fontseasonslight Instructions}} |
192 | | - \begin{enumerate}[itemsep=4pt, leftmargin=13pt] |
193 | | -}{% |
194 | | - \end{enumerate} |
195 | | - \end{minipage} |
196 | | -} |
197 | | - |
198 | | - |
199 | | -\newcommand{\ingredient}[1]{\item \textcolor{textColor}{#1}} |
200 | | - |
201 | | -\newcommand{\step}[1]{\item \textcolor{textColor}{#1}} |
| 215 | + \hspace{34pt}% |
| 216 | + \begin{minipage}[t]{0.45\textwidth} |
| 217 | + \section*{{\fontsize{22}{26}\selectfont\fontseasonslight Instructions}} |
| 218 | + \begin{enumerate}[itemsep=4pt, leftmargin=13pt] |
| 219 | + }{% |
| 220 | + \end{enumerate} |
| 221 | + \end{minipage} |
| 222 | +} |
0 commit comments