mirror of
				https://github.com/flynx/photobook.git
				synced 2025-11-03 21:00:18 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			274 lines
		
	
	
		
			8.1 KiB
		
	
	
	
		
			TeX
		
	
	
	
	
	
			
		
		
	
	
			274 lines
		
	
	
		
			8.1 KiB
		
	
	
	
		
			TeX
		
	
	
	
	
	
%----------------------------------------------------------------------
 | 
						|
%
 | 
						|
%
 | 
						|
% This does the following:
 | 
						|
%	- sets up the document/pdf for viewing as a book
 | 
						|
%	- adds support for page bleeds
 | 
						|
%	- adds basic templates for image pages (XXX)
 | 
						|
%
 | 
						|
%----------------------------------------------------------------------
 | 
						|
 | 
						|
\NeedsTeXFormat{LaTeX2e}
 | 
						|
 | 
						|
% XXX set release date...
 | 
						|
\ProvidesClass{photobook}[2021/07/28 Photo book Latex class]
 | 
						|
 | 
						|
 | 
						|
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 | 
						|
 | 
						|
\RequirePackage{calc}
 | 
						|
\RequirePackage{xargs}
 | 
						|
\RequirePackage{iftex}
 | 
						|
\RequirePackage{kvoptions}
 | 
						|
\RequirePackage{etoolbox}
 | 
						|
\RequirePackage{atbegshi}
 | 
						|
\RequirePackage[unicode]{hyperref}
 | 
						|
\RequirePackage{graphicx}
 | 
						|
\RequirePackage{geometry}
 | 
						|
\RequirePackage{eso-pic}
 | 
						|
 | 
						|
 | 
						|
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 | 
						|
% Helpers...
 | 
						|
 | 
						|
\newcommand\@DeclareLiteralOptionTo[2]{%
 | 
						|
	\DeclareVoidOption{#2}{%
 | 
						|
		\expandafter\edef\csname photobook@#1\endcsname{#2}}}
 | 
						|
 | 
						|
 | 
						|
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 | 
						|
% options...
 | 
						|
 | 
						|
% pdf layout...
 | 
						|
%
 | 
						|
% see: hyperref's pdfpagelayout for more options...
 | 
						|
\DeclareStringOption[TwoPageRight]{pdfpagelayout}[TwoPageRight]
 | 
						|
\@DeclareLiteralOptionTo{pdfpagelayout}{SinglePage}
 | 
						|
\@DeclareLiteralOptionTo{pdfpagelayout}{OneColumn}
 | 
						|
\@DeclareLiteralOptionTo{pdfpagelayout}{TwoColumnRight}
 | 
						|
\@DeclareLiteralOptionTo{pdfpagelayout}{TwoColumnLeft}
 | 
						|
\@DeclareLiteralOptionTo{pdfpagelayout}{TwoPageRight}
 | 
						|
\@DeclareLiteralOptionTo{pdfpagelayout}{TwoPageLeft}
 | 
						|
 | 
						|
 | 
						|
% page geometry...
 | 
						|
%
 | 
						|
%   <---> bleed                                 <---> innerbleed
 | 
						|
%
 | 
						|
%   + - - - - - - - - - - - - - - - - - - - - - + - +   ^
 | 
						|
%   .                                           .   .   | bleed
 | 
						|
%   .   +---------------------------------------+   .   v   .   .  ---
 | 
						|
%   .   |                           ^       .   =   .
 | 
						|
%   .   |   .   .   .   .   .   .   |   .   .   =   .               ^
 | 
						|
%   .   |<-- pagewidth ------------------------>=   .               |
 | 
						|
%   .   |   .                       |   .   .   =   .               |
 | 
						|
%   .   |                           |       .   =   .       textheight
 | 
						|
%   .   |   .                       |   .   .   =   .               |
 | 
						|
%   .   |                       pageheight  .   =   .               |
 | 
						|
%   .   |   .                       |   .   .   =   .               |
 | 
						|
%   .   |                           |       <---> bindingoffset     |
 | 
						|
%   .   |   .   .   .   .   .   .   |   .   .   =   .               v
 | 
						|
%   .   |                           v       .   =   .
 | 
						|
%   .   +---------------------------------------+   .   ^   .   .  ---
 | 
						|
%   .   .                                       .   .   | bleed
 | 
						|
%   + - - - - - - - - - - - - - - - - - - - - - + - +   v
 | 
						|
%       .                                       .
 | 
						|
%       |   <-- textwidth -------------->   .   |
 | 
						|
%                                               ^ binding line
 | 
						|
%
 | 
						|
% NOTE: innerbleed defaults to bleed...
 | 
						|
% NOTE: if pagewidth/pageheight are set they will force recalculations 
 | 
						|
%		and overriding of the paperwidth/paperheight if they were changed
 | 
						|
%		by the user code anywhere between \documentclass[..]{photobook}
 | 
						|
%		and \begin{document}...
 | 
						|
\DeclareStringOption[5mm]{bleed}[5mm]
 | 
						|
\DeclareStringOption{innerbleed}
 | 
						|
% XXX do we need to rename these??? (used by lualatex??)
 | 
						|
\DeclareStringOption{pagewidth}
 | 
						|
\DeclareStringOption{pageheight}
 | 
						|
\DeclareStringOption[0]{bindingoffset}[10mm]
 | 
						|
 | 
						|
% Image block size relative to text block...
 | 
						|
%
 | 
						|
% XXX not yet used...
 | 
						|
% XXX better name...
 | 
						|
\DeclareStringOption[0.85]{imageblockwidth}[1]
 | 
						|
\DeclareStringOption[0.85]{imageblockheight}[1]
 | 
						|
\DeclareStringOption[-0.05]{imageblockoffsettop}[0]
 | 
						|
 | 
						|
\DeclareDefaultOption{\PassOptionsToClass{\CurrentOption}{book}}
 | 
						|
\ProcessKeyvalOptions*
 | 
						|
 | 
						|
 | 
						|
% Parent class...
 | 
						|
%
 | 
						|
\LoadClass[9pt, final, openany]{book}
 | 
						|
 | 
						|
 | 
						|
 | 
						|
%----------------------------------------------------------------------
 | 
						|
% Globals...
 | 
						|
 | 
						|
% NOTE: page and bleed block sizes are set via \RecalculatePageLengths
 | 
						|
\newlength\pagewidth
 | 
						|
\newlength\pageheight
 | 
						|
% NOTE: these are equivalent to \paperwidth and \paperheight but are 
 | 
						|
%		independent of them...
 | 
						|
\newlength\bleedblockwidth
 | 
						|
\newlength\bleedblockheight
 | 
						|
 | 
						|
 | 
						|
\newlength\bleed
 | 
						|
\setlength\bleed{\photobook@bleed}
 | 
						|
 | 
						|
\newlength\innerbleed
 | 
						|
\setlength\innerbleed{
 | 
						|
	\ifx\photobook@innerbleed\empty
 | 
						|
		\bleed
 | 
						|
	\else
 | 
						|
		\photobook@innerbleed
 | 
						|
	\fi }
 | 
						|
 | 
						|
 | 
						|
\newlength\bindingoffset
 | 
						|
\setlength\bindingoffset{\photobook@bindingoffset}
 | 
						|
 | 
						|
 | 
						|
 | 
						|
%----------------------------------------------------------------------
 | 
						|
% Commands...
 | 
						|
 | 
						|
\newcommand\keywords[1]{%
 | 
						|
	\def\@keywords{#1}}
 | 
						|
 | 
						|
 | 
						|
\newcommand\subject[1]{%
 | 
						|
	\def\@subject{#1}}
 | 
						|
 | 
						|
 | 
						|
\newcommand\RecalculatePageLengths{
 | 
						|
	% final page size...
 | 
						|
	\setlength\pagewidth{
 | 
						|
		\ifx\photobook@pagewidth\empty
 | 
						|
			\dimexpr \paperwidth - \bleed - \innerbleed \relax
 | 
						|
		\else
 | 
						|
			\photobook@pagewidth
 | 
						|
		\fi}
 | 
						|
	\setlength\pageheight{
 | 
						|
		\ifx\photobook@pageheight\empty
 | 
						|
			\dimexpr \paperheight - 2\bleed \relax
 | 
						|
		\else
 | 
						|
			\photobook@pageheight
 | 
						|
		\fi }
 | 
						|
	% page with bleeds...
 | 
						|
	% NOTE: this is essentially \paperwidth and \paperheight but we do 
 | 
						|
	%		not rely on them being defined -- photobook settings take 
 | 
						|
	%		priority over \paperwidth and \paperwidth...
 | 
						|
	\setlength\bleedblockwidth{\dimexpr 
 | 
						|
		\bleed + \pagewidth + \innerbleed 
 | 
						|
		\relax}
 | 
						|
	\setlength\bleedblockheight{\dimexpr 
 | 
						|
		2\bleed + \pageheight 
 | 
						|
		\relax} }
 | 
						|
 | 
						|
 | 
						|
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 | 
						|
% update global values...
 | 
						|
 | 
						|
\RecalculatePageLengths
 | 
						|
 | 
						|
 | 
						|
 | 
						|
%----------------------------------------------------------------------
 | 
						|
% Setup...
 | 
						|
 | 
						|
\AtEndPreamble{
 | 
						|
 | 
						|
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 | 
						|
% Metadata...
 | 
						|
 | 
						|
	\hypersetup{
 | 
						|
		pdfinfo={
 | 
						|
			Title={\@title},
 | 
						|
			Subject={\@subject},
 | 
						|
			Author={\@author},
 | 
						|
			Keywords={\@keywords},
 | 
						|
		},
 | 
						|
		pdfpagelayout=\photobook@pdfpagelayout,
 | 
						|
	}
 | 
						|
 | 
						|
 | 
						|
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 | 
						|
% Geometry...
 | 
						|
 | 
						|
	\RecalculatePageLengths
 | 
						|
 | 
						|
	\geometry{
 | 
						|
		% paper size (incl. bleeds)...
 | 
						|
		paperwidth=\bleedblockwidth, paperheight=\bleedblockheight,
 | 
						|
		bindingoffset=\bindingoffset,
 | 
						|
		% XXX these should be overridable...
 | 
						|
		% include header/footer/margin notes in printed area
 | 
						|
		twoside, includeall, nomarginpar,
 | 
						|
		ignorehead=false, ignorefoot=false, ignoremp=false,
 | 
						|
		% center printed area on page
 | 
						|
		vcentering, hcentering}
 | 
						|
 | 
						|
 | 
						|
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 | 
						|
% pdf boxes...
 | 
						|
 | 
						|
	% calculate pdf box dimensions in pt...
 | 
						|
	\edef\@pdfWidthPt{\strip@pt\dimexpr 
 | 
						|
		0.996264009963\bleedblockwidth \relax}
 | 
						|
	\edef\@pdfHeightPt{\strip@pt\dimexpr 
 | 
						|
		0.996264009963\bleedblockheight \relax}
 | 
						|
	\edef\@pdfBleedPt{\strip@pt\dimexpr 
 | 
						|
		0.996264009963\bleed \relax}
 | 
						|
	\edef\@pdfTopPt{\strip@pt\dimexpr 
 | 
						|
		0.996264009963\dimexpr 
 | 
						|
			\bleedblockheight - \bleed \relax \relax}
 | 
						|
	\edef\@pdfRightPt{\strip@pt\dimexpr 
 | 
						|
		0.996264009963\dimexpr 
 | 
						|
			\bleedblockwidth - \bleed \relax \relax}
 | 
						|
 | 
						|
	% set the boxes...
 | 
						|
	\ifxetex
 | 
						|
		% XXX not tested...
 | 
						|
		\AtBeginShipout{\AtBeginShipoutAddToBox{
 | 
						|
			\special{pdf:put @thispage <<
 | 
						|
				/MediaBox [0 0 \@pdfWidthPt\space \@pdfHeightPt]
 | 
						|
				/BleedBox [0 0 \@pdfWidthPt\space \@pdfHeightPt]
 | 
						|
				/ArtBox [\@pdfBleedPt\space \@pdfBleedPt\space \@pdfRightPt\space \@pdfTopPt]
 | 
						|
				/TrimBox [\@pdfBleedPt\space \@pdfBleedPt\space \@pdfRightPt\space \@pdfTopPt]
 | 
						|
				/CropBox [\@pdfBleedPt\space \@pdfBleedPt\space \@pdfRightPt\space \@pdfTopPt]
 | 
						|
			>>} }} 
 | 
						|
 | 
						|
	\else
 | 
						|
		\edef\pdfboxes{
 | 
						|
			/MediaBox [0 0 \@pdfWidthPt\space \@pdfHeightPt]
 | 
						|
			/BleedBox [0 0 \@pdfWidthPt\space \@pdfHeightPt]
 | 
						|
			/ArtBox [\@pdfBleedPt\space \@pdfBleedPt\space \@pdfRightPt\space \@pdfTopPt]
 | 
						|
			/TrimBox [\@pdfBleedPt\space \@pdfBleedPt\space \@pdfRightPt\space \@pdfTopPt]
 | 
						|
			/CropBox [\@pdfBleedPt\space \@pdfBleedPt\space \@pdfRightPt\space \@pdfTopPt]
 | 
						|
		}
 | 
						|
		\expandafter\pdfpageattr\expandafter{\pdfboxes}
 | 
						|
	\fi
 | 
						|
 | 
						|
} % \AtEndPreamble{..}
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
%----------------------------------------------------------------------
 | 
						|
% Templates...
 | 
						|
 | 
						|
% XXX
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
%----------------------------------------------------------------------
 | 
						|
%                                                  vim:set ts=4 sw=4 :
 |