typo-del.mkiv /size: 29 Kb    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=typo-del, % moved from core-mis,
3%D        version=20110112,
4%D          title=\CONTEXT\ Typesetting Macros,
5%D       subtitle=Delimited Content,
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% todo: textstyle|color for inline \quotation etc
15
16\writestatus{loading}{ConTeXt Typesetting Macros / Delimited Content}
17
18\unprotect
19
20\ifdefined\dotagsetdelimitedsymbol   \else \let\dotagsetdelimitedsymbol  \gobbleoneargument \fi
21\ifdefined\dotagsetsubsentencesymbol \else \let\dotagsetsubsentencesymbol\gobbleoneargument \fi
22
23% THIS IS OBSOLETE:
24
25\installcorenamespace{hyphenmarksign} % let's not waste a setuphandler (yet)
26
27\unexpanded\def\setuphyphenmark[#1]% sign=normal|wide
28  {\getdummyparameters[#1]%
29   \expandnamespaceparameter\??hyphenmarksign\dummyparameter\c!sign\v!normal}
30
31\setvalue{\??hyphenmarksign\v!normal}%
32  {\let\textmodehyphen\normalhyphen
33   \let\textmodehyphendiscretionary\normalhyphendiscretionary}
34
35\setvalue{\??hyphenmarksign\v!wide}%
36  {\let\textmodehyphen\composedhyphen
37   \let\textmodehyphendiscretionary\composedhyphendiscretionary}
38
39\setuphyphenmark[\c!sign=\v!wide]
40
41\definesymbol[\c!lefthyphen]  [\languageparameter\c!lefthyphen]
42\definesymbol[\c!righthyphen] [\languageparameter\c!righthyphen]
43\definesymbol[\c!hyphen]      [\languageparameter\c!hyphen]
44
45\unexpanded\def\normalhyphen
46  {\hbox{\directsymbol\empty\c!hyphen}}
47
48\unexpanded\def\composedhyphen
49  {\hbox{\directsymbol\empty\c!compoundhyphen}}
50
51\unexpanded\def\normalhyphendiscretionary
52  {\discretionary
53     {\hbox{\directsymbol\empty\c!righthyphen}}
54     {\hbox{\directsymbol\empty\c!lefthyphen}}
55     {\hbox{\directsymbol\empty\c!hyphen}}}
56
57\unexpanded\def\composedhyphendiscretionary
58  {\discretionary
59     {\hbox{\directsymbol\empty\c!rightcompoundhyphen}}
60     {\hbox{\directsymbol\empty\c!leftcompoundhyphen}}
61     {\hbox{\directsymbol\empty\c!compoundhyphen}}}
62
63\let\textmodehyphen             \composedhyphen
64\let\textmodehyphendiscretionary\composedhyphendiscretionary
65
66\definesymbol[\c!leftcompoundhyphen]  [\languageparameter\c!leftcompoundhyphen]
67\definesymbol[\c!rightcompoundhyphen] [\languageparameter\c!rightcompoundhyphen]
68\definesymbol[\c!compoundhyphen]      [\languageparameter\c!compoundhyphen]
69
70% TILL HERE
71
72\setnewconstant\boundarycharactermode\plusone
73
74% old:       skip symbol skip
75% new: bound skip symbol skip bound
76
77\unexpanded\def\midboundarycharacter#1#2%
78  {\ifcase\boundarycharactermode
79   \or
80     \removeunwantedspaces
81     \wordboundary
82     \hskip\hspaceamount\currentusedlanguage{#2}%
83     \usedlanguageparameter#1%
84     \hskip\hspaceamount\currentusedlanguage{#2}%
85     \wordboundary
86     \ignorespaces
87   \or
88     \usedlanguageparameter#1%
89   \fi
90   \boundarycharactermode\plusone}
91
92% old: symbol nobreak skip
93% new: symbol nobreak skip wordboundary
94
95\unexpanded\def\leftboundarycharacter#1#2%
96  {\ifcase\boundarycharactermode
97   \or
98     \usedlanguageparameter#1%
99     \nobreak
100     \hskip\hspaceamount\currentusedlanguage{#2}% why not a kern
101     \wordboundary
102   \or
103     \usedlanguageparameter#1%
104   \fi
105   \boundarycharactermode\plusone}
106
107% old: preword         skip symbol
108% new: bound   nobreak skip symbol
109
110\unexpanded\def\rightboundarycharacter#1#2%
111  {\ifcase\boundarycharactermode
112   \or
113     \wordboundary
114     \nobreak
115     \hskip\hspaceamount\currentusedlanguage{#2}% why not a kern
116     \usedlanguageparameter#1%
117   \or
118     \usedlanguageparameter#1%
119   \fi
120   \boundarycharactermode\plusone}
121
122\definehspace [sentence]      [\zeropoint]
123\definehspace [intersentence] [.250\emwidth]
124
125\definesymbol
126  [\c!midsentence]
127  [\midboundarycharacter\c!midsentence{sentence}]
128
129\definesymbol
130  [\c!leftsentence]
131  [\leftboundarycharacter\c!leftsentence{sentence}]
132
133\definesymbol
134  [\c!rightsentence]
135  [\rightboundarycharacter\c!rightsentence{sentence}]
136
137\definesymbol
138  [\c!leftsubsentence]
139  [\leftboundarycharacter\c!leftsubsentence{sentence}]
140
141\definesymbol
142  [\c!rightsubsentence]
143  [\rightboundarycharacter\c!rightsubsentence{sentence}]
144
145\newsignal\d_typo_subsentence_signal
146\newcount \c_typo_subsentence_nesting
147
148\let\beforesubsentence\donothing
149\let\aftersubsentence \donothing
150
151% todo: make this language option
152%
153% \def\beforesubsentence{\removeunwantedspaces}
154% \def\aftersubsentence {\ignorespaces}
155
156\newconditional\c_typo_subsentence_cleanup  \settrue\c_typo_subsentence_cleanup
157
158\def\typo_subsentence_cleanup_start
159  {\ifconditional\c_typo_subsentence_cleanup
160     \expandafter\ignorespaces
161   \fi}
162
163\def\typo_subsentence_cleanup_stop
164  {\ifconditional\c_typo_subsentence_cleanup
165     \removeunwantedspaces
166   \fi}
167
168\unexpanded\def\midsentence
169  {\dostarttagged\t!subsentencesymbol\empty
170   \dotagsetsubsentencesymbol\s!middle
171   \symbol[\c!midsentence]%
172   \dostoptagged}
173
174\unexpanded\def\beginofsubsentence
175  {\beforesubsentence
176   \ifdim\lastkern=\d_typo_subsentence_signal
177     \unskip
178     \kern\hspaceamount\currentusedlanguage{intersentence}%
179   \fi
180   \global\advance\c_typo_subsentence_nesting\plusone
181   \ifnum\c_typo_subsentence_nesting=\plusone
182     \dontleavehmode
183   \fi
184   \dostarttagged\t!subsentence\empty % no chain
185   \dostarttagged\t!subsentencesymbol\empty
186   \dotagsetsubsentencesymbol\s!left
187   \symbol[\ifodd\c_typo_subsentence_nesting\c!leftsentence\else\c!leftsubsentence\fi]%
188   \dostoptagged
189   \dostarttagged\t!subsentencecontent\empty
190   \typo_subsentence_cleanup_start}
191
192\unexpanded\def\endofsubsentence % relax prevents space gobbling
193  {\typo_subsentence_cleanup_stop
194   \dostoptagged
195   \dostarttagged\t!subsentencesymbol\empty
196   \dotagsetsubsentencesymbol\s!right
197   \symbol[\ifodd\c_typo_subsentence_nesting\c!rightsentence\else\c!rightsubsentence\fi]%
198   \dostoptagged
199   \dostoptagged
200   \global\advance\c_typo_subsentence_nesting\minusone
201   \unskip
202   \kern\d_typo_subsentence_signal\relax
203   \aftersubsentence}
204
205\unexpanded\def\beginofsubsentencespacing % relax prevents space gobbling
206  {\kern\d_typo_subsentence_signal\relax}% \ignorespaces}
207
208\unexpanded\def\endofsubsentencespacing
209  {\ifdim\lastkern=\d_typo_subsentence_signal
210     \unskip
211     \hskip\hspaceamount\currentusedlanguage{intersentence}%
212     % no good, actually language dependent:
213     % \ignorespaces
214   \else
215     \unskip
216   \fi}
217
218%D \startbuffer
219%D test |<|test |<|test|>| test|>| test \par
220%D test|<|test|<|test|>|test|>|test \par
221%D test |<||<|test|>||>| test \par
222%D test \directdiscretionary{<}test\directdiscretionary{>} test \par
223%D \stopbuffer
224%D
225%D \typebuffer
226%D \getbuffer
227
228%unexpanded\def\startsubsentence{\beginofsubsentence\prewordbreak\beginofsubsentencespacing\typo_subsentence_cleanup_start}
229%unexpanded\def\stopsubsentence {\typo_subsentence_cleanup_stop\endofsubsentencespacing\prewordbreak\endofsubsentence}
230%unexpanded\def\subsentence     {\groupedcommandcs\startsubsentence\stopsubsentence}
231%unexpanded\def\midsubsentence  {\typo_subsentence_cleanup_start\prewordbreak\midsentence\prewordbreak\typo_subsentence_cleanup_stop}
232
233\unexpanded\def\startsubsentence{\beginofsubsentence\wordboundary\beginofsubsentencespacing\wordboundary\typo_subsentence_cleanup_start}
234\unexpanded\def\stopsubsentence {\typo_subsentence_cleanup_stop\wordboundary\endofsubsentencespacing\wordboundary\endofsubsentence}
235\unexpanded\def\subsentence     {\groupedcommandcs\startsubsentence\stopsubsentence}
236\unexpanded\def\midsubsentence  {\typo_subsentence_cleanup_start\wordboundary\midsentence\wordboundary\typo_subsentence_cleanup_stop}
237
238\definehspace [quotation]      [\zeropoint]
239\definehspace [interquotation] [.125em]
240
241%definehspace [quote]  [\zeropoint]
242%definehspace [speech] [\zeropoint]
243
244\definehspace [quote]  [\hspaceamount\currentusedlanguage{quotation}]
245\definehspace [speech] [\hspaceamount\currentusedlanguage{quotation}]
246
247\definesymbol
248  [\c!leftquotation]
249  [\leftboundarycharacter\c!leftquotation{quotation}]
250
251\definesymbol
252  [\c!rightquotation]
253  [\rightboundarycharacter\c!rightquotation{quotation}]
254
255\definesymbol
256  [\c!nextleftquotation]
257  [\rightboundarycharacter\c!leftquotation{quotation}]
258
259\definesymbol
260  [\c!nextrightquotation]
261  [\leftboundarycharacter\c!rightquotation{quotation}]
262
263\definesymbol
264  [\c!leftquote]
265  [\leftboundarycharacter\c!leftquote{quote}]
266
267\definesymbol
268  [\c!rightquote]
269  [\rightboundarycharacter\c!rightquote{quote}]
270
271\definesymbol
272  [\c!leftspeech]
273  [\leftboundarycharacter\c!leftspeech{speech}]
274
275\definesymbol
276  [\c!rightspeech]
277  [\rightboundarycharacter\c!rightspeech{speech}]
278
279\definesymbol
280  [\c!middlespeech]
281  [\leftboundarycharacter\c!middlespeech{speech}]
282
283\appendtoks
284    \def\quotation#1{"#1"}%
285    \def\quote    #1{'#1'}%
286\to \everysimplifycommands
287
288%D The next features was so desperately needed by Giuseppe Bilotta that he made a
289%D module for it. Since this is a typical example of core functionality, I decided
290%D to extend the low level quotation macros in such a way that a speech feature
291%D could be build on top of it. The speech opening and closing symbols are defined
292%D per language. Italian is an example of a language that has them set.
293
294\newsignal\d_typo_delimited_signal
295
296\let\currentdelimitedtext\s!unknown
297
298\installglobalmacrostack\currentdelimitedtext
299
300\let\delimitedtextlevel\!!zerocount
301
302\def\c_typo_delimited_nesting{\csname\??delimitedtextlevel\currentparentdelimitedtext\endcsname}
303
304% the \setlanguageparameter macro sets but we are ungrouped .. only used here
305%
306% \currentusedlanguage
307% \usedlanguageparameter
308
309%D The optional argument can be a language, a narrower spec, or a outer:inner language
310%D specification.
311%D
312%D \starttabulate
313%D     \NC [en]    \NC {\tttf en} \quotation[en]   {{\tttf <en=\currentlanguage>} something french} \NC \NR
314%D     \NC [fr]    \NC {\tttf en} \quotation[fr]   {{\tttf <fr=\currentlanguage>} something french} \NC \NR
315%D     \NC [fr:]   \NC {\tttf fr} \quotation[fr:]  {{\tttf <en=\currentlanguage>} something french} \NC \NR
316%D     \NC [:fr]   \NC {\tttf en} \quotation[:fr]  {{\tttf <fr=\currentlanguage>} something french} \NC \NR
317%D     \NC [fr:fr] \NC {\tttf fr} \quotation[fr:fr]{{\tttf <fr=\currentlanguage>} something french} \NC \NR
318%D     \NC [en:fr] \NC {\tttf en} \quotation[en:fr]{{\tttf <fr=\currentlanguage>} something french} \NC \NR
319%D     \NC [fr:en] \NC {\tttf fr} \quotation[fr:en]{{\tttf <en=\currentlanguage>} something french} \NC \NR
320%D \stoptabulate
321
322\let\currentdelimitedlanguage\empty
323
324\installglobalmacrostack\currentdelimitedlanguage
325
326\def\typo_delimited_set_language_nop
327  {\setusedlanguage{\delimitedtextparameter\c!language}}
328
329\def\typo_delimited_set_language_yes
330  {\doiflanguageelse\m_delimited_argument
331     \typo_delimited_set_language_yes_a
332     {\doifelseinstring:\m_delimited_argument
333        \typo_delimited_set_language_yes_b
334        \typo_delimited_set_language_nop}}
335
336\def\typo_delimited_set_language_yes_b
337  {\splitatcolon\m_delimited_argument\outerdelimitedlanguage\innerdelimitedlanguage
338   \ifx\outerdelimitedlanguage\empty
339     \typo_delimited_set_language_nop
340   \else
341     \doiflanguageelse\outerdelimitedlanguage
342       {\setusedlanguage\outerdelimitedlanguage}%
343       \typo_delimited_set_language_nop
344   \fi
345   \ifx\innerdelimitedlanguage\empty
346   \else
347     \doiflanguageelse\innerdelimitedlanguage
348       {\let\currentdelimitedlanguage\innerdelimitedlanguage}%
349       \donothing
350   \fi
351   \let\m_delimited_argument\empty}
352
353\def\typo_delimited_set_language_yes_a
354  {\let\currentdelimitedlanguage\m_delimited_argument
355   \let\m_delimited_argument\empty}
356
357\def\typo_delimited_push#1#2%
358  {\push_macro_currentdelimitedtext     % can we combine these two
359   \push_macro_currentdelimitedlanguage % the language used for hyphenation
360   \edef\currentdelimitedtext{#1}%
361   \edef\m_delimited_argument{#2}%
362   \ifx\m_delimited_argument\empty
363     \typo_delimited_set_language_nop
364   \else
365     \typo_delimited_set_language_yes
366   \fi
367   \let\currentparentdelimitedtext\currentdelimitedtext
368   \global\advance\c_typo_delimited_nesting\plusone
369   \edef\delimitedtextlevel{\number\c_typo_delimited_nesting}%
370   \normalexpanded{\chaintocurrentdelimitedtext{\currentparentdelimitedtext:\delimitedtextlevel}}%
371   \edef\currentdelimitedtext{\currentparentdelimitedtext:\delimitedtextlevel}}
372
373\def\typo_delimited_pop
374  {\global\advance\c_typo_delimited_nesting\minusone
375   \pop_macro_currentdelimitedlanguage
376   \pop_macro_currentdelimitedtext}
377
378\installcorenamespace{delimitedtext}
379\installcorenamespace{delimitedtextlevel}
380
381\installcommandhandler \??delimitedtext {delimitedtext} \??delimitedtext
382
383\appendtoks
384    \expandafter\newcount\csname\??delimitedtextlevel\currentdelimitedtext\endcsname
385    \setuevalue{\currentdelimitedtext        }{\delimitedtext[\currentdelimitedtext]}%
386    \setuevalue{\e!start\currentdelimitedtext}{\startdelimitedtext[\currentdelimitedtext]}%
387    \setuevalue{\e!stop \currentdelimitedtext}{\stopdelimitedtext}%
388\to \everydefinedelimitedtext
389
390\setupdelimitedtext
391  [\c!location=\v!margin, % \v!text \v!paragraph
392   \c!spacebefore=,
393   \c!spaceafter=\delimitedtextparameter\c!spacebefore,
394   \c!style=,
395   \c!color=,
396   \c!leftmargin=\zeropoint,
397   \c!rightmargin=\delimitedtextparameter\c!leftmargin,
398   \c!indentnext=\v!yes,
399   \c!before=,
400   \c!after=,
401   \c!left=,
402   \c!right=,
403  %\c!level=0,
404   \c!method=,
405  %\c!language=\v!local,
406   \c!repeat=\v!no]
407
408\def\typo_delimited_repeat_indeed
409  {\relax\ifcase\delimitedtextlevel\else
410     \typo_delimited_handle_middle\c!middle
411   \fi}
412
413\let\typo_delimited_repeat\relax
414
415\unexpanded\def\startdelimitedtext
416  {\dodoubleempty\typo_delimited_text_start}
417
418\unexpanded\def\typo_delimited_text_start[#1][#2]%
419  {\begingroup
420   \typo_delimited_push{#1}{#2}%
421   \dostarttaggedchained\t!delimitedblock\currentdelimitedtext\??delimitedtext
422   \edef\p_delimited_method{\delimitedtextparameter\c!method}%
423   \ifx\p_delimited_method\v!font
424     \expandafter\typo_delimited_start_font
425   \else
426     \expandafter\typo_delimited_start_other
427   \fi}
428
429\let\typo_delimited_stop\relax % hooks into \everypar
430
431\def\typo_delimited_start_font
432  {\let\typo_delimited_stop\typo_delimitedtexts_finish_font
433   \dostarttagged\t!delimitedsymbol\empty
434   \dotagsetdelimitedsymbol\s!left
435   \delimitedtextparameter\c!left
436   \dostoptagged
437   \ignorespaces}
438
439\newconditional\c_typo_delimited_repeating
440
441\def\typo_delimited_start_other
442  {\edef\p_delimited_repeat{\delimitedtextparameter\c!repeat}%
443   \ifx\p_delimited_repeat\v!yes
444     \let\typo_delimited_repeat\typo_delimited_repeat_indeed
445   \else
446     \let\typo_delimited_repeat\relax
447   \fi
448   \setfalse\c_typo_delimited_repeating
449   \edef\p_delimited_location{\delimitedtextparameter\c!location}%
450   \ifx\p_delimited_location\v!paragraph
451     \singleexpandafter\typo_delimited_start_par
452   \else\ifx\p_delimited_location\v!margin
453     \doubleexpandafter\typo_delimited_start_par
454   \else
455     \doubleexpandafter\typo_delimited_start_txt
456   \fi\fi}
457
458\def\typo_delimitedtexts_finish_font
459  {\removeunwantedspaces % again ?
460   \dostarttagged\t!delimitedsymbol\empty
461   \dotagsetdelimitedsymbol\s!right
462   \delimitedtextparameter\c!right
463   \dostoptagged}
464
465\def\typo_delimited_show_language_indeed#1#2%
466  {\begingroup
467   \infofont
468   \setbox\scratchbox\hpack{\lower\strutht\hbox to \zeropoint{\darkred#1\currentlanguage:\currentdelimitedlanguage#2}}%
469   \vsmashbox\scratchbox
470   \box\scratchbox
471   \endgroup}
472
473\let\typo_delimited_show_language\gobbletwoarguments
474
475\installtextracker{delimited.language}
476  {\let\typo_delimited_show_language\typo_delimited_show_language_indeed}
477  {\let\typo_delimited_show_language\gobbletwoarguments}
478
479\def\typo_delimited_start_content
480  {\dostarttagged\t!delimitedcontent\empty
481   \begingroup
482   \douselanguageparameter\currentdelimitedlanguage
483   \typo_delimited_show_language<\hss
484   \ignorespaces}
485
486\def\typo_delimited_stop_content
487  {\removeunwantedspaces
488   \removelastskip % redundant
489   \typo_delimited_show_language\hss<%
490   \endgroup
491   \dostoptagged}
492
493\def\typo_delimited_start_par
494  {\dosingleempty\typo_delimited_start_par_indeed}
495
496\let\typo_delimited_stop_par_indeed\endgraf
497
498\def\typo_delimited_start_par_indeed[#1]%
499  {\let\typo_delimited_stop\typo_delimited_stop_par
500   \edef\p_delimited_spacebefore{\delimitedtextparameter\c!spacebefore}%
501   \ifx\p_delimited_spacebefore\empty \else
502     \blank[\p_delimited_spacebefore]%
503   \fi
504   \delimitedtextparameter\c!before
505   \iffirstargument
506     \edef\m_delimited_argument{#1}%
507   \fi
508   \ifx\m_delimited_argument\empty
509     \let\m_delimited_argument\m_delimited_argument
510   \fi
511   \ifx\m_delimited_argument\empty
512     \endgraf
513     \doadaptleftskip {\delimitedtextparameter\c!leftmargin}%
514     \doadaptrightskip{\delimitedtextparameter\c!rightmargin}%
515     \let\typo_delimited_stop_par_indeed\endgraf
516   \else % backward compatible direct directive
517     \startnarrower[\m_delimited_argument]%
518     \let\typo_delimited_stop_par_indeed\stopnarrower
519   \fi
520   % so far
521   \push_macro_checkindentation
522   \useindentingparameter\delimitedtextparameter
523   %
524   \begingroup
525   \usedelimitedtextstyleandcolor\c!style\c!color
526   %
527   \begingroup
528   \usealignparameter\delimitedtextparameter
529   \edef\p_delimited_left     {\delimitedtextparameter\c!left}%
530   \edef\p_delimited_right    {\delimitedtextparameter\c!right}%
531   \edef\p_delimited_nextleft {\delimitedtextparameter\c!nextleft}%
532   \edef\p_delimited_nextright{\delimitedtextparameter\c!nextright}%
533   %
534   \leftdelimitedtextmark
535   %
536   \setnextleftdelimitedtextmark
537   \setnextrightdelimitedtextmark
538   %
539   \typo_delimited_start_content}
540
541\def\typo_delimited_stop_par
542  {\typo_delimited_stop_content
543   \rightdelimitedtextmark
544   \rightdelimitedtextmark
545   \carryoverpar\endgroup
546   \endgraf
547   \endgroup
548   \pop_macro_checkindentation
549   \typo_delimited_stop_par_indeed
550   \delimitedtextparameter\c!after
551   \edef\p_delimited_spaceafter{\delimitedtextparameter\c!spaceafter}%
552   \ifx\p_delimited_spaceafter\empty \else
553     \blank[\p_delimited_spaceafter]%
554   \fi
555   \useindentnextparameter\delimitedtextparameter
556   \aftergroup\dorechecknextindentation}% AM: This was missing!
557
558\def\typo_delimited_start_txt
559  {\let\typo_delimited_stop\typo_delimited_stop_txt
560   \begingroup
561   \usedelimitedtextstyleandcolor\c!style\c!color
562   \typo_delimited_handle_left\c!left
563   \typo_delimited_start_content}
564
565\def\typo_delimited_stop_txt
566  {\typo_delimited_stop_content
567   \typo_delimited_handle_right\c!right
568   \endgroup}
569
570\unexpanded\def\stopdelimitedtext
571  {\typo_delimited_stop
572   \dostoptagged
573   \typo_delimited_pop
574   \endgroup}
575
576\unexpanded\def\delimitedtext
577  {\dodoubleempty\typo_delimited_text}
578
579\unexpanded\def\typo_delimited_text[#1][#2]%
580  {\dontleavehmode % following ones can be omited
581   \typo_delimited_push{#1}{#2}%
582   \edef\p_delimited_method{\delimitedtextparameter\c!method}%
583   \ifx\p_delimited_method\v!font
584     \expandafter\typo_delimited_fontdriven
585   \else
586     \expandafter\typo_delimited_other
587   \fi}
588
589\def\typo_delimited_other
590  {\edef\p_delimited_location{\delimitedtextparameter\c!location}%
591   \ifx\p_delimited_location\v!paragraph
592     \singleexpandafter\typo_delimited_par
593   \else\ifx\p_delimited_location\v!margin
594     \doubleexpandafter\typo_delimited_par
595   \else
596     \doubleexpandafter\typo_delimited_txt
597   \fi\fi}
598
599% shortcuts
600
601\unexpanded\def\startdelimited{\startdelimitedtext}
602\unexpanded\def\stopdelimited {\stopdelimitedtext}  % no let, dynamically assigned
603           \def\delimited     {\delimitedtext}
604
605% todo: \dostarttagged\t!nothing\empty % for left/right boxes
606
607%D We have 4 different location and symbol handlers (two pairs):
608%D
609%D \starttyping
610%D \input tufte \startquotation \input tufte \stopquotation
611%D
612%D \setupdelimitedtext
613%D   [quotation]
614%D   [nextleft=right,
615%D    nextright=left]
616%D
617%D \input tufte \startquotation \input tufte \stopquotation
618%D
619%D \setupdelimitedtext
620%D   [quotation]
621%D   [nextleft={\symbol[nextleftquotation]},
622%D    nextright={\symbol[nextrightquotation]}]
623%D
624%D \input tufte \startquotation \input tufte \stopquotation
625%D \stoptyping
626
627\unexpanded\def\setnextleftdelimitedtextmark
628  {\ifx\p_delimited_nextleft\empty
629      % nothing
630   \else\ifx\p_delimited_nextleft\v!left
631     \typo_delimited_nextleft_symbol\p_delimited_left
632   \else\ifx\p_delimited_nextleft\v!right
633     \typo_delimited_nextleft_symbol\p_delimited_right
634   \else
635     \typo_delimited_nextleft_symbol\p_delimited_nextleft
636   \fi\fi\fi}
637
638\unexpanded\def\setnextrightdelimitedtextmark
639  {\ifx\p_delimited_nextright\empty
640      % nothing
641   \else\ifx\p_delimited_nextright\v!right
642     \typo_delimited_nextright_symbol\p_delimited_right
643   \else\ifx\p_delimited_nextright\v!left
644     \typo_delimited_nextright_symbol\p_delimited_left
645   \else
646     \typo_delimited_nextright_symbol\p_delimited_nextright
647   \fi\fi\fi}
648
649\unexpanded\def\leftdelimitedtextmark
650  {\ifx\p_delimited_left\empty
651      % nothing
652   \else
653     \typo_delimited_left_symbol\p_delimited_left
654   \fi}
655
656\unexpanded\def\rightdelimitedtextmark
657  {\ifx\p_delimited_right\empty
658      % nothing
659   \else
660      \typo_delimited_right_symbol\p_delimited_right
661   \fi}
662
663\def\typo_delimited_left_symbol#1%
664  {\dostarttagged\t!delimitedsymbol\empty
665   \dotagsetdelimitedsymbol\s!left
666   \setbox\scratchbox\hbox{\usedelimitedtextstyleandcolor\c!symstyle\c!symcolor#1}%
667   \dontleavehmode
668   \edef\p_delimited_margin{\delimitedtextparameter\c!location}%
669   \ifx\p_delimited_margin\v!margin
670      \hskip-\wd\scratchbox
671   \fi
672   \box\scratchbox
673   \dostoptagged}
674
675\def\typo_delimited_right_symbol#1%
676  {\dostarttagged\t!delimitedsymbol\empty
677   \dotagsetdelimitedsymbol\s!right
678   \hsmash{\usedelimitedtextstyleandcolor\c!symstyle\c!symcolor#1}%
679   \dostoptagged}
680
681\def\typo_delimited_nextleft_symbol#1%
682  {\let\typo_delimited_reset_next_symbol\typo_delimited_reset_next_symbol_indeed
683   \localleftbox\bgroup
684     \swapmacros\leftboundarycharacter\rightboundarycharacter
685     \boundarycharactermode\plusone
686     \typo_delimited_left_symbol#1%
687   \egroup}
688
689\def\typo_delimited_nextright_symbol#1%
690  {\let\typo_delimited_reset_next_symbol\typo_delimited_reset_next_symbol_indeed
691   \localrightbox\bgroup
692     \swapmacros\leftboundarycharacter\rightboundarycharacter
693     \boundarycharactermode\plusone
694     \typo_delimited_right_symbol#1%
695   \egroup}
696
697\unexpanded\def\typo_delimited_reset_next_symbol_indeed
698  {\localleftbox {}%
699   \localrightbox{}}%
700
701\let\typo_delimited_reset_next_symbol\relax
702
703\appendtoks
704    \typo_delimited_reset_next_symbol
705\to \everyforgetall
706
707% \starttext
708%    \hyphenatedword{groepsvrijstellingsverordeningen}\par
709%    \hyphenatedword{\quote{groepsvrijstellingsverordeningen}}\par
710%     \dorecurse{100}{\hskip300pt\hskip\recurselevel pt test \quote{xxx xxxx}.\par}
711%     \page \setuppapersize[A5][A4]
712%     \quotation {overly beautiful pusillanimous sesquipedalian
713%     longwinded} test test test test test test test test test test test
714%     test test test test test test test test test test test test test
715%     test test test test test test test test test test test test test
716%     test test test test test test test test test test test test test
717%     test test test
718% \stoptext
719
720% We have no real test case for this and it's broken already for a while,
721% even in \MKII. Maybe we should to this in \LUA. Only Italian has the
722% middlespeech parameter set.
723
724\def\typo_delimited_handle_middle#1% special case
725  {\ifconditional\c_typo_delimited_repeating
726     \begingroup
727     \usedelimitedtextstyleandcolor\c!symstyle\c!symcolor
728     \setbox\scratchbox\hbox{\delimitedtextparameter#1}%
729     \ifdim\wd\scratchbox>\zeropoint
730       \ifdim\lastkern=\d_typo_delimited_signal
731         \unkern
732         \hskip\hspaceamount\currentusedlanguage{interquotation}%
733       \else % maybe an option:
734        %\edef\p_delimited_margin{\delimitedtextparameter\c!location}%
735        %\ifx\p_delimited_margin\v!margin
736        %   \hskip-\wd\scratchbox
737        %\fi
738       \fi
739       \strut % new, needed below
740       \dostarttagged\t!delimitedsymbol\empty
741       \dotagsetdelimitedsymbol\s!middle
742       \delimitedtextparameter#1% unhbox\scratchbox
743       \dostoptagged
744     % \penalty\plustenthousand % else overfull boxes, but that's better than dangling periods
745       \kern\d_typo_delimited_signal % +- \prewordbreak
746     \fi
747     \endgroup
748   \else
749     \settrue\c_typo_delimited_repeating
750   \fi}
751
752\def\typo_delimited_handle_left#1%
753  {\begingroup
754   \usedelimitedtextstyleandcolor\c!symstyle\c!symcolor
755   \setbox\scratchbox\hbox{\delimitedtextparameter#1}%
756   \ifdim\wd\scratchbox>\zeropoint
757     \ifdim\lastkern=\d_typo_delimited_signal
758       \unkern
759       \hskip\hspaceamount\currentusedlanguage{interquotation}%
760     \else\ifdim\lastskip=\d_typo_delimited_signal
761       \unskip
762       \hskip\hspaceamount\currentusedlanguage{interquotation}%
763     \fi\fi
764   % \strut % new, needed below
765   % \ifhmode % else funny pagebeaks
766   %   \penalty\plustenthousand
767   %   \hskip\zeropoint % == \prewordbreak
768   % \fi
769     \strut % new, needed below
770     \dostarttagged\t!delimitedsymbol\empty
771     \dotagsetdelimitedsymbol\s!left
772     \delimitedtextparameter#1% unhbox\scratchbox
773     \dostoptagged
774     \penalty\plustenthousand % new per 2013-03-09 WS mailing list
775     \hskip\d_typo_delimited_signal % +- \prewordbreak
776   \fi
777   \endgroup}
778
779\def\typo_delimited_handle_right#1%
780  {\begingroup
781   \usedelimitedtextstyleandcolor\c!symstyle\c!symcolor
782   \setbox\scratchbox\hbox{\delimitedtextparameter#1}%
783   \ifdim\wd\scratchbox>\zeropoint
784     \ifdim\lastkern=\d_typo_delimited_signal
785       \unkern
786       \penalty\plustenthousand
787       \hskip\hspaceamount\currentusedlanguage{interquotation}%
788     \else\ifdim\lastskip=\d_typo_delimited_signal
789       \unskip
790       \penalty\plustenthousand
791       \hskip\hspaceamount\currentusedlanguage{interquotation}%
792     \fi\fi
793     \ifhmode % else funny pagebeaks
794       \penalty\plustenthousand
795       \hskip\zeropoint % == \prewordbreak
796     \fi
797     \strut % new, needed below
798     \dostarttagged\t!delimitedsymbol\empty
799     \dotagsetdelimitedsymbol\s!right
800     \delimitedtextparameter#1% unhbox\scratchbox
801     \dostoptagged
802     \kern\d_typo_delimited_signal % +- \prewordbreak
803   \fi
804   \endgroup}
805
806\unexpanded\def\typo_delimited_par
807  {\groupedcommand
808     {\dostarttaggedchained\t!delimited\currentdelimitedtext\??delimitedtext % block?
809      \usedelimitedtextstyleandcolor\c!style\c!color
810      \typo_delimited_handle_left\c!left
811      \typo_delimited_start_content}
812     {\typo_delimited_stop_content
813      \typo_delimited_handle_right\c!right
814      \removelastskip % hm
815      \dostoptagged
816      \typo_delimited_pop}}
817
818\unexpanded\def\typo_delimited_txt
819  {\edef\p_left_right{\delimitedtextparameter\c!left\delimitedtextparameter\c!right}%
820   \ifx\p_left_right\empty
821     \expandafter\typo_delimited_attributed
822   \else
823     \expandafter\typo_delimited_quoted
824   \fi}
825
826\def\typo_delimited_quoted
827  {\dontleavehmode
828   \begingroup
829   \dostarttaggedchained\t!delimited\currentdelimitedtext\??delimitedtext
830   \typo_delimited_handle_left\c!left
831   \usedelimitedtextstyleandcolor\c!style\c!color
832   \typo_delimited_start_content
833   \bgroup
834   \aftergroup\typo_delimited_quoted_e
835   \let\next=}
836
837\def\typo_delimited_quoted_e
838  {\typo_delimited_stop_content
839   \typo_delimited_handle_right\c!right
840   \removelastskip % ?
841   \dostoptagged
842   \typo_delimited_pop
843   \endgroup}
844
845\def\typo_delimited_attributed
846  {\dontleavehmode
847   \begingroup
848   \dostarttaggedchained\t!delimited\currentdelimitedtext\??delimitedtext
849   \usedelimitedtextstyleandcolor\c!style\c!color
850   \typo_delimited_start_content
851   \bgroup
852   \aftergroup\typo_delimited_attributed_e
853   \let\next=}
854
855\def\typo_delimited_attributed_e
856  {\typo_delimited_stop_content
857   \dostoptagged
858   \typo_delimited_pop
859   \endgroup}
860
861\def\typo_delimited_fontdriven
862  {\dontleavehmode
863   \begingroup
864   \dostarttaggedchained\t!delimited\currentdelimitedtext\??delimitedtext
865   \usedlanguageparameter{\c!left\currentparentdelimitedtext}% was: \currentdelimitedtext
866   \usedelimitedtextstyleandcolor\c!style\c!color
867   \typo_delimited_start_content
868   \bgroup
869   \aftergroup\typo_delimited_fontdriven_e
870   \let\next=}
871
872\def\typo_delimited_fontdriven_e
873  {\typo_delimited_stop_content
874   \usedlanguageparameter{\c!right\currentparentdelimitedtext}% was: \currentdelimitedtext
875   \dostoptagged
876   \typo_delimited_pop
877   \endgroup}
878
879% testcase for nesting:
880%
881% \quotation{... \quotation{...} ...}
882% \startquotation ... \startquotation... \quotation{...} \stopquotation\space ...\stopquotation
883% \setupdelimitedtext[quotation][1][left=(,right=)]
884% \setupdelimitedtext[quotation][2][left={[},right={]}]
885% \setupdelimitedtext[quotation][3][left=\{,right=\}]
886% \quotation{... \quotation{...} ...}
887% \startquotation ... \startquotation... \quotation{...} \stopquotation\space ...\stopquotation
888
889\definedelimitedtext
890  [\v!quotation]
891  [\c!left={\symbol[\c!leftquotation]},
892   \c!right={\symbol[\c!rightquotation]},
893   \c!leftmargin=\v!standard]
894
895\definedelimitedtext
896  [\v!quote][\v!quotation]
897
898\setupdelimitedtext
899  [\v!quote]
900  [\c!location=\v!text,
901   \c!left={\symbol[\c!leftquote]},
902   \c!right={\symbol[\c!rightquote]}]
903
904\definedelimitedtext
905   [\v!blockquote][\v!quotation]
906
907\setupdelimitedtext
908  [\v!blockquote]
909  [\c!left=,
910   \c!right=]
911
912\definedelimitedtext
913  [\v!speech][\v!quotation]
914
915\setupdelimitedtext
916  [\v!speech]
917  [\c!repeat=\v!yes,
918   \c!left={\symbol[\c!leftspeech]},
919   \c!middle={\symbol[\c!middlespeech]},
920   \c!right={\symbol[\c!rightspeech]}]
921
922\definedelimitedtext
923  [\v!aside]
924  [\c!left={\symbol[\c!leftsentence]},
925   \c!right={\symbol[\c!rightsentence]}]
926
927% how do we call an tight quote
928%
929% \definedelimitedtext
930%    [\v!quotation][\v!quotation]
931%
932% \setupdelimitedtext
933%   [\v!quotation]
934%   [\c!indentnext=\v!no,
935%    \c!spacebefore=\v!nowhite]
936
937\unexpanded\def\setupquotation{\setupdelimitedtext[\v!quotation]}
938\unexpanded\def\setupquote    {\setupdelimitedtext[\v!quote]}
939
940\protect \endinput
941