summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/node-par.mkiv
blob: 2e9efde1f3c8dccb640d8bae042419ee2d6be4be (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
%D \module
%D   [       file=node-par,
%D        version=2008.09.30,
%D          title=\CONTEXT\ Node Macros,
%D       subtitle=Paragraph Building,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%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 Node Macros / Paragraph Building}

%D This is very experimental, undocumented, subjected to changes, etc. just as
%D the underlying interfaces.

% \enableparbuilders
%
% \startparbuilder[default]
%     \input tufte \par
%     \startparbuilder[oneline]
%         \input tufte \par
%     \stopparbuilder
%     \input tufte \par
% \stopparbuilder

\unprotect

\registerctxluafile{node-par}{1.001}

\definesystemattribute[parbuilder][public]

% todo auto-enable

% management (enable/disable) is global and will move to lua

\newcount\nofparbuilders

\unexpanded\def\defineparbuilder[#1]%
  {\global\advance\nofparbuilders\plusone
   \ctxlua{builders.paragraphs.constructors.register("#1",\number\nofparbuilders)}%
   \setxvalue{\??ng:#1}{\attribute\parbuilderattribute\nofparbuilders}}

\unexpanded\def\startparbuilder[#1]%
  {\edef\@@currentparbuilder{\number\attribute\parbuilderattribute}%
   \globalpushmacro\@@currentparbuilder
   \getvalue{\??ng:#1}%
   \checkparbuilders}

\unexpanded\def\stopparbuilder
  {\ifhmode\par\fi
   \globalpopmacro\@@currentparbuilder
   \attribute\parbuilderattribute\@@currentparbuilder\relax
   \checkparbuilders}

\def\setmainparbuilder[#1]%
  {\ctxlua{builders.paragraphs.constructors.set("#1")}}

% no high level interface, after all implementing a linebreaker is not something that
% the average user will do

\defineparbuilder[default] % just for testing
\defineparbuilder[oneline] % just for testing
\defineparbuilder[basic]   % just for testing

\def\enableparbuilders {\ctxlua{builders.paragraphs.constructors.enable ()}}
\def\disableparbuilders{\ctxlua{builders.paragraphs.constructors.disable()}}

\def\checkparbuilders % can be more efficient as we don't want to do this to often
  {\ifcase\attribute\parbuilderattribute
     \disableparbuilders
   \else
     \enableparbuilders
   \fi}

\protect \endinput