summaryrefslogtreecommitdiff
path: root/tex/context/base/attr-eff.mkiv
blob: c788933075bcfa6ce5bfa3144875456a6d086917 (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
%D \module
%D   [       file=attr-eff,
%D        version=2007.06.06,
%D          title=\CONTEXT\ Attribute Macros,
%D       subtitle=Effects,
%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 Attribute Macros / Effects}

\registerctxluafile{attr-eff}{1.001}

\unprotect

% \def\registereffect#1#2#3% #2=stretch #3=rulethickness
%   {\setxvalue{(es:#1:#2:\number\dimexpr#3\relax)}% todo: set attribute at lua end
%      {\attribute\effectattribute\ctxcommand{registereffect('#1',#2,\number\dimexpr#3\relax)}\relax}}
%
% \def\dotriggereffect
%   {\ctxcommand{enableeffect()}% can then move to caller
%    \gdef\dotriggereffect##1##2##3%
%      {\ifcsname(es:##1:##2:\number\dimexpr##3\relax)\endcsname\else\registereffect{##1}{##2}{##3}\fi
%       \csname(es:##1:##2:\number\dimexpr##3\relax)\endcsname}%
%    \dotriggereffect}
%
% \def\registereffect#1#2#3% #2=stretch #3=rulethickness
%   {\setxvalue{(es:#1:#2:\number\dimexpr#3\relax)}% todo: set attribute at lua end
%      {\attribute\effectattribute\ctxcommand{registereffect('#1',#2,\number\dimexpr#3\relax)}\relax}}

\gdef\dotriggereffect#1#2#3%
  {\ctxcommand{triggereffect('#1',#2,\number\dimexpr#3\relax)}}

\unexpanded\def\setupeffect
  {\dodoubleargument\dosetupeffect}

\def\dosetupeffect[#1][#2]%
  {\getparameters[\??et#1][#2]}

\unexpanded\def\defineeffect
  {\dodoubleargument\dodefineeffect}

\def\dodefineeffect[#1][#2]%
  {\getparameters[\??et#1][\c!method=\v!none,\c!stretch=0,\c!rulethickness=\zeropoint,\c!alternative=\v!normal,#2]%
   \doif{\getvalue{\??et#1\c!method}}\v!command
     {\setugvalue{\e!start#1}{\starteffect[#1]}%
      \setugvalue{\e!stop #1}{\stopeffect}}}

% yes or no grouped

\unexpanded\def\starteffect[#1]%
  {\dotriggereffect
     {\csname\??et#1\c!alternative  \endcsname}%
     {\csname\??et#1\c!stretch      \endcsname}%
     {\csname\??et#1\c!rulethickness\endcsname}}

\unexpanded\def\stopeffect % can be special
  {\dotriggereffect\v!normal0\zeropoint}

\unexpanded\def\effect[#1]%
  {\groupedcommand{\starteffect[#1]}{\stopeffect}}

\defineeffect [\v!inner]   [\c!alternative=\v!inner,\c!rulethickness=.25pt]
\defineeffect [\v!outer]   [\c!alternative=\v!outer,\c!rulethickness=.25pt]
\defineeffect [\v!both]    [\c!alternative=\v!both, \c!rulethickness=.25pt]
\defineeffect [\v!normal]  [\c!alternative=\v!normal]
\defineeffect [\v!hidden]  [\c!alternative=\v!hidden]
\defineeffect [\v!stretch] [\c!alternative=\v!stretch,\c!stretch=1]

\protect \endinput