Created
June 7, 2012 13:28
-
-
Save phi-gamma/2888809 to your computer and use it in GitHub Desktop.
refined structure fullsize image macros
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% macros=mkvi | |
% | |
% pretty dummy graphics | |
\useMPlibrary | |
[dum] | |
% fake text | |
\usemodule | |
[visual] | |
\setuppagenumbering | |
[alternative=doublesided] | |
\setupbackgrounds | |
[page] | |
[background=chapterimages] | |
\definelayer | |
[chapterimages] | |
\setuphead | |
[chapter] | |
[before=\setups{s:chapter}] | |
\definemakeup | |
[chapterimage] | |
[page] | |
\definelayout | |
[chapterimage] %% invoked automagically by the makeup | |
[page] | |
\setupmakeup | |
[chapterimage] | |
[page=left,] %% images on verso | |
\unprotect | |
\newcount \image_counter | |
\newdimen\image_ht | |
\newdimen\image_wd | |
\def\defineimagelist{\dodoubleempty\do_define_image_list} | |
\def\do_define_image_list[#structurename][#lst]{% | |
\edef\current_structure{#structurename}% | |
\scratchcounter0 | |
\ifsecondargument | |
\processcommalist[#lst]\define_structure_image | |
\fi% | |
} | |
%% We-F¢ll do this in an old fashioned manner with macros for each image. | |
\def\define_structure_image#img{% | |
\advance\scratchcounter\plusone | |
\expandafter\def% | |
\csname\current_structure _image_\the\scratchcounter\endcsname{% | |
\externalfigure[#img]% | |
}% | |
} | |
\unexpanded\def\pickimage{\dosingleempty\do_pick_image} | |
\def\do_pick_image[#structurename]{% | |
\global\advance\image_counter\plusone | |
\ifcsname#{structurename}_image_\the\image_counter\endcsname | |
\expandafter\let\expandafter% | |
\current_structure_image\csname#{structurename}_image_\the\image_counter\endcsname | |
\else | |
\let\current_structure_image\structure_image_dummy | |
\fi% | |
\setbox\scratchbox\vbox{\current_structure_image}% | |
\image_ht\ht\scratchbox | |
\image_wd\wd\scratchbox | |
\ctxcommand{test_image_dimensions()} | |
{\current_structure_image[width=\paperwidth]} | |
{\current_structure_image[height=\paperheight]}% | |
} | |
\def\structure_image_dummy{\externalfigure[dummy]}% | |
%% Since \externalfigure[foo][factor=max] doesn¢t work anymore, we¢ll | |
%% have to bypass TEX¢s inadequate integer arithmetic through Lua. | |
\startluacode | |
local td = tex.dimen | |
commands.test_image_dimensions = function () | |
local pht, pwd = td.paperheight, td.paperwidth | |
local iht, iwd = td.image_ht, td.image_wd | |
local result = iht / iwd > pht / pwd | |
-- print(iht, iwd, pht, pwd, result) | |
commands.doifelse(result) | |
end | |
\stopluacode | |
\protect | |
%% This gets shortened to setting the makeup and calling the image | |
%% selector. | |
\startsetups s:chapter | |
\startchapterimagemakeup | |
\pickimage[chapter] | |
\stopchapterimagemakeup | |
\stopsetups | |
\starttext | |
\defineimagelist[chapter][cow,mill,hacker] | |
\dorecurse{1}{ | |
\startchapter [title=First Chapter] | |
\startsection [title=Some section] | |
\fakewords{500}{1000} | |
\stopsection | |
\stopchapter | |
\startchapter [title=Second Chapter] | |
\startsection [title=Some other section] | |
\fakewords{500}{1000} | |
\stopsection | |
\stopchapter | |
\startchapter [title=Third Chapter] | |
\startsection [title=Some new section] | |
\fakewords{500}{1000} | |
\stopsection | |
\stopchapter | |
} | |
\stoptext |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment