s-tugboat-columns.mkxl /size: 19 Kb    last modification: 2024-01-16 10:22
1%D \module
2%D   [      file=s-tugboat-columns,
3%D        version=2023-08-10,
4%D          title=\CONTEXT\ Style File,
5%D       subtitle=\TUGBOAT\ base style,
6%D         author={Hans Hagen and others},
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9
10\startmodule[tugboat-columns]
11
12% \startmode[columns]
13%     \widowpenalty        0
14%     \clubpenalty         0
15% %    \hyphenpenalty       0
16% %     \finalhyphendemerits 0
17% %     \doublehyphendemerits0
18% \stopmode
19%
20% \startnotmode[columns]
21%     \widowpenalty        100000
22%     \clubpenalty         100000
23% %     \finalhyphendemerits 100000
24% %     \doublehyphendemerits100000
25% \stopnotmode
26
27% \enablemode[columns]
28
29% \startsetups columns:figure:before
30%     \startlinecorrection[blank]
31% \stopsetups
32%
33% \startsetups columns:figure:after
34%     \stoplinecorrection
35% \stopsetups
36
37%D This file is derived t-tugboat by Aditya Mahajan which in turn is derived from
38%D older files. As Mikael and I work on and experiment with math, par building, page
39%D building, etc.\ we decided to look (again) into the \TUGBOAT\ style, also because
40%D write articles for it. We use page columns because with a few tricks we don't
41%D need to adapt the source too much; we prefer single columns and that shows.
42
43\enablemode[tugboat]
44
45%D Karl wants:
46
47\enabletrackers[builders.hpack.quality]
48\enabletrackers[builders.hpack.collect]
49\enabletrackers[builders.hpack.overflow]
50
51%D We store the information about the article in variables. We can pick up some from
52%D \type {rugboat.dates} once I know which ones.
53
54\setvariables
55  [tugboat]
56  [type=article,
57   %
58   year=1900,
59   volume=0,
60   number=0,
61   page=1001,
62   %
63   title=ConTeXt style for TUGboat,
64   subtitle=,
65   keywords=,
66   author=T. Boat,
67   address={Harbour Master KB \\ Harbour St. 1 \\ 8061XX Hasselt NL},
68   email={tugboat@tug.org}]
69
70%D \TUGBOAT\ uses slightly different interline space than the default. So we change
71%D the interline space. Keep in mind that the engine does not really have a concept
72%D of lines beyond baseline skip that interacts with the previous depth and current
73%D height. There's a lot of attention to spacing in \CONTEXT\ so don't mess it up
74%D with vertical skips and such, use \type {\blank} instead.
75
76\definebodyfontenvironment    [8pt] [interlinespace=9.5pt, big=9pt,   small=7pt]
77\definebodyfontenvironment    [9pt] [interlinespace=11pt,  big=10pt,  small=8pt]
78\definebodyfontenvironment   [10pt] [interlinespace=12pt,  big=12pt,  small=9pt]
79\definebodyfontenvironment   [12pt] [interlinespace=14pt,  big=14.4pt,small=10pt]
80\definebodyfontenvironment [14.4pt] [interlinespace=18pt,  big=14.4pt,small=12pt]
81
82%D We use italic rather than slanted for emphasis.
83
84\setupbodyfontenvironment
85  [default]
86  [em=italic]
87
88%D \TUGBOAT\ uses Computer Modern fonts, and \CONTEXT\ uses Latin Modern by default.
89%D So, we just specify the font size.
90
91\setupbodyfont
92  [10pt]
93
94%D We break after these chars in urls, not before.
95
96\sethyphenatedurlafter /
97\sethyphenatedurlafter .
98\sethyphenatedurlafter _
99
100%D The layout is based on the letter paper format. This means that we get somewhat
101%D wider columns than on A4, but we can't make the margins narrower, which would
102%D ease some constraints.
103
104\setuppapersize
105  [letter]
106  [letter]
107
108\setuplayout
109  [topspace=3.8pc,% was 3.5pc
110   header=1pc,
111   headerdistance=1.5pc,
112   height=middle,
113   footerdistance=2pc,
114   footer=1pc,
115   bottomspace=3pc,
116   %
117   backspace=6pc,
118   width=middle,
119   cutspace=6pc,
120   %
121   margin=4pc,
122   margindistance=1pc]
123
124%D We have several column mechanisms and they all serve a different purpose. Here we
125%D use pagecolumns. They support much of what we can do in single columns, but of
126%D course there are exceptions. Floats can go into columns of aremoved to the top or
127%D bottom when there is no room. We don't span mid column. Notes can go in columns
128%D or at the end. We can start with a single column (for titles and such).
129%D
130%D This mechanism will be improved over time in sync with additional features in the
131%D \LUAMETATEX\ engine. This means that older documents might render differently
132%D (hopefully better). It is no problem to use more than two columns but this is
133%D what \TUGBOAT\ needs:
134
135\setuppagecolumns
136  [n=2,
137   distance=1.5pc]
138
139\setuppagenumbering
140  [location=,
141   alternative=doublesided]
142
143%D In \TUGBOAT\ different articles are glued together to form the final journal, so
144%D we do not want each article to occupy even number of pages.
145
146%D TODO: this needs checking with page columns:
147
148\installpagebreakhandler {last} {}
149
150%D We use automatic indentation control, that is: no indentation after titles and
151%D skips. Normally we dont'use indentation in \CONTEXT\ articles but prefer
152%D whitespace. Quite often we have short sentences and indentation just looks bad
153%D on successive ones.
154
155\setupindenting
156  [20pt,yes]
157
158%D We do not usually want indentation after lists.
159
160\setupenumerations [indentnext=no]
161\setupdescriptions [indentnext=no]
162
163%D And these. We typeset itemizations ragged right.
164
165\setupitemgroup
166  [itemize]
167  [indentnext=no,
168   align=right]
169
170%D We align them at the paragraph indentation and pack them by default.
171
172\setupitemgroup
173  [itemize]
174  [each]
175  [margin=1pc,
176   width=1em,
177   distance=0pt]
178
179\setupitemgroup
180  [itemize]
181  [1]
182  [packed]
183
184%D This a good opportunity to play with the additional passes in the par builder.
185%D The following values are experimental
186
187% \setupalign
188%   [tolerant]
189
190\startsetups align:pass:quality:1
191\parpasses    6
192    classes              \indecentparpassclasses
193    threshold            0.025pt
194    tolerance             250
195    extrahyphenpenalty     50
196    orphanpenalty        5000
197  % font driven
198  next ifadjustspacing
199    threshold            0.025pt
200    classes              \tightparpassclasses
201    tolerance             300
202    adjustspacing           3
203    orphanpenalty        5000
204  next ifadjustspacing
205    threshold            0.025pt
206    tolerance            350
207    adjustspacing           3
208    adjustspacingstep       1
209    adjustspacingshrink    20
210    adjustspacingstretch   40
211    orphanpenalty        5000
212    emergencystretch     .25\bodyfontsize
213  % otherwise, factors 1000
214  next
215    threshold            0.025pt
216    classes              \tightparpassclasses
217    tolerance             300
218    adjustspacing           3
219    adjustspacingstep       1
220    adjustspacingshrink    10
221    adjustspacingstretch   15
222    orphanpenalty        5000
223  next
224    threshold            0.025pt
225    tolerance             350
226    adjustspacing           3
227    adjustspacingstep       1
228    adjustspacingshrink    20
229    adjustspacingstretch   40
230    orphanpenalty        5000
231    emergencystretch     .25\bodyfontsize
232  % whatever
233  next
234    threshold            0.025pt
235    tolerance            3000
236    orphanpenalty        5000
237    emergencystretch     .25\bodyfontsize
238\relax\stopsetups
239
240\setupalignpass[quality:1]
241
242%D We don't want this ugly extreme stretching between elements when we end a page
243%D and package it.
244
245\setuplayout
246  [limitstretch=yes]
247
248\setuplayout
249  [vz=2]
250
251\setupalign
252  [depth]
253
254%D The question is: do we prefer a \CONTEXT\ look and feel or go for the more \LATEX
255%D ish one used in \TUGBOAT. Because no grid typesetting is expected we suppose that
256%D it doesn't matter much. We also definitely will use properly spaced tables, so
257%D we're already different.
258
259\definevspacingamount[tugbeforesection] [8pt plus 1pt minus 1pt][\lineheight]
260\definevspacingamount[tugaftersection]  [4pt plus 1pt minus 1pt][.5\lineheight]
261
262\setuphead
263  [section,subsection,subsubsection,
264   subject,subsubject,subsubsubject]
265  [style=bold,
266   align=right,
267   before={\blank[tugbeforesection]},
268   after={\blank[tugaftersection]}]
269
270%D We define a logical skip. This is equal to the \type {topsep} in the normal style,
271%D and most environments should have this skip.
272
273\definevspacingamount[tugsmallamount] [3pt  plus 1pt minus 1pt][.5\lineheight]
274\definevspacingamount[tugmediumamount][9pt  plus 3pt minus 3pt][.5\lineheight]
275\definevspacingamount[tuglargeamount] [10pt plus 4pt minus 4pt][\lineheight]
276
277\defineblank[tugblank] [tugsmallamount]
278\defineblank[tugsmall] [tugsmallamount]
279\defineblank[tugmedium][tugmediumamount]
280\defineblank[tuglarge] [tuglargeamount]
281\defineblank[tughalf]  [halfline]
282
283\setupblank
284  [tugblank]
285
286\setupitemize
287  [1]
288  [before={\blank[tugblank]},
289   after={\blank[tugblank]},
290   inbetween={\blank[tugblank]}]
291
292\setuplines
293  [before={\blank[tugblank]},
294   after={\blank[tugblank]},
295   inbetween={\blank[tugblank]}]
296
297%D Because we don't want to mess up originals too much we have a few hacks:
298
299\setuplinecorrection
300  [before={\blank[tugblank]},
301   after={\blank[tugblank]}]
302
303%D \TUGBOAT\ uses a smaller font size for verbatim typesetting.
304
305%D TODO: tb uses 9pt for verbatim, which looks a bit funny and it messes up the spacing
306%D but in lmtx we can actually play with \glyphxscale
307
308\definefontfile[modern-condensed][modern-condensed]
309
310\definetypeface
311  [narrowtt] [tt]
312  [mono] [modern-condensed] [default] [features=none]
313
314\definefont[TugBoatVerbatimFont][Mono*none sa .9]
315
316\setuptyping
317  [option=none,
318   align=hangright,
319   style=narrowtt,
320   before={\blank[tugblank]},
321   after={\blank[tugblank]}]
322
323% An uglier variant:
324
325\startsetups[tugboat:verbatim:tight]
326    \setuptyping
327      [style=TugBoatVerbatimFont,
328       bodyfont=9pt, % hm
329       blank=halfline,
330       lines=hyphenated]
331\stopsetups
332
333%D Do not colorize code.
334
335\setuptyping[LUA][option=]
336\setuptyping[TEX][option=]
337\setuptyping[MP] [option=]
338
339
340%      %D Tiny line numbers in numbered code (not text size)
341%
342%      \setuplinenumbering[style=\tfxx] % \infofont would be really tiny
343%
344%      %D \section{Figure captions}
345%      %D
346%      %D \TUGBOAT\ uses a smaller font size for captions, too; \type {\small} gives 8pt,
347%      %D and we want 9pt, so we have to manually fix the baselines.
348%
349%      \setupcaptions
350%        [headstyle=\AcroFontBold,
351%         style={\AcroFont\advance\baselineskip by -1pt},
352%         align=right]
353%
354%      %D We like a colon after the caption label.
355%
356%      \let\floatcaptionsuffix=:
357%
358%      % Prefer floats in text.
359%
360%      \setupfloat[figure][align=middle,default=here]
361%      \setupfloat[table] [align=middle,default=here]
362
363
364%D Not entirely a la \TUGBOAT:
365
366\protected\def\MyFootNoteRule
367  {\hrule width 5pc height .4pt depth 0pt\relax \kern \strutdepth}
368
369\setupfootnotes
370% [bodyfont=8pt,
371  [bodyfont=9pt,
372   location=columns,
373   rule=on,
374   rulecommand=\MyFootNoteRule]
375
376% \setupnotation
377% [footnote]
378
379\setupnotations
380  [location=joinedup,
381   width=fit,
382   headstyle=normal,
383   distance=.5em]
384
385%D We define a standard description and enumeration environment.
386
387\definedescription
388  [description]
389  [location=hanging,
390   width=broad,
391   before={\blank[tugblank]},
392   after={\blank[tugblank]}]
393
394\defineenumeration
395  [enumeration]
396  [location=hanging,
397   width=broad,
398   before={\blank[tugblank]},
399   after={\blank[tugblank]}]
400
401%D We need to get rid of some structure in case we include something also used
402%D otherwise. This assumes that we always start at the section level.
403
404\setuphead
405  [chapter]
406  [page=,
407   before=,
408   after=,
409   incrementnumber=no,
410   placehead=no]
411
412%D More or less like plain BibTeX + ltugboat.
413
414\setupbtx
415  [default:list:numbering]
416  [left={[},
417   right={]}]
418
419\setupbtxlist
420  [default]
421  [width=2em,
422   style={\frenchspacing},
423   align={raggedright,verystrict}]
424
425%D Instead of color, we use weighted gray scales (will become an option):
426
427\setupcolors
428  [conversion=always]
429
430%D English it is.
431
432\mainlanguage
433  [en]
434
435%D We define some logical skips
436
437\defineblank [tugbefore]   [big]
438\defineblank [tuginbetween][big]
439\defineblank [tugafter]    [tugbefore]
440
441%D Some real macros:
442
443\protected\def\StopAbstract
444  {}
445
446\protected\def\StartAbstract
447  {\dostartbuffer[abstract][StartAbstract][StopAbstract]}
448
449\startsetups tugboat:abstract:setup
450
451  \setuptolerance              % really? we need an example
452    [horizontal,tolerant]
453
454  \setupnarrower
455    [before={\blank[tughalf]},
456     after={\blank[tuglarge]},
457     middle=4.875pc]
458
459\stopsetups
460
461%D Headers and footers are different for normal issues and proceedings.
462
463\startsetups tugboat:banner:text:article
464
465%   {\sl TUGboat},\space
466%   Volume \getvariable{tugboat}{volume}\space
467%   (\getvariable{tugboat}{year}),\space
468%   No.\space\getvariable{tugboat}{number}
469
470\stopsetups
471
472\def\postissno{Proceedings of the \tubyear\ Annual Meeting}
473
474\startsetups tugboat:banner:text:proceedings
475
476    \setups[tugboat:banner:text:article]
477    \thinspace\emdash\thinspace
478    \postissno
479
480\stopsetups
481
482\startsetups tugboat:banner:setup:article
483
484  \setupheadertexts
485    [\setups{tugboat:banner:text:article}]
486    [pagenumber]
487
488% There are no footers in regular articles
489%
490%  \setupfootertexts
491%    [][\getvariable{tugboat}{author}]
492%    [\getvariable{tugboat}{title}][]
493
494\stopsetups
495
496\startsetups tugboat:banner:setup:proceedings
497
498  \setupheadertexts
499    [][\getvariable{tugboat}{title}]
500    [\getvariable{tugboat}{author}][]
501
502  \setupfootertexts
503    [\setups{tugboat:banner:text:proceedings}]
504    [pagenumber]
505
506\stopsetups
507
508%D Article is default so,
509
510\setups[tugboat:banner:setup:article]
511
512%D It all starts here:
513
514\permanent\protected\def\StartArticle{\directsetup{tugboat:\getvariable{tugboat}{type}:start}}
515\permanent\protected\def\StopArticle {\directsetup{tugboat:article:stop}}
516
517\startsetups tugboat:introduction:article
518
519    \start
520        \enforced\protected\def\\{\unskip\space\&\space\ignorespaces}
521        \hbox{\indent\getvariable{tugboat}{author}}% really \indent here?
522        \par
523    \stop
524
525\stopsetups
526
527\startsetups tugboat:introduction:proceedings
528
529    \blank[20pt]
530
531    \start
532        \switchtobodyfont[12pt]
533        \enforced\protected\def\\{\unskip\space\&\space\ignorespaces}
534        \getvariable{tugboat}{author}
535        \par
536    \stop
537
538    \start
539        \switchtobodyfont[9pt]
540        \enforced\protected\def\\{\unskip,\space\ignorespaces}
541        \getvariable{tugboat}{address}
542        \par
543        \start
544            \tt
545            \getvariable{tugboat}{email}
546        \stop
547        \par
548    \stop
549
550\stopsetups
551
552\startsetups tugboat:columns:presets
553
554    % whatever
555
556\stopsetups
557
558\startsetups tugboat:article:start
559
560  \starttext
561
562    \setups{tugboat:columns:presets}
563
564    \setups{tugboat:banner:setup:\getvariable{tugboat}{type}}
565
566    \startpagecolumns
567
568    \setupheadertexts
569        [\setups{tugboat:banner:text:article}]
570        [pagenumber]
571
572    \setuppagenumber
573        [number=\getvariable{tugboat}{page}]
574
575  % \snaptogrid \vbox \bgroup
576    \vbox \bgroup % \dbox ?
577        \forgetall
578        \hrule height .6pt
579        \blank[halfline]
580        \start
581            \enforced\let\\\par
582            \start
583                \bf
584                \getvariable{tugboat}{title}
585            \stop
586            \par
587            \blank[halfline]
588            \hskip20pt\getvariable{tugboat}{author}
589        \stop
590
591        \doifelsebufferempty {abstract} {
592            % no abstract
593        } {
594            \blank[line]
595
596            \enforced\let\\\endgraf
597            \setups[tugboat:abstract:setup]
598            \startsubject[title={Abstract}]
599                \getbuffer[abstract]
600            \stopsubject
601        }
602    \egroup
603
604\stopsetups
605
606\startsetups tugboat:proceedings:start
607
608    \starttext
609
610    \setups{tugboat:banner:setup:\getvariable{tugboat}{type}}
611
612    \setupheader
613        [state=empty]
614
615    \setuppagenumber
616        [number=\getvariable{tugboat}{page}]
617
618  % \snaptogrid \vbox \bgroup
619    \vbox \bgroup % \dbox ?
620
621        \forgetall
622
623        \start
624            \switchtobodyfont[14.4pt]
625            \enforced\let\\\par
626            \getvariable{tugboat}{title}
627            \par
628        \stop
629
630        \setups{tugboat:introduction:\getvariable{tugboat}{type}}
631
632        \blank[tugmedium]
633
634        \enforced\let\\\par
635
636        \doifelsebufferempty {abstract} {
637            % no abstract
638        } {
639            \setups[tugboat:abstract:setup]
640
641            \midaligned{\bf Abstract}
642
643            \startnarrower[middle]
644                \getbuffer[abstract]
645            \stopnarrower
646        }
647    \egroup
648
649    \startpagecolumns
650
651\stopsetups
652
653\def\signaturewidth{13pc}
654
655\startsetups tugboat:affiliation:article
656
657    \blank[line]
658
659  % \snaptogrid \vbox \bgroup
660    \vbox \bgroup % \dbox ?
661
662        \forgetall
663
664        \leftskip=\dimexpr\textwidth-\signaturewidth\relax
665
666        \enforced\let\\\par
667
668        \noindent\llap {
669            $\diamond$\enspace
670        }
671        \getvariable{tugboat}{author}
672        \par
673
674        \getvariable{tugboat}{address}
675        \par
676
677        {\tt\getvariable{tugboat}{email}}
678
679  \egroup
680
681\stopsetups
682
683\startsetups tugboat:affiliation:proceedings
684
685    % nothing fancy at the end
686
687\stopsetups
688
689\startsetups tugboat:article:stop
690
691    \setups{tugboat:affiliation:\getvariable{tugboat}{type}}
692
693    \blank[line]
694
695    \startpacked
696        \placenotes[endnotes]
697    \stoppacked
698
699    % Karl: what does \writelastpage do
700
701    \ifdefined\writelastpage
702        \begingroup
703            \count0 = \realpageno % an integerdef
704            \writelastpage{+1}%
705        \endgroup
706    \fi
707
708    \stoppagecolumns
709
710    \page
711
712    \stoptext
713
714\stopsetups
715
716%D Normal word spacing, really?
717
718\setuptolerance
719  [strict]
720
721%D Use this in documents:
722
723% \setuptolerance
724%   [verytolerant,stretch]
725
726%D Language stuff.
727
728\setuplanguage
729  [lefthyphenmin=2,
730   rightthyphenmin=3]
731
732%D A hack to read tugboat.dates settings. I need an example.
733
734\doifelsefileexists {../tugboat.dates} {
735
736    \pushoverloadmode
737
738    \newcount\issueseqno
739    \newif   \ifPrelimDraft
740
741  % \pushmacro\vol
742  % \pushmacro\issyear
743
744    \def\vol    #1, #2.{\xdef\tubvol {#1}%
745                        \xdef\tubnum {#2}}
746    \def\issyear    #1.{\xdef\tubyear{#1}}
747
748    \input {../tugboat.dates}
749
750  % \popmacro\vol
751  % \popmacro\issyear
752
753    \popoverloadmode
754
755    \setevariables
756      [tugboat]
757      [year=\tubyear,
758       volume=\tubvol,
759       number=\tubnum,
760       page=\the\count0]
761
762} {
763    % nothing
764}
765
766\def\tubyear{1234}
767\def\tubvol {5}
768\def\tubnum {6}
769
770\def\issyear    #1.{\def\tubyear{#1}}
771\def\vol    #1, #2.{\def\tubvol {#1}%
772                    \def\tubnum {#2}}
773
774\stopmodule
775
776%D Good bye.
777
778\continueifinputfile{s-tugboat-columns.mkxl}
779
780\setupexternalfigures[location={local,global,default}]
781
782\StartArticle
783
784    \StartAbstract
785        \input bryson
786    \StopAbstract
787
788%     \dorecurse{30}{\input ward \par} \page
789
790%     \startitemize
791%         \startitem \input ward \stopitem
792%         \startitem \input ward \stopitem
793%     \stopitemize
794
795
796    \samplefile{tufte}\par
797    \samplefile{tufte}
798
799    As we see \doifelsemode {columns} {in \in {table} [demo-1]} {below} we can have
800    more than one cell in a row.
801
802    \startplacetable[mode=columns,reference=demo-1]
803        \starttabulate[|||||]
804            \expandedloop 1 10 1 {%
805                \NC one \the\currentloopiterator \NC one more \NC and even 1 mode \NC and way more 1 now \NC \NR
806                \NC two \the\currentloopiterator \NC two more \NC and even 2 mode \NC and way more 2 now \NC \NR
807            }%
808        \stoptabulate
809    \stopplacetable
810
811    \samplefile{tufte}
812
813    \startplacefigure[mode=columns,reference=demo-2]
814        \externalfigure[cow.pdf][height=2cm,width=\textwidth]
815    \stopplacetable
816
817    \samplefile{tufte}\par
818    \samplefile{tufte}
819
820    \starttyping
821    test test test test test test
822    test test test test test test test test test test test test test test test test test test
823    test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test
824    test test test test test test test test test test test test test test test test test test
825    \stoptyping
826
827    \samplefile{tufte}
828
829    \dorecurse{10}{\samplefile{zapf}\blank}
830
831\StopArticle
832