typo-syn.mkxl /size: 7021 b    last modification: 2024-01-16 10:22
1%D \module
2%D   [       file=typo-syn,
3%D        version=2022.01.06,
4%D          title=\CONTEXT\ Typesetting Macros,
5%D       subtitle=synchronizers,
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% Musical timestamp: this code was written when I start relistening my whole
15% digitized cd collection with the (new) r2r soekris dac in my setup.
16
17\writestatus{loading}{ConTeXt Typesetting Macros / Synchronizers}
18
19\registerctxluafile{typo-syn}{autosuffix}
20
21%D Yet another experiment (triggered by a question / demand from Ton Otten.)
22%D
23%D \starttyping
24%D \setupsynchronize [paralleltext] [color=darkblue]
25%D % \setupsynchronize [paralleltext] [style=\tx,color=darkred]
26%D % \setupsynchronize [paralleltext] [style=\txx,color=darkgreen]
27%D
28%D \dorecurse{10}{%
29%D     \paralleltext
30%D         {[een allereerste zinnetje]}
31%D         {[een tweede      zinnetje]}%
32%D     \space
33%D     \paralleltext
34%D         {[een derde zin]}
35%D         {[een vierde zinnetje]}
36%D     \space
37%D } \removeunwantedspaces
38%D \par test line \page
39%D
40%D \paralleltext
41%D     {[\ignorespaces\samplefile{tufte}\removeunwantedspaces]}
42%D     {[\samplefile{ward}\removeunwantedspaces]}%
43%D \par test line \page
44%D
45%D \paralleltext
46%D     {[\ignorespaces\samplefile{tufte}\removeunwantedspaces]}
47%D     {[\ignorespaces\samplefile{tufte}\removeunwantedspaces]}%
48%D \par test line \page
49%D
50%D \paralleltext
51%D     {[\ignorespaces\samplefile{ward}\removeunwantedspaces]}%
52%D     {[\ignorespaces\samplefile{tufte}\removeunwantedspaces]}
53%D \par test line \page
54%D
55%D \startbuffer[en]
56%D     This is an english text and
57%D     this is also something english;
58%D     as is this.
59%D     Not that there is much meaning in it.
60%D \stopbuffer
61%D
62%D \startbuffer[nl]
63%D     Dit is een nederlandse tekst
64%D     en dit is ook wat nederlands;
65%D     net als dit.
66%D     Niet dat het veel te betekenen heeft.
67%D \stopbuffer
68%D
69%D \definesynchronizecontent
70%D   [nl]
71%D   [language=nl,
72%D    color=darkred]
73%D
74%D \definesynchronizecontent
75%D   [en]
76%D   [language=en,
77%D    color=darkgreen]
78%D
79%D \definesynchronize
80%D   [parallel-en-nl]
81%D   [list={en,nl}]
82%D
83%D \placesynchronize
84%D   [parallel-en-nl]
85%D   [buffer={en,nl}]
86%D
87%D \blank
88%D
89%D \placesynchronize
90%D   [parallel-en-nl]
91%D   [split={.},
92%D    text={
93%D     {This is an english text and this is also something english; as is this. Not that there is much meaning in it.},
94%D     {Dit is een nederlandse tekst en dit is ook wat nederlands; net als dit. Niet dat het veel te betekenen heeft.}
95%D    }]
96%D
97%D \blank
98%D
99%D \placesynchronize
100%D   [parallel-en-nl]
101%D   [split={.},
102%D    text={
103%D     {
104%D         {This is an english text and this is also something english;},
105%D         {as is this.},
106%D         {Not that there is much meaning in it.}
107%D     },
108%D     {
109%D         {Dit is een nederlandse tekst en dit is ook wat nederlands;},
110%D         {net als dit.},
111%D         {Niet dat het veel te betekenen heeft.}
112%D     }
113%D    }]
114%D
115%D \setupsynchronizecontent
116%D   [nl]
117%D   [language=nl,
118%D    style=\tx,
119%D    left={[},
120%D    right={]},
121%D    color=darkblue]
122%D
123%D \placesynchronize
124%D   [parallel-en-nl]
125%D   [distance=1pt,
126%D    buffer={en,nl}]
127%D \stoptyping
128
129\unprotect
130
131\definesystemattribute[synchronize][public]
132
133\installcorenamespace {synchronize}
134\installcorenamespace {synchronizecontent}
135
136\installcommandhandler \??synchronize        {synchronize}        \??synchronize
137\installcommandhandler \??synchronizecontent {synchronizecontent} \??synchronizecontent
138
139\setupsynchronize
140  [\c!buffer=,
141   \c!text=,
142   \c!list=,
143   \c!split=,
144   \c!distance=\zeropoint]
145
146\let\typo_sync_rule\novrule
147
148\installtextracker
149  {synchronize}
150  {\let\typo_sync_rule\vrule}
151  {\let\typo_sync_rule\novrule}
152
153\tolerant\protected\def\typo_synchronize#1#*[#S#2]#:#3#4%
154  {\dontleavehmode
155   \begingroup
156   \cdef\currentsynchronize{#1}%
157   \setupcurrentsynchronize[#2]%
158   \scratchdistance\synchronizeparameter\c!distance
159   \dontcomplain
160   \setbox\scratchboxtwo\hbox\bgroup
161     \usesynchronizestyleandcolor\c!style\c!color
162     \begstrut
163     \ignorespaces#4\removeunwantedspaces
164     \endstrut
165   \egroup
166   \scratchdimentwo\wd\scratchboxtwo
167   \advanceby\scratchdimentwo\scratchdistance
168   \clf_registersynchronize
169     \strutht
170     \strutdp
171     .1\onepoint
172     \box\scratchboxtwo
173   \relax
174   \setbox\scratchboxone\hbox\bgroup
175     \ignorespaces#3\removeunwantedspaces
176   \egroup
177   \scratchdimenone\wd\scratchboxone
178   \unhbox\scratchboxone
179   \advanceby\scratchdimentwo-\scratchdimenone
180   \ifdim\scratchdimentwo>\zeropoint
181     \wordboundary
182     \typo_sync_rule
183        \s!width  \scratchdimentwo
184        \s!height \exheight
185        \s!depth  \zeropoint
186     \relax
187   \fi
188   \endgroup}
189
190\protected\def\dosplitsynchronize#1#2#3#4%
191  {\begingroup
192   \dontcomplain
193   \setbox\scratchboxtwo\hbox\bgroup
194     \def\currentsynchronizecontent{#2}%
195     \usesynchronizecontentstyleandcolor\c!style\c!color
196     \uselanguageparameter\synchronizecontentparameter
197     \synchronizecontentparameter\c!left
198     \begstrut
199     \ignorespaces
200     #4\removeunwantedspaces
201     \endstrut
202     \synchronizecontentparameter\c!right
203   \egroup
204   \scratchdimentwo\wd\scratchboxtwo
205   \advanceby\scratchdimentwo\scratchdistance
206   \clf_registersynchronize
207     \strutht
208     \strutdp
209     .1\onepoint
210     \box\scratchboxtwo
211   \relax
212   \setbox\scratchboxone\hbox\bgroup
213     \def\currentsynchronizecontent{#1}%
214     \usesynchronizecontentstyleandcolor\c!style\c!color
215     \uselanguageparameter\synchronizecontentparameter
216     \synchronizecontentparameter\c!left
217     \ignorespaces#3\removeunwantedspaces
218     \synchronizecontentparameter\c!right
219   \egroup
220   \scratchdimenone\wd\scratchboxone
221   \unhbox\scratchboxone
222   \advanceby\scratchdimentwo-\scratchdimenone
223   \ifdim\scratchdimentwo>\zeropoint
224     \wordboundary
225     \typo_sync_rule
226        \s!width  \scratchdimentwo
227        \s!height \exheight
228        \s!depth  \zeropoint
229     \relax
230   \fi
231   \endgroup
232   \space}
233
234\tolerant\protected\def\placesynchronize[#1]#*[#S#2]%
235  {\dontleavehmode
236   \begingroup
237   \cdef\currentsynchronize{#1}%
238   \setupcurrentsynchronize[#2]%
239   \scratchdistance\synchronizeparameter\c!distance
240   \clf_synchronizesteps
241      list   {\synchronizeparameter\c!list}%
242      split  {\synchronizeparameter\c!split}%
243      buffer {\synchronizeparameter\c!buffer}%
244      text   {\synchronizeparameter\c!text}%
245   \relax
246   \removeunwantedspaces
247   \endgroup}
248
249\appendtoks
250    \protected\instance\edefcsname\currentsynchronize\endcsname{\typo_synchronize{\currentsynchronize}}%
251\to \everydefinesynchronize
252
253% \setupsynchronize
254%   [\c!alternative=\v!horizontal]
255
256\definesynchronize
257  [paralleltext]
258
259% defined in lua: \hsplit to upto width height depth criterium shrinkcriterium stretchcriterium
260
261\protect \endinput
262