summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkiv/pack-mis.mkvi
blob: 420f9440a2f00a000662e733189b61fb69014e8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
%D \module
%D   [       file=pack-mis, % moved from e.g. core-mis
%D        version=1998.01.29,
%D          title=\CONTEXT\ Core Macros,
%D       subtitle=Miscelaneous,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Packing Macros / Misc Commands}

\unprotect

% a quite old mechanism already (but inheritance added)
%
% \defineplacement[name][settings]
% \setupplacement [name][settings]
% \placement      [name][settings]
% \place<name>          [settings]

\installcorenamespace{placement}

\installcommandhandler \??placement {placement} \??placement

\appendtoks
   \setuevalue{\e!place\currentplacement}{\pack_placement{\currentplacement}}%
\to \everydefineplacement

\setupplacement
  [\c!left=\hss,
   \c!right=\hss,
   \c!linecorrection=\v!off,
   \c!depthcorrection=\v!off,
   \c!grid=\v!middle,
  %\c!before=,
  %\c!after=,
   \c!margin=\v!standard]

\unexpanded\def\placement[#tag]%
  {\pack_placement{#tag}}

\unexpanded\def\pack_placement#tag%
  {\bgroup
   \edef\currentplacement{#tag}%
   \doifelsenextoptionalcs\pack_placement_yes\pack_placement_nop}

\def\pack_placement_yes[#settings]%
  {\setupcurrentplacement[#settings]%
   \pack_placement_nop}

\def\pack_placement_nop
  {\dowithnextboxcontentcs\forgetall\pack_placement_flush\vbox}

\def\pack_placement_flush
  {\setlocalhsize
   \placementparameter\c!before
   \begingroup
   \disableparpositions
   \setbox\nextbox\hbox to \localhsize
     {\placementparameter\c!left
      \flushnextbox
      \placementparameter\c!right}%
  %\ifinsidefloat \else
  %  \page_backgrounds_add_local_to_box\nextbox
  %\fi
\flushnotes % new per 2014-05-29 : todo: move them up in the mvl
   \ifgridsnapping
     \pack_placement_flush_grid_yes
   \else
     \pack_placement_flush_grid_nop
   \fi
   \endgroup
   \placementparameter\c!after
   \egroup}

\def\pack_placement_flush_grid_yes
  {\edef\p_grid{\placementparameter\c!grid}%
   \ifx\p_grid\empty
     \let\p_grid\v!middle
   \fi
   \pack_placement_flush_grid_noindent
   \snaptogrid[\p_grid]\hbox{\box\nextbox}}

\def\pack_placement_flush_grid_nop
  {\edef\p_linecorrection {\placementparameter\c!linecorrection}%
   \edef\p_depthcorrection{\placementparameter\c!depthcorrection}%
   \ifx\p_linecorrection\v!on
     \startbaselinecorrection
   \fi
   \pack_placement_flush_grid_noindent
   \box\nextbox
   \ifx\p_depthcorrection\v!on
     \baselinecorrection
   \fi
   \ifx\p_linecorrection\v!on
     \stopbaselinecorrection
   \fi}

\def\pack_placement_flush_grid_noindent
  {\edef\p_margin{\placementparameter\c!margin}%
   \ifx\p_margin\v!standard
     \noindent
   \else\ifx\p_margin\v!yes
     \noindent
   \fi\fi}

\protect \endinput