pack-mis.mkvi /size: 2896 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=pack-mis, % moved from e.g. core-mis
3%D        version=1998.01.29,
4%D          title=\CONTEXT\ Core Macros,
5%D       subtitle=Miscelaneous,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14\writestatus{loading}{ConTeXt Packing Macros / Misc Commands}
15
16\unprotect
17
18% a quite old mechanism already (but inheritance added)
19%
20% \defineplacement[name][settings]
21% \setupplacement [name][settings]
22% \placement      [name][settings]
23% \place<name>          [settings]
24
25\installcorenamespace{placement}
26
27\installcommandhandler \??placement {placement} \??placement
28
29\appendtoks
30   \setuevalue{\e!place\currentplacement}{\pack_placement{\currentplacement}}%
31\to \everydefineplacement
32
33\setupplacement
34  [\c!left=\hss,
35   \c!right=\hss,
36   \c!linecorrection=\v!off,
37   \c!depthcorrection=\v!off,
38   \c!grid=\v!middle,
39  %\c!before=,
40  %\c!after=,
41   \c!margin=\v!standard]
42
43\unexpanded\def\placement[#tag]%
44  {\pack_placement{#tag}}
45
46\unexpanded\def\pack_placement#tag%
47  {\bgroup
48   \edef\currentplacement{#tag}%
49   \doifelsenextoptionalcs\pack_placement_yes\pack_placement_nop}
50
51\def\pack_placement_yes[#settings]%
52  {\setupcurrentplacement[#settings]%
53   \pack_placement_nop}
54
55\def\pack_placement_nop
56  {\dowithnextboxcontentcs\forgetall\pack_placement_flush\vbox}
57
58\def\pack_placement_flush
59  {\setlocalhsize
60   \placementparameter\c!before
61   \begingroup
62   \disableparpositions
63   \setbox\nextbox\hbox to \localhsize
64     {\placementparameter\c!left
65      \flushnextbox
66      \placementparameter\c!right}%
67  %\ifinsidefloat \else
68  %  \page_backgrounds_add_local_to_box\nextbox
69  %\fi
70\flushnotes % new per 2014-05-29 : todo: move them up in the mvl
71   \ifgridsnapping
72     \pack_placement_flush_grid_yes
73   \else
74     \pack_placement_flush_grid_nop
75   \fi
76   \endgroup
77   \placementparameter\c!after
78   \egroup}
79
80\def\pack_placement_flush_grid_yes
81  {\edef\p_grid{\placementparameter\c!grid}%
82   \ifx\p_grid\empty
83     \let\p_grid\v!middle
84   \fi
85   \pack_placement_flush_grid_noindent
86   \snaptogrid[\p_grid]\hbox{\box\nextbox}}
87
88\def\pack_placement_flush_grid_nop
89  {\edef\p_linecorrection {\placementparameter\c!linecorrection}%
90   \edef\p_depthcorrection{\placementparameter\c!depthcorrection}%
91   \ifx\p_linecorrection\v!on
92     \startbaselinecorrection
93   \fi
94   \pack_placement_flush_grid_noindent
95   \box\nextbox
96   \ifx\p_depthcorrection\v!on
97     \baselinecorrection
98   \fi
99   \ifx\p_linecorrection\v!on
100     \stopbaselinecorrection
101   \fi}
102
103\def\pack_placement_flush_grid_noindent
104  {\edef\p_margin{\placementparameter\c!margin}%
105   \ifx\p_margin\v!standard
106     \noindent
107   \else\ifx\p_margin\v!yes
108     \noindent
109   \fi\fi}
110
111\protect \endinput
112
113