| 1 |
% \iffalse meta-comment |
| 2 |
% SPDX-FileCopyrightText: Copyright (c) 2021-2026 Yegor Bugayenko |
| 3 |
% SPDX-License-Identifier: MIT |
| 4 |
% \fi |
| 5 |
|
| 6 |
% \CheckSum{0} |
| 7 |
% |
| 8 |
% \CharacterTable |
| 9 |
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z |
| 10 |
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z |
| 11 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 12 |
% Exclamation \! Double quote \" Hash (number) \# |
| 13 |
% Dollar \$ Percent \% Ampersand \& |
| 14 |
% Acute accent \' Left paren \( Right paren \) |
| 15 |
% Asterisk \* Plus \+ Comma \, |
| 16 |
% Minus \- Point \. Solidus \/ |
| 17 |
% Colon \: Semicolon \; Less than \< |
| 18 |
% Equals \= Greater than \> Question mark \? |
| 19 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 20 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 21 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 22 |
% Right brace \} Tilde \~} |
| 23 |
|
| 24 |
% \GetFileInfo{kdpcover.dtx} |
| 25 |
% \DoNotIndex{\endgroup,\begingroup,\let,\else,\fi,\newcommand,\newenvironment} |
| 26 |
|
| 27 |
% \iffalse |
| 28 |
%<*driver> |
| 29 |
\ProvidesFile{kdpcover.dtx} |
| 30 |
%</driver> |
| 31 |
%<class>\NeedsTeXFormat{LaTeX2e} |
| 32 |
%<class>\ProvidesClass{kdpcover} |
| 33 |
%<*class> |
| 34 |
[2026-05-23 0.6.2 Cover for Kindle Direct Publishing books] |
| 35 |
%</class> |
| 36 |
%<*driver> |
| 37 |
\documentclass{ltxdoc} |
| 38 |
\usepackage{lmodern} |
| 39 |
\usepackage{microtype} |
| 40 |
\AddToHook{env/verbatim/begin}{\microtypesetup{protrusion=false}} |
| 41 |
\usepackage{href-ul} |
| 42 |
\usepackage[dtx,margin=0,small]{docshots} |
| 43 |
\usepackage{graphicx} |
| 44 |
\PageIndex |
| 45 |
\EnableCrossrefs |
| 46 |
\CodelineIndex |
| 47 |
\RecordChanges |
| 48 |
\begin{document} |
| 49 |
\DocInput{kdpcover.dtx} |
| 50 |
\PrintChanges |
| 51 |
\PrintIndex |
| 52 |
\end{document} |
| 53 |
%</driver> |
| 54 |
% \fi |
| 55 |
|
| 56 |
% \title{\includegraphics[width=0.75in]{yb-book-logo.pdf} \\ |kdpcover|: \LaTeX{} Package \\ for Amazon Book Covers\thanks{The sources are on GitHub at \href{https://github.com/yegor256/kdpcover}{yegor256/kdpcover}}} |
| 57 |
% \author{Yegor Bugayenko \\ \texttt{[email protected]}} |
| 58 |
% \date{\filedate, \fileversion} |
| 59 |
% |
| 60 |
% \maketitle |
| 61 |
% |
| 62 |
% \section{Introduction} |
| 63 |
% |
| 64 |
|
| 65 |
% \changes{v0.5.0}{2022/11/29}{The \texttt{docshots} package is used to render the documentation.} |
| 66 |
% This class produces a book cover suitable for Kindle Direct Publishing (KDP). |
| 67 |
% The author employs it for \href{https://amzn.to/2WMTXWF}{a number of his books}. |
| 68 |
% A \LaTeX{} document conforming to this class takes the following form: |
| 69 |
% \docshotPrerequisite{cactus.pdf} |
| 70 |
% \begin{docshot} |
| 71 |
% \documentclass[pages=200,6x9]{kdpcover} |
| 72 |
% \begin{document} |
| 73 |
% \putSpine{kdpcover, a LaTeX class for KDP books} |
| 74 |
% \putVolume{1} |
| 75 |
% \putVersion{0.6.2} |
| 76 |
% \putPrice{\$0.00} |
| 77 |
% \putCopyright{\the\year}{Yegor Bugayenko} |
| 78 |
% \putTitle{kdpcover} |
| 79 |
% \putAuthor{Yegor Bugayenko} |
| 80 |
% \putTLDR{This book recounts |
| 81 |
% an interesting story!} |
| 82 |
% \putPicture{cactus.pdf} |
| 83 |
% \end{document} |
| 84 |
% \end{docshot} |
| 85 |
|
| 86 |
% The problem addressed by this class is the necessity of adjusting the size of |
| 87 |
% the cover PDF in accordance with the number of pages within the book---the more |
| 88 |
% voluminous the book, the broader its spine must be. The class performs the |
| 89 |
% requisite calculations on the fly by means of the |qpdf| tool, which must |
| 90 |
% therefore be installed. The |pdflatex| processor must furthermore be invoked |
| 91 |
% with the |--shell-escape| option, so that \LaTeX{} may execute |qpdf|. |
| 92 |
|
| 93 |
% \section{Class Options} |
| 94 |
|
| 95 |
% \begin{macro}{pages} |
| 96 |
% By means of |pages|, the total number of pages within the book may be specified: |
| 97 |
%\iffalse |
| 98 |
%<*verb> |
| 99 |
%\fi |
| 100 |
\begin{verbatim} |
| 101 |
\documentclass[pages=120]{kdpcover} |
| 102 |
\begin{document} |
| 103 |
\end{document} |
| 104 |
\end{verbatim} |
| 105 |
%\iffalse |
| 106 |
%</verb> |
| 107 |
%\fi |
| 108 |
% \end{macro} |
| 109 |
|
| 110 |
% \begin{macro}{pdf} |
| 111 |
% The |pages| option is best avoided in favour of letting the class compute |
| 112 |
% the size of the book from the PDF file (by means of the |qpdf| command-line |
| 113 |
% tool, which must be installed): |
| 114 |
%\iffalse |
| 115 |
%<*verb> |
| 116 |
%\fi |
| 117 |
\begin{verbatim} |
| 118 |
\documentclass[pdf=book.pdf]{kdpcover} |
| 119 |
\begin{document} |
| 120 |
\end{document} |
| 121 |
\end{verbatim} |
| 122 |
%\iffalse |
| 123 |
%</verb> |
| 124 |
%\fi |
| 125 |
% \end{macro} |
| 126 |
|
| 127 |
% \begin{macro}{6x9} |
| 128 |
% This option sets the page dimensions to 6x9 inches. |
| 129 |
% A custom size may likewise be defined as follows: |
| 130 |
%\iffalse |
| 131 |
%<*verb> |
| 132 |
%\fi |
| 133 |
\begin{verbatim} |
| 134 |
\documentclass[6x9]{kdpcover} |
| 135 |
\setlength\kdpxsize{8.1in} |
| 136 |
\setlength\kdpysize{12.7in} |
| 137 |
\begin{document} |
| 138 |
\end{document} |
| 139 |
\end{verbatim} |
| 140 |
%\iffalse |
| 141 |
%</verb> |
| 142 |
%\fi |
| 143 |
% \end{macro} |
| 144 |
|
| 145 |
% \begin{macro}{barless} |
| 146 |
% To eliminate the black bar at the centre of the page, the |barless| |
| 147 |
% option suffices: |
| 148 |
%\iffalse |
| 149 |
%<*verb> |
| 150 |
%\fi |
| 151 |
\begin{verbatim} |
| 152 |
\documentclass[barless]{kdpcover} |
| 153 |
\begin{document} |
| 154 |
\end{document} |
| 155 |
\end{verbatim} |
| 156 |
%\iffalse |
| 157 |
%</verb> |
| 158 |
%\fi |
| 159 |
% \end{macro} |
| 160 |
|
| 161 |
% \section{Commands} |
| 162 |
|
| 163 |
% \begin{macro}{\putSpine} |
| 164 |
% The |\putSpine| command places a vertical black spine line containing two |
| 165 |
% white elements: the text at the top and the logo at the bottom. The text |
| 166 |
% should be sufficiently short to avoid contact with the logo. It is sound |
| 167 |
% practice to record the volume number at the end of the text whenever more |
| 168 |
% than one volume exists, e.g.\ ``my book, vol.\ 1''. The use of small caps |
| 169 |
% within the text alone is recommended. |
| 170 |
% \end{macro} |
| 171 |
|
| 172 |
% \begin{macro}{\putVolume} |
| 173 |
% This command renders the volume figure. It is deliberately rendered at large |
| 174 |
% size to ensure conspicuousness. |
| 175 |
% \end{macro} |
| 176 |
|
| 177 |
% \begin{macro}{\putVersion} |
| 178 |
% This command prints the version and additionally appends the date of the |
| 179 |
% latest Git commit in the current directory. Should the directory not |
| 180 |
% constitute a Git repository, the date is omitted. |
| 181 |
% \end{macro} |
| 182 |
|
| 183 |
% \begin{macro}{\putPrice} |
| 184 |
% This command prints the price, the inclusion of which is, in the author's |
| 185 |
% view, sound practice. |
| 186 |
% \end{macro} |
| 187 |
|
| 188 |
% \begin{macro}{\putCopyright} |
| 189 |
% This command prints a brief copyright notice, comprising the year and the |
| 190 |
% name of the author. |
| 191 |
% \end{macro} |
| 192 |
|
| 193 |
% \begin{macro}{\putTitle} |
| 194 |
% This command prints the title of the book. |
| 195 |
% \end{macro} |
| 196 |
|
| 197 |
% \begin{macro}{\putAuthor} |
| 198 |
% This command prints the author. |
| 199 |
% \end{macro} |
| 200 |
|
| 201 |
% \begin{macro}{\putTLDR} |
| 202 |
% This command prints the TL;DR paragraph, which summarises the central message |
| 203 |
% of the entire book. |
| 204 |
% \end{macro} |
| 205 |
|
| 206 |
% \begin{macro}{\putPicture} |
| 207 |
% This command prints the front-cover picture. The file |cactus.pdf| may be employed. |
| 208 |
% \end{macro} |
| 209 |
|
| 210 |
% \begin{macro}{\putBack} |
| 211 |
% This command prints the text on the back of the book; the author generally |
| 212 |
% recommends omitting it and leaving the back empty and white. |
| 213 |
% \end{macro} |
| 214 |
|
| 215 |
% \StopEventually{} |
| 216 |
|
| 217 |
% \section{Implementation} |
| 218 |
|
| 219 |
% \changes{v0.2.0}{2021/07/14}{Initial version} |
| 220 |
|
| 221 |
% First, we load our parent class: |
| 222 |
% \changes{v0.5.0}{2022/11/29}{The base class is now \texttt{article}.} |
| 223 |
% \begin{macrocode} |
| 224 |
\LoadClass{article} |
| 225 |
% \end{macrocode} |
| 226 |
|
| 227 |
% Then, we define a few internal commands: |
| 228 |
% \begin{macrocode} |
| 229 |
\makeatletter |
| 230 |
\newcount\kdp@pages |
| 231 |
\kdp@pages=100 |
| 232 |
\newlength\kdp@xsize |
| 233 |
\setlength\kdp@xsize{6in} |
| 234 |
\newlength\kdp@ysize |
| 235 |
\setlength\kdp@ysize{9in} |
| 236 |
\makeatother |
| 237 |
% \end{macrocode} |
| 238 |
|
| 239 |
% Then, we include |iexec| for being able to execute |qpdf| and |git|: |
| 240 |
% \begin{macrocode} |
| 241 |
\RequirePackage{iexec} |
| 242 |
% \end{macrocode} |
| 243 |
|
| 244 |
% Then, we parse class options with the help of the |pgfopts| package: |
| 245 |
% \changes{v0.6.1}{2025/03/02}{If the PDF file is absent, an error is printed.} |
| 246 |
% \begin{macrocode} |
| 247 |
\RequirePackage{pgfopts} |
| 248 |
\makeatletter |
| 249 |
\pgfkeys{ |
| 250 |
/kdp/.cd, |
| 251 |
barless/.store in = \kdp@barless, |
| 252 |
pdf/.code = { |
| 253 |
\IfFileExists{#1} |
| 254 |
{} |
| 255 |
{\PackageError{kdpcover}{The "#1" file is absent}{}}% |
| 256 |
\iexec[trace,quiet,stdout=kdpcover-pages-count.txt] |
| 257 |
{qpdf --show-npages --no-warn #1 | tr -d '[[:space:]]'} |
| 258 |
\openin1=kdpcover-pages-count.txt |
| 259 |
\read1 to \temp |
| 260 |
\closein1 |
| 261 |
\kdp@pages=\temp |
| 262 |
}, |
| 263 |
6x9/.code = { |
| 264 |
\setlength\kdp@xsize{6in} |
| 265 |
\setlength\kdp@ysize{9in} |
| 266 |
}, |
| 267 |
7x10/.code = { |
| 268 |
\setlength\kdp@xsize{7in} |
| 269 |
\setlength\kdp@ysize{10in} |
| 270 |
}, |
| 271 |
8x10/.code = { |
| 272 |
\setlength\kdp@xsize{8in} |
| 273 |
\setlength\kdp@ysize{10in} |
| 274 |
}, |
| 275 |
pages/.code = { |
| 276 |
\kdp@pages=#1 |
| 277 |
} |
| 278 |
} |
| 279 |
\ProcessPgfPackageOptions{/kdp} |
| 280 |
\makeatother |
| 281 |
% \end{macrocode} |
| 282 |
|
| 283 |
% Then, we include a few useful packages: |
| 284 |
% \begin{macrocode} |
| 285 |
\RequirePackage{anyfontsize} |
| 286 |
\RequirePackage{tikz} |
| 287 |
\RequirePackage{microtype} |
| 288 |
\RequirePackage{xcolor} |
| 289 |
\RequirePackage{graphicx} |
| 290 |
\RequirePackage{calc} |
| 291 |
% \end{macrocode} |
| 292 |
|
| 293 |
% Then, we set spacing using |setspace|: |
| 294 |
% \begin{macrocode} |
| 295 |
\RequirePackage{setspace} |
| 296 |
\setstretch{1.2} |
| 297 |
% \end{macrocode} |
| 298 |
|
| 299 |
% Then, we calculate size. |
| 300 |
% The height of the page is 9 inches plus 0.125 "bleed" on top and |
| 301 |
% on the bottom, see \href{https://kdp.amazon.com/en_US/help/topic/G201953020}{this}. |
| 302 |
% The width is 6 inches plus 0.125 "bleed" on each side. The width of the |
| 303 |
% "spine" depends on the amount of pages in the book. |
| 304 |
% \begin{macrocode} |
| 305 |
\makeatletter |
| 306 |
\newlength\kdp@height |
| 307 |
\setlength\kdp@height{0.125in + \kdp@ysize + 0.125in} |
| 308 |
\newlength\kdp@width |
| 309 |
\setlength\kdp@width{ |
| 310 |
0.125in + \kdp@xsize |
| 311 |
+ 0.125in + \kdp@xsize |
| 312 |
+ 0.0025in * \kdp@pages} |
| 313 |
\makeatother |
| 314 |
% \end{macrocode} |
| 315 |
|
| 316 |
% Then, we set the size of the page, using |geometry|: |
| 317 |
% \begin{macrocode} |
| 318 |
\RequirePackage{geometry} |
| 319 |
\makeatletter |
| 320 |
\geometry{ |
| 321 |
paperwidth=\kdp@width, |
| 322 |
paperheight=\kdp@height, |
| 323 |
left=0pt, |
| 324 |
right=0pt, |
| 325 |
top=0pt, |
| 326 |
bottom=0pt |
| 327 |
} |
| 328 |
\makeatother |
| 329 |
% \end{macrocode} |
| 330 |
|
| 331 |
% Then, we set coordinates using |textpos|: |
| 332 |
% \begin{macrocode} |
| 333 |
\PassOptionsToPackage{absolute}{textpos} |
| 334 |
\RequirePackage{textpos} |
| 335 |
\TPGrid{16}{16} |
| 336 |
% \end{macrocode} |
| 337 |
|
| 338 |
% \begin{macro}{\putSpine} |
| 339 |
% Then, we define |\putSpine|: |
| 340 |
% \begin{macrocode} |
| 341 |
\makeatletter |
| 342 |
\newcommand\putSpine[2][kdpcover-signature]{% |
| 343 |
\ifdefined\kdp@barless\else% |
| 344 |
\begin{textblock}{2.4}[0.5,0](8,0)% |
| 345 |
\begin{tikzpicture}% |
| 346 |
\node [rectangle, inner sep=0em, fill=black, |
| 347 |
minimum width=2.4\TPHorizModule, |
| 348 |
minimum height=16\TPVertModule] at (0,0) {}; |
| 349 |
\end{tikzpicture}% |
| 350 |
\end{textblock}% |
| 351 |
\fi% |
| 352 |
\begin{textblock}{1}[0.5,0](8,2)% |
| 353 |
\begin{tikzpicture}% |
| 354 |
\node [color=white, inner sep=0cm, outer sep=0cm, |
| 355 |
rotate=270, minimum height=\TPHorizModule] at (0,0) { |
| 356 |
\Large #2% |
| 357 |
}; |
| 358 |
\end{tikzpicture}% |
| 359 |
\end{textblock}% |
| 360 |
\begin{textblock}{2.4}[0.5,1](8,14)% |
| 361 |
\centerline{\includegraphics[width=0.32in]{#1}}% |
| 362 |
\end{textblock}% |
| 363 |
} |
| 364 |
\makeatother |
| 365 |
% \end{macrocode} |
| 366 |
% \end{macro} |
| 367 |
|
| 368 |
% \begin{macro}{\putPicture} |
| 369 |
% Then, we define |\putPicture|: |
| 370 |
% \begin{macrocode} |
| 371 |
\newcommand\putPicture[1]{% |
| 372 |
\begin{textblock}{4}(10,2)% |
| 373 |
\includegraphics[width=\textwidth]{#1} |
| 374 |
\end{textblock}% |
| 375 |
} |
| 376 |
% \end{macrocode} |
| 377 |
% \end{macro} |
| 378 |
|
| 379 |
% \begin{macro}{\putVolume} |
| 380 |
% Then, we define |\putVolume|: |
| 381 |
% \begin{macrocode} |
| 382 |
\newcommand\putVolume[1]{% |
| 383 |
\begin{textblock}{2}[1,1](15,14)% |
| 384 |
\raggedleft% |
| 385 |
\includegraphics[height=0.4in]{kdpcover-vol-#1}% |
| 386 |
\end{textblock}% |
| 387 |
} |
| 388 |
% \end{macrocode} |
| 389 |
% \end{macro} |
| 390 |
|
| 391 |
% \begin{macro}{\putPrice} |
| 392 |
% Then, we define |\putPrice|: |
| 393 |
% \begin{macrocode} |
| 394 |
\newcommand\putPrice[1]{% |
| 395 |
\begin{textblock}{4}[0,1](1,2)% |
| 396 |
\small #1% |
| 397 |
\end{textblock}% |
| 398 |
} |
| 399 |
% \end{macrocode} |
| 400 |
% \end{macro} |
| 401 |
|
| 402 |
% \begin{macro}{\putBack} |
| 403 |
% Then, we define |\putBack|: |
| 404 |
% \begin{macrocode} |
| 405 |
\newcommand\putBack[1]{% |
| 406 |
\begin{textblock}{5}[0,0](1,3)% |
| 407 |
\small #1% |
| 408 |
\end{textblock}% |
| 409 |
} |
| 410 |
% \end{macrocode} |
| 411 |
% \end{macro} |
| 412 |
|
| 413 |
% \begin{macro}{\putTitle} |
| 414 |
% Then, we define |\putTitle|: |
| 415 |
% \begin{macrocode} |
| 416 |
\newcommand\putTitle[1]{% |
| 417 |
\begin{textblock}{5}(10,9)% |
| 418 |
\fontsize{32}{32}\selectfont #1% |
| 419 |
\end{textblock}% |
| 420 |
} |
| 421 |
% \end{macrocode} |
| 422 |
% \end{macro} |
| 423 |
|
| 424 |
% \begin{macro}{\putAuthor} |
| 425 |
% Then, we define |\putAuthor|: |
| 426 |
% \begin{macrocode} |
| 427 |
\newcommand\putAuthor[1]{% |
| 428 |
\begin{textblock}{4}(10,10)% |
| 429 |
\large by #1% |
| 430 |
\end{textblock}% |
| 431 |
} |
| 432 |
% \end{macrocode} |
| 433 |
% \end{macro} |
| 434 |
|
| 435 |
% \begin{macro}{\putTLDR} |
| 436 |
% Then, we define |\putTLDR|: |
| 437 |
% \begin{macrocode} |
| 438 |
\newcommand\putTLDR[1]{% |
| 439 |
\begin{textblock}{5}(10,11)% |
| 440 |
TL;DR #1% |
| 441 |
\end{textblock}% |
| 442 |
} |
| 443 |
% \end{macrocode} |
| 444 |
% \end{macro} |
| 445 |
|
| 446 |
% \begin{macro}{\putVersion} |
| 447 |
% Then, we define |\putVersion|: |
| 448 |
% \begin{macrocode} |
| 449 |
\newcommand\putVersion[1]{% |
| 450 |
\begin{textblock}{4}[0,1](10,14)% |
| 451 |
#1% |
| 452 |
\IfFileExists{.git} |
| 453 |
{\quad\iexec{git log -n 1 --pretty='format:\%ad' --date='format:\%e-\%b-\%Y'}} |
| 454 |
{}% |
| 455 |
\end{textblock}% |
| 456 |
} |
| 457 |
% \end{macrocode} |
| 458 |
% \end{macro} |
| 459 |
|
| 460 |
% \begin{macro}{\putCopyright} |
| 461 |
% Then, we define |\putCopyright|: |
| 462 |
% \begin{macrocode} |
| 463 |
\newcommand\putCopyright[2]{% |
| 464 |
\begin{textblock}{4}[0,1](1,14)% |
| 465 |
\small (c)~% |
| 466 |
#1 #2% |
| 467 |
\end{textblock}% |
| 468 |
} |
| 469 |
% \end{macrocode} |
| 470 |
% \end{macro} |
| 471 |
|
| 472 |
% Finally, a few layout instructions: |
| 473 |
% \begin{macrocode} |
| 474 |
\AtBeginDocument{% |
| 475 |
\ttfamily% |
| 476 |
\raggedright% |
| 477 |
\setlength\parindent{0pt}% |
| 478 |
\setlength\parskip{0pt}% |
| 479 |
\interfootnotelinepenalty=10000% |
| 480 |
} |
| 481 |
\endinput |
| 482 |
% \end{macrocode} |
| 483 |
|
| 484 |
% \Finale |
| 485 |
|
| 486 |
%\clearpage |
| 487 |
% |
| 488 |
%\PrintChanges |
| 489 |
%\clearpage |
| 490 |
%\PrintIndex |