From c98b70a5cf45585175a7507075517c5fe835fe97 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 12 Oct 2021 16:44:11 +0300 Subject: [PATCH] foldouts now fully working.. Signed-off-by: Alex A. Naanou --- examples/test.tex | 9 +++ photobook.cls | 201 +++++++++++++++++++--------------------------- 2 files changed, 93 insertions(+), 117 deletions(-) diff --git a/examples/test.tex b/examples/test.tex index f0c4d22..e29bb39 100644 --- a/examples/test.tex +++ b/examples/test.tex @@ -51,6 +51,7 @@ auto-calculate \end{foldout} +%\begin{foldout}[in 15cm 10cm] \begin{foldout}[in in 10cm] count \begin{foldoutcell}[2] @@ -89,6 +90,14 @@ \lipsum \lipsum \end{foldoutcell} + % + \newpage + % + \begin{foldoutcell}[2-3] + \lipsum + \lipsum + \lipsum + \end{foldoutcell} \end{foldout} \begin{foldout}[in] diff --git a/photobook.cls b/photobook.cls index f1d3596..d934fc4 100644 --- a/photobook.cls +++ b/photobook.cls @@ -2951,22 +2951,6 @@ + \bleed + \foldmarkoffset}} -% >> \photobook@setfoldoutoffset{}{}{} -% XXX doc [from, to[ -% XXX this can't be used outside of a foldout... -\newcommand\photobook@setfoldoutoffset[3]{% - \expandafter\setlength\csname #1\endcsname{0pt}% - \ifnum \numexpr #2 \relax < \numexpr #3 \relax% - \xintFor* ##1 in {% - \ifnumodd{\thepage}{% - \xintSeq{#2}{\xintiiMin{#3}{\foldoutcellwidthslen + 1} - 1} - }{% - \xintSeq{\xintiiMin{#3}{\foldoutcellwidthslen + 1} - 1}{#2} - }} \do {% - \expandafter\setlength\csname #1\endcsname{% - \csname #1\endcsname% - + \foldoutcellwidths[##1]}}\fi} - \newlength\photobook@foldout@panelwidth \setlength\photobook@foldout@panelwidth{0pt} \newlength\photobook@foldout@maxpanelwidth @@ -3064,7 +3048,6 @@ \newcounter{photobook@foldoutpanel} \setcounter{photobook@foldoutpanel}{1} -% XXX in/out branches are identical -- unify... \newenvironment{foldout}[1][\foldoutspec]{% \begingroup% \setsepchar{ }% @@ -3077,17 +3060,15 @@ % % panel count... \ifnum \photobook@foldout@argslen = 1% - % in... - \ifthenelse{\equal{#1}{in}}{% - \edef\photobook@foldout@count{2}% - \edef\photobook@foldout@prevfold{#1}% - % out... - }{\ifthenelse{\equal{#1}{out}}{% + % in/out... + \ifthenelse{ + \equal{#1}{in} + \OR \equal{#1}{out}}{% \edef\photobook@foldout@count{2}% \edef\photobook@foldout@prevfold{#1}% % count... }{% - \edef\photobook@foldout@count{#1}}}% + \edef\photobook@foldout@count{#1}}% % % build the panels... \xintFor* ##1 in {\xintSeq{1}{\photobook@foldout@count}} \do {% @@ -3096,22 +3077,16 @@ % fold spec... \else% \foreachitem \photobook@foldout@opt \in \photobook@foldout@args{% - % in... - \ifthenelse{\equal{\photobook@foldout@opt}{in}}{% + % in/out... + \ifthenelse{ + \equal{\photobook@foldout@opt}{in} + \OR \equal{\photobook@foldout@opt}{out}}{% \photobook@foldout@pushpanel{% \photobook@foldout@panelwidth}{\photobook@foldout@opt}% % prep for next panel... \edef\photobook@foldout@prevfold{% \photobook@foldout@opt}% \setlength\photobook@foldout@panelwidth{0pt}% - % out... - }{\ifthenelse{\equal{\photobook@foldout@opt}{out}}{% - \photobook@foldout@pushpanel{% - \photobook@foldout@panelwidth}{\photobook@foldout@opt} - % prep for next panel... - \edef\photobook@foldout@prevfold{% - \photobook@foldout@opt}% - \setlength\photobook@foldout@panelwidth{0pt}% % explicit size... }{% % finalize prev panel... @@ -3119,7 +3094,7 @@ \photobook@foldout@pushpanel{% \photobook@foldout@panelwidth}{\photobook@foldout@prevfold}\fi% % - \setlength\photobook@foldout@panelwidth{\photobook@foldout@opt}}}}% + \setlength\photobook@foldout@panelwidth{\photobook@foldout@opt}}}% % add trailing panel... \photobook@foldout@pushpanel{% \photobook@foldout@panelwidth}{\photobook@foldout@prevfold}% @@ -3157,7 +3132,12 @@ % %% >> \begin{foldoutcell} ... \end{foldoutcell} % -%% This will also auto-advance the page when all panels are created. +%% This will also auto-advance the page when all panels are filled. +%% +%% Note that manual panel placement has no effect on the panel counter +%% thus care must be taken when mixing manual and auto-advanced panels. +%% Also note that |foldoutpanel|'s value is not maintained within manually +%% placed panels and should be treated as undefined. %% %% |foldoutcell*| is the same as the non-star version but creates cells %% including bleeds. @@ -3167,12 +3147,32 @@ %% %% These can only be used from within a |foldout| cell. %% +% XXX should we be able to turn clipping on/off??? + \newlength\photobook@foldoutcell@left \setlength\photobook@foldoutcell@left{0pt} \newlength\photobook@foldoutcell@width \setlength\photobook@foldoutcell@width{0pt} -% XXX +% calculate offset via \foldoutcellwidths and write to dimension ... +% >> \photobook@foldoutcell@setfoldoutoffset{}{}{} +% +% NOTE: [, [ -- i.e. is not included... +\newcommand\photobook@foldoutcell@setfoldoutoffset[3]{% + \expandafter\setlength\csname #1\endcsname{0pt}% + \ifnum \numexpr #2 \relax < \numexpr #3 \relax% + \xintFor* ##1 in {% + \xintSeq{#2}{\xintiiMin{#3}{\foldoutcellwidthslen + 1} - 1}} \do {% + \ifnumodd{\thepage}{% + \expandafter\setlength\csname #1\endcsname{% + \csname #1\endcsname% + + \foldoutcellwidths[##1]} + }{% + \expandafter\setlength\csname #1\endcsname{% + \csname #1\endcsname% + + \foldoutcellwidths[-\numexpr ##1 \relax]}}}\fi} + +% foldout panel auto-advance counter... \newcounter{foldoutpanel} \setcounter{foldoutpanel}{0} \edef\photobook@foldoutcell@from{0} @@ -3182,51 +3182,52 @@ \edef\photobook@foldoutcell@from{% \thefoldoutpanel}} -% XXX the following two envs are almost identical... -% XXX BUG: even (left) page panel sizes are in the same order as odd -% page -- should be reversed... -% ...use same strategy as for foldmarks... -% XXX revise naming.... -% foldoutcell - 1:1 (unclipped) -% should be clipped to bleeds, i.e. should use -% foldoutcell* and create a new offset cell inside... -% foldoutcell* - with bleeds like cell* (unclipped)... -% XXX need to be able to turn clipping on/off (???) -% XXX should these clip by default??? -% XXX doc [from, to] -% XXX this can't be used outside of a foldout -- warn... -\newenvironment{foldoutcell}[1][0]{% - \begingroup% - \setsepchar{-}% - \readlist*\photobook@foldoutcell@panels{#1}% - % auto advance panel... - \ifnum \photobook@foldoutcell@panels[1] = 0% - % auto advance page... - \ifnum \value{foldoutpanel} = \foldoutcellwidthslen% - % NOTE: this will reset the counter... - \newpage\fi% - \stepcounter{foldoutpanel}% - \global\edef\photobook@foldoutcell@from{% - \thefoldoutpanel}% - % explicit panels... - \else% - \global\edef\photobook@foldoutcell@from{ - \photobook@foldoutcell@panels[1]}\fi% - % left offset... - \photobook@setfoldoutoffset{photobook@foldoutcell@left}{% - 1 +% set panel left/width dimensions (helper)... +% >> \photobook@foldoutcell@setdimensions[] +% +% NOTE: for see docs for foldoutcell/foldoutcell*... +\newcommand\photobook@foldoutcell@setdimensions[1][0]{ + % parse args... + \setsepchar{-}% + \readlist*\photobook@foldoutcell@panels{#1}% + % + % auto advance panel... + \ifnum \photobook@foldoutcell@panels[1] = 0% + % auto advance page... + \ifnum \value{foldoutpanel} = \foldoutcellwidthslen% + % NOTE: this will reset the counter... + \newpage\fi% + \stepcounter{foldoutpanel}% + \global\edef\photobook@foldoutcell@from{% + \thefoldoutpanel}% + % explicit panels... + \else% + \global\edef\photobook@foldoutcell@from{ + \photobook@foldoutcell@panels[1]}\fi% + % left offset... + \photobook@foldoutcell@setfoldoutoffset{photobook@foldoutcell@left}{% + 1 + }{% + \photobook@foldoutcell@from}% + % panel from-to width... + \ifnum \photobook@foldoutcell@panelslen > 1% + \photobook@foldoutcell@setfoldoutoffset{photobook@foldoutcell@width}{% + \photobook@foldoutcell@from% }{% - \photobook@foldoutcell@from}% - % panel width... - \ifnum \photobook@foldoutcell@panelslen > 1% - \photobook@setfoldoutoffset{photobook@foldoutcell@width}{% - \photobook@foldoutcell@from% - }{% - \photobook@foldoutcell@panels[2] + 1}% - \else% + \photobook@foldoutcell@panels[2] + 1}% + % panel N width... + \else% + \ifnumodd{\thepage}{% \setlength\photobook@foldoutcell@width{% - \foldoutcellwidths[{\photobook@foldoutcell@from}]}\fi% - % + \foldoutcellwidths[{\photobook@foldoutcell@from}]} + }{% + \setlength\photobook@foldoutcell@width{% + \foldoutcellwidths[-\numexpr \photobook@foldoutcell@from \relax]}}\fi} + +\newenvironment{foldoutcell}[1][0]{% + % XXX check if outside of foldout -> warn... + \begingroup% + \photobook@foldoutcell@setdimensions[#1]% \begin{cell*}{% \bleed + \photobook@foldoutcell@left,% @@ -3236,44 +3237,11 @@ }{% \end{cell*}% \endgroup} -% bleed version... + \newenvironment{foldoutcell*}[1][0]{% + % XXX check if outside of foldout -> warn... \begingroup% - \setsepchar{-}% - \readlist*\photobook@foldoutcell@panels{#1}% - % auto advance... - \ifnum \photobook@foldoutcell@panels[1] = 0% - % auto advance page... - \ifnum \value{foldoutpanel} = \foldoutcellwidthslen% - % NOTE: this will reset the counter... - \newpage\fi% - \stepcounter{foldoutpanel}% - \global\edef\photobook@foldoutcell@from{% - \thefoldoutpanel}% - % explicit panels... - \else% - \global\edef\photobook@foldoutcell@from{ - \photobook@foldoutcell@panels[1]}\fi% - % left offset... - \photobook@setfoldoutoffset{photobook@foldoutcell@left}{% - 1 - }{% - \photobook@foldoutcell@from}% - % panel width... - \ifnum \photobook@foldoutcell@panelslen > 1% - \photobook@setfoldoutoffset{photobook@foldoutcell@width}{% - \photobook@foldoutcell@from% - }{% - \photobook@foldoutcell@panels[2] + 1}% - % add bleed to last panel... - \ifnum \photobook@foldoutcell@panels[2] = \foldoutcellwidthslen% - \setlength\photobook@foldoutcell@width{% - \bleed - + \photobook@foldoutcell@width}\fi% - \else% - \setlength\photobook@foldoutcell@width{% - \foldoutcellwidths[{\photobook@foldoutcell@from}]} - \fi% + \photobook@foldoutcell@setdimensions[#1]% % add bleed to first/last panel... \ifnum \photobook@foldoutcell@from = 1% \setlength\photobook@foldoutcell@width{% @@ -3287,7 +3255,6 @@ \setlength\photobook@foldoutcell@width{% \bleed + \photobook@foldoutcell@width}\fi% - % \begin{cell*}{% \photobook@foldoutcell@left,% 0pt}%