~avaneya/avaneya/trunk

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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
% This is part of the Avaneya Project Crew Handbook.
% Copyright (C) 2010-2017 Cartesian Theatre™ <info@cartesiantheatre.com>.
% See the file Copying for details on copying conditions.

% The environment file is used to setup the typesetting that relate to
%  any product, but at present, just the handbook...

\startenvironment Environment

% Quiet...
\showmessagesfalse

% Plugin modules we need to import...

    % Simple fonts...
    \usemodule[simplefonts]

    % \BIBTEX macro...
    \usemodule[abr-02]

% Define colours...
\definecolor[colour_figure_background][colour_page]
\definecolor[colour_figure_border][colour_text]
\definecolor[colour_footnote_background][colour_page]
\definecolor[colour_footnote_text][colour_text]
\definecolor[colour_frame_border][colour_text]
\definecolor[colour_head][r=0.828,g=0.313,b=0.176]
\definecolor[colour_item][r=0.864,g=0.426,b=0.234]
\definecolor[colour_link][colour_head]
\definecolor[colour_page_number][colour_head]
\definecolor[colour_page][r=0,g=0,b=0]
\definecolor[colour_table_row_even][r=0.357,g=0.357,b=0.357,t=0.4,a=1]
\definecolor[colour_table_row_odd][r=0.3,g=0.3,b=0.3,t=0.4,a=1]
\definecolor[colour_table_dark_column][r=0.05,g=0.05,b=0.05]
\definecolor[colour_text][r=0.754,g=0.516,b=0.324] % RGB 0xc08453
\definecolor[colour_text_background_shaded][r=0,g=0,b=0,t=0.4,a=1]
\definecolor[colour_text_background_clear][r=0,g=0,b=0,t=0.0,a=1]

% Setup various lists...

    % Fill space to page number with dots...
    \setupcombinedlist[content]
        [alternative=c]

    % Chapters...
    \setuplist[chapter]
        [color=colour_text,
         numbercolor=colour_head,
         pagecolor=colour_page_number,
         style=bold]

    % Section...
    \setuplist[section]
        [color=colour_text,
         numbercolor=colour_head,
         pagecolor=colour_page_number
         width=15mm]

    % Subsection...
    \setuplist[subsection]
        [color=colour_text,
         numbercolor=colour_head,
         pagecolor=colour_page_number
         width=20mm]

    % Subsubsection...
    \setuplist[subsubsection]
        [color=colour_text,
         numbercolor=colour_head,
         pagecolor=colour_page_number
         width=25mm]

% Revision control...

    % Bzr revision...
    \def\initializeBzr{
        \ctxlua{
            context.setxvalue(
                "BzrRevision",
                os.resultof("bzr revno | tr -d '\string\n'"))}
    }

    \initializeBzr

    % URL of latest handbook...
    \def\LatestHandbookURL{https://goo.gl/F3AxPZ}

    % Clickable Bzr revision...
    \def\BzrRevisionClickable{\href{https://blueprints.launchpad.net/avaneya/+spec/avaneya-project-crew-handbook}{\BzrRevision}}

% External program version strings...

    % PDF renderer version...
    \def\initializePDFRenderer
        {\ctxlua{context.setgvalue("PDFRendererVersion", os.resultof"xreader --version | tr -d '\\n'")}}
    \initializePDFRenderer

    % Graphviz version...
    \def\initializeGraphviz
        {\ctxlua{context.setgvalue("GraphvizVersion", os.resultof"dot -V 2>&1 | sed -e 's/dot - graphviz version //g'")}}
    \initializeGraphviz

    % Umbrello version...
    \def\initializeUmbrello
        {\ctxlua{context.setgvalue("UmbrelloVersion", os.resultof"umbrello --version | grep -i umbrello | tr -d ':\\n'")}}
    \initializeUmbrello

% LuaTeX / LuajitTex backend version...
\def\texjitenginename{\ctxlua{if (texenginename == LuaTeX and jit ~= nil) then context("LuajitTeX") else context.texenginename() end }}

% Document description...
\def\BookShortDescription{A guidebook for our community's contributors.}

% Setup PDF metadata...
\setupinteraction
  [state=start,
   color=colour_link,
   click=yes,
   contrastcolor=colour_link,
   focus=standard, % Clicking an inter-document hyperlink by default switches to "fit page" mode. Override.
   openaction={FitWidth,ToggleViewer},
   title=Avaneya Project Crew Handbook (Revision \BzrRevision),
   subtitle=\BookShortDescription,
   author=The Avaneya Project Crew (Revision \BzrRevision),
   keyword={Avaneya, handbook, Mars, GNU, linux, Ubuntu, game}]

% Show the PDF bookmarks and expand to the chapter and section level...
\placebookmarks[chapter,section,subsection,subsubsection][chapter]
\setupinteractionscreen[option=bookmark]

\setupTABLE[row][odd][background=color,backgroundcolor=colour_table_row_odd]
\setupTABLE[row][even][background=color,backgroundcolor=colour_table_row_even]
\setupTABLE[row][each][offset=2mm]

% Select language...
\mainlanguage[en]
\language[en]

% Avoid breaking words when going to next line...
\setupalign[nothyphenated]

% Setup default text colour...
\setupcolors[
    state=start,
    textcolor=colour_text,
    pagecolormodel=rgb] % gray rgb cmyk auto none

\setupmargindata
  [inmargin]
  [style={\switchtobodyfont[6pt]\bi]},
   color=colour_text]

\setupmarginframed
  [inmargin]
  [background=color,
   backgroundcolor=colour_page]

\setupexternalfigures
  [location={local,default},
   frame=off,
   corner=rectangular,
   framecolor=colour_figure_border,
%   background=color,
%   backgroundcolor=colour_page,
   rulethickness=0.5pt]

% Setup bibliography. Thanks Taco for your help...

    % References database and other general settings...
    \setupbibtex[database={References/References}, sort=author]

    % Global settings...
    \setuppublications[
        alternative=apa, % Anything other than apa typesets [[error 2]]???
        numbering=yes,
        monthconversion=month,
        autohang=yes,
        sorttype=cite]

    % Without this, no hyperlinks at all in the output...
    \setupinteraction[state=start]

    % This two-part helper creates a hyperlink for url fields...
    \unprotect
        \def\bibgotoURL#1#2%
         {\useURL[#1][#2][][#1]\from[#1]}
        \def\bibinsertbiburl#1#2#3%
         {\bibdoifelse{\@@pb@biburl}
           {#1\expanded{\bibgotoURL{\@@pb@title}{\@@pb@biburl}}#2}{#3}}
    \protect

    % Book reference layout...
    \setuppublicationlayout[book]{%
         \insertauthors{}{. }{\insertthekey{}{. }{}}%
         \inserttitle{\bgroup\it }{.\egroup\space }{}%
         \insertpubname{}{. }{}%
         \insertday{}{ }{}%
         \insertmonth{\Word }{. }{}%
         \insertpubyear{}{. }{}%
         \insertnote{}{.}{}%
        }

    % Adjusted version of 'misc' typesetting, using \insertbiburl
    % instead of \inserttitle (and \insertbiburl runs the
    % \bibinsertbiburl macro defined above)
    \setuppublicationlayout[misc]{%
     \insertauthors{}{. }{\insertthekey{}{. }{}}%
     \insertbiburl{\bgroup\it }{.\egroup\space }{}%
     \insertpubname{}{. }{}%
     \insertday{}{ }{}%
     \insertmonth{\Word }{. }{}%
     \insertpubyear{}{. }{}%
     \insertnote{}{.}{}%
    }

    % finally, this is a horrible hack needed due to bibtex inserting
    % line breaks in the middle of urls in the output bbl (!)
    % If you find this hack too ugly, consider editing the .bbl by
    % hand and forgetting about the .bib file altogether...
    \let\mydodostartpublication\dodostartpublication
    \def\dodostartpublication{\catcode`\%=14 \mydodostartpublication}

    % Macro to put the citations as footnotes...
    \unexpanded\def\footnotecite{\dodoubleempty\domycite}
    \def\domycite[#1][#2]%
        {\ifsecondargument
            \footnote{\cite[alternative=data,#1][#2]}%
        \else
            \footnote{\cite[data][#1]}%
        \fi}

    % Individial citation settings...

        % Enable clickable links...
        \setupcite[alternative=interaction=start, compress=no]

    % Publication list setups for end of the book list...

        % Settings for triggering et al...
        \setuppublicationlist[authoretallimit=3]
        \setuppublicationlist[authoretaltext={\it\ et al.}]
        \setuppublicationlist[authoretaldisplay=2]

        % List the author, editor, or article author's full name, inverted...
        \setuppublicationlist[%
            author=\invertedauthor,%
            artauthor=\invertedauthor,%
            editor=\invertedauthor,%
            title=References]

% Setup footnotes...

    \setupnotation[footnote]
        [color=colour_footnote_text,
         backgroundcolor=colour_footnote_background,
         width=0.5cm, % Space between footnote number and footnote itself
         numbercommand=] % Remove elevated footnote notation at bottom of page

    % Implemented by Hans in bleeding edge ConTeXt...
    \setupnote[footnote]
        [textseparator={\textcomma}, % Comma delineated
         before={\crlf\crlf}] %

    \setupfootnotes
      [rule=on, % Toggle off to disable horizontal rule
       textstyle={\hskip.06em}] % Vertical space between footnotes and the text

% To move footnotes inside of text boxes to the bottom of the page with
%  the rest of the footnotes. Disabled temporarily to fix issue of text
%  background frame borders vanishing...
\kindofpagetextareas\plusone

\automigrateinserts

% Setup floats...

    % Tables of width <0.5 times textwidth are automatically placed at the inner margin...
    \setupfloat[table]
        [criterium=0.5\textwidth,
         default=inner]

    \setupfloats
        [spacebefore=1*medium,
         spaceafter=1*medium]

% Jenya inline figure
\useexternalfigure[jenya_inline][Game_World/Images/Jenya_red.svg][factor=8]

% URL macros and setups...

    % Usage: \href{http://www.someurl.com}{Text}
    \def\href#1#2{\useURL[#2][{#2}][][{#1}]\goto{\url[#2]}[url(#1)]}
    \def\ahref#1{\color[colour_link]{\ttx \href{#1}{<#1>}}}
    \def\fullahref#1{\color[colour_link]{\ttx \href{#1}{#1}}}
    \def\mailto#1{\useURL[#1][mailto:#1][][#1]\from[{#1}]}
    \def\MailTo#1#2{\useURL[#1][mailto:#1][][#2]\from[{#1}]}

    % Style...
    \setupurl
      [color=colour_link,
       style=\bf]

\setupframedtexts
  [framecolor=colour_frame_border]

% Start counting page numbers from the cover onwards...
\setupmakeup[standard][pagestate=start]

% Set the background image...

    \defineoverlay
      [PageBackgroundImage]
      [{\overlayfigure{Makeup/Images/Background.png}}]

    \setupbackgrounds[page][background=PageBackgroundImage]

% PDF related settings...
\setupbackend
  [level=9,             % PDF compression level defaults to 3, so set maximum...
   xmpfile=Copying.xmp] % Licensing metadata...
\pdfcompresslevel9
\maximumpdfcompression

\setupsystem
  [random=big]

\unprotect
\setuplayout
  [location=middle,
   style=\bi,
   backspace=2.5cm,
   topspace=1.5cm,
   width=16cm,
   margindistance=.25cm,
   margin=2.5cm,
   height=middle]

\definelayout
  [fullpage]
  [backspace=0pt,
   topspace=0pt,
   width=middle,
   height=middle,
   header=0pt,
   footer=0pt]
\protect

\definepapersize[main][A4][A4]
\definepapersize[diagram][A4,landscape][A4,landscape]

\definehspace[star_hspace][1.75em]

% Define definitions used in terms & concepts chapter...
\definedescription[definition]
  [location=top,
   alternative=top,
   width=fit,
   headcolor=colour_head,
   headstyle=boldslanted]

% Define article item groups...
\defineitemgroup[article]

\setupitemgroup
   [article]
   [left={Article },
    stopper=,
    symbol=R,
    before=\blank,
    after=\blank,
    command=\blank,
    distance=0.5em]

\setupitemgroup
    [article]
    [color=colour_head]

% Remove surrounding quotation marks on references...
\setupreferencing[left=, right=]

% Font setup...

    \definefontsynonym[chapternumberfont][RegularBold]
    \definefontsynonym[chaptertextfont]  [RegularBold]

    \definebodyfont[11pt][rm][bfe=RegularBold at 30pt]
    \definebodyfont[11pt][rm][bft=RegularBold at 30pt]

    % Font to use for math...
    %\definetypeface[mainface][rm][serif][modern] [default][designsize=auto]
    %\definetypeface[mainface][ss][sans] [modern] [default][designsize=auto]
    %\definetypeface[mainface][tt][mono] [modern] [default][designsize=auto]
    %\definetypeface[mainface][mm][math] [pagella]
    %\setupbodyfont[mainface]

    % Font to use for main text...
    %\setmainfont[Ubuntu]
    \setupbodyfont[11pt]

    % Main font to use...
    \definefontfamily [main_font] [rm] [titillium] [features={default,quality}]
    \definefontfamily [main_font] [mm] [TeX Gyre Pagella Math]
    \setupbodyfont[main_font]

    % For code...
    \definefontfamily [code] [rm] [Liberation Mono] [features={default,quality}]
    \definefontfamily [code] [mm] [Liberation Mono] [features={default,quality}]

    % For Greek characters...
    \definefontfamily [greek_font] [rm] [TeX Gyre Pagella Math]
    \definefontfamily [greek_font] [mm] [TeX Gyre Pagella Math]
    
    % For Sanskrit characters...
    \definefontfamily [sanskrit_font] [rm] [Lohit Devanagari]
    \definefontfamily [sanskrit_font] [mm] [Lohit Devanagari]

\def\CopyrightDates{2010--2017}
\def\CopyrightHolder{Cartesian Theatre™}

% Bancor symbol properly typeset in something that supports Greek...
\def\Bancor{ \begingroup\switchtobodyfont[greek_font]β\endgroup }

% For any inline Sanskrit which may need a supporting typeface...
\define[1]\Sanskrit{ \begingroup\switchtobodyfont[sanskrit_font]#1\endgroup }

\def\SetupCharacterTable
{
    \bTABLE[width=0.2\textwidth]
    \switchtobodyfont[6pt]
    \setupTABLE[column][1]
        [align={middle,lohi},
         background=color,
         backgroundcolor=colour_table_row_even,
         style=\bf,
         width=2cm]
    \setupTABLE[column][2]
        [align=flushleft,
         option=stretch,
         background=color,
         backgroundcolor=colour_table_row_odd]
    \setupTABLE[each][each]
        [style=\tf]
}

% Insert a full page landscape diagram, parameters are node name, caption, and path...
\def\FullPageDiagram#1#2#3%
{
    \startTEXpage[offset=0mm,width=30cm]
    \placefigure
        [force][#1]
        {#2}
        {\externalfigure[#3]
            [factor=max,
             align=center]}
    \stopTEXpage
}

\def\StartChapter#1%
{
    \startcomponent{#1}
    \chapter[#1]{#1}
%    \index{#1}
}

\def\StopChapter%
{
    \stopcomponent
}

\def\StartSection#1%
{
    \section[#1]{#1}
%    \index{#1}
}

\def\StartSubSection#1%
{
    \subsection[#1]{#1}
%    \index{#1}
}

\def\StartSubSubSection#1%
{
    \subsubsection[#1]{#1}
%    \index{#1}
}

\def\StartTimelineDate#1%
{
    \subsubsubject{\bf #1}
}

\def\StopTimelineDate%
{
    \crlf
}

\definetextbackground[TimelineGeneralDocument]
   [location=paragraph,
    color=color_text,
    background=color,
    backgroundcolor=colour_text_background_shaded,
    frame=on,
    framecolor=colour_text,
    topoffset=0.5cm,
    bottomoffset=0.5cm,
    leftoffset=0.5cm,
    rightoffset=0.5cm,
    before={
        \blank[2*big]
    },
    after={
        \blank[2*big]
    },
    style=small,
    corner=round]

\definetextbackground[TimelineCorrespondenceDocument]
   [location=paragraph,
    color=color_text,
    background=color,
    backgroundcolor=colour_text_background_shaded,
    frame=on,
    framecolor=colour_text,
    topoffset=1.0cm,
    bottomoffset=1.0cm,
    leftoffset=1.5cm,
    rightoffset=1.5cm,
    before={
        \blank[2*big]
    },
    after={
        \blank[2*big]
    },
    style=smalltype,
    bodyfont=4pt,
    corner=round]

\definetextbackground[CodeExampleFrame]
   [corner=round,
    before={
        \blank[0.5cm]
        \startlinecorrection
    },
    after={
        \blank[0.5cm]
        \stoplinecorrection
    },
    bodyfont=5pt,
    color=color_text,
    background=color,
    backgroundcolor=colour_text_background_shaded,
    frame=on,
    framecolor=colour_text,
    location=paragraph,
    topoffset=0.5cm,
    bottomoffset=0.5cm,
    leftoffset=0.5cm,
    rightoffset=0.5cm]

    \definetyping
      [CodeExample]
      [before=\startCodeExampleFrame,
       bodyfont=code,
       after=\stopCodeExampleFrame]

% Number formulae etc. using the chapter number...
\setupnumbering
    [way=bychapter]

\setuppagenumbering
  [location=top,
   way=bytext,
   left={\lettertilde\space},right={\space\lettertilde},
%   left={(\space},right={\space)},
   color=colour_page_number,
   style=bold]

\setuptolerance
  [verytolerant,stretch]

\setupblank
  [medium]

% Spacing between paragraphs...
\setupwhitespace
  [big]

\setupfootertexts
  [margin]
  [][{
\hfill
%\doifnotmode{*frontpart}{\getmarking[chapternumber]}
\hfill
    }]

\setupbodyfontenvironment
  [default]
  [em=italic]

\setupsectionblock[frontpart] [page=yes]
\setupsectionblock[bodypart]  [page=yes]
\setupsectionblock[appendix]  [page=yes]
\setupsectionblock[frontpart] [before=,after=]

\setuphead
  [chapter]
  [command=\PlaceSection,
   color=colour_head,
   page=yes,
   before=,
   header=nomarking,
   style=\bfd]

\setuphead
  [title]
  [command=\PlaceSection,
   color=colour_head,
   page=right,
   before=,
   header=nomarking,
   style=\bfd]

\setuphead
  [section]
  [command=\PlaceSection,
   color=colour_head,
   inbetween=,
   style=\bfb]

\setuphead
  [subsection]
  [command=\PlaceSection,
   color=colour_head,
   before=\crlf,
   style=\bfa]

\setuphead
  [subsubsection]
  [command=\PlaceSection,
   color=colour_head,
   before=\blank,
   style=\bsa]

\define[2]\PlaceSection
  {\goodbreak
   \vbox
     {\localheadsetup
      \begstrut
      \inleftmargin{\hbox to \leftmarginwidth{\hss#1\hss}}%
      #2}}

\setupcaptions[location=bottom]

\setuptype
  [option=slanted]

\setuptyping
  [option=slanted,
   blank=medium]

\def\DotAfterNumber#1{\doiftext{#1}{#1.}}

\defineregister
  [texmacro]
  [texmacros]

\setupregister
  [texmacro]
  [indicator=off,
   distance=1em minus .25em]

\setuphead
  [chapter]
  [header=empty]

\setupitemize
  [each]
  [fit,2*broad]
  [color=colour_item,
   distance=.25em] % Distance between indicator and body text

\setupitemgroup[itemize]
  [each]
  [stopper]
  [headstyle=bold,
   inbetween={\blank[0.5cm]},
   before={\blank[0.5cm]},
   after={\blank[0.5cm]}]

\setupsubpagenumber
  [way=bychapter,
   state=start]

\stopenvironment