languages-labels.tex /size: 3994 b    last modification: 2021-10-28 13:50
1% language=us runpath=texruns:manuals/languages
2
3\startcomponent languages-labels
4
5\environment languages-environment
6
7\startchapter[title=Labels][color=darkcyan]
8
9\startsection[title=Introduction]
10
11When we started using \TEX, I naturally started with plain \TEX. But it didn't
12take long before we tried \LATEX. Because our documents were in Dutch one of the
13first fights with this package was to get rid of the english labels. Because
14rather soon we decided to cook up an alternative package, a decent label
15mechanism was one of the first things to show up. And as soon as multiple
16language typesetting gets into view, such a mechanism becomes one of those
17language dependent features. In this chapter the basics will be covered.
18
19\stopsection
20
21\startsection[title=Defining labels]
22
23Before we define a label we need to define a label class. You probably seldom
24need that but this is how it's done:
25
26\startbuffer
27\definelabelclass [mylabel]
28\stopbuffer
29
30\typebuffer \getbuffer
31
32There are some classes predefined:
33
34\starttabulate[|lB|l|]
35    \NC head      \NC (complete) titles like \headtext {chapter} and \headtext {figure} \NC \NR
36    \NC label     \NC in||text labels like \labeltext {chapter} and \labeltext {figure} \NC \NR
37    \NC mathlabel \NC function names like \mathlabeltext{sin} and \mathlabeltext{cos} \NC \NR
38    \NC taglabel  \NC labels used for tagging purposed in the backend \NC \NR
39    \NC btxlabel  \NC labels used in typesetting bibliographic items \NC \NR
40\stoptabulate
41
42The physical units mechanism also uses labels: unit, operator, prefix and suffix.
43All these labels are defined per language with a fall back on english.
44
45Given that we have defined class \type {mylabel}, a label itself is set like
46this:
47
48\startbuffer
49\setupmylabeltext
50  [en]
51  [first={<after first},
52   second={{before second>},{<after second}}]
53\stopbuffer
54
55\typebuffer \getbuffer
56
57The first argument (the language) is optional. In the next section we will see
58how these labels are used. A lot of labels are predefined, in \MKIV\ this happens
59in the file \type {lang-txt.lua}. There is no need to adapt this file as you can
60always add labels run time.
61
62\stopsection
63
64\startsection[title=Using labels]
65
66How a label is called depends on the way it needs to be used. In any case the
67main language set determines the language of the label. So, when in an Dutch text
68we temporary switch to German, the Dutch labels are used.
69
70\startbuffer
71\starttabulate[||||]
72    \NC  \bf command                         \NC \ttbf first                    \NC \ttbf {second}                  \NC \NR
73    \HL
74    \NC \type {\leftmylabeltext {tag}}       \NC \leftmylabeltext {first}       \NC \leftmylabeltext {second}       \NC \NR
75    \NC \type {\rightmylabeltext{tag}}       \NC \rightmylabeltext{first}       \NC \rightmylabeltext{second}       \NC \NR
76    \NC \type {\mylabeltext     {tag}}       \NC \mylabeltext     {first}       \NC \mylabeltext     {second}       \NC \NR
77    \NC \type {\mylabeltexts    {tag}{text}} \NC \mylabeltexts    {first}{text} \NC \mylabeltexts    {second}{text} \NC \NR
78\stoptabulate
79\stopbuffer
80
81\getbuffer
82
83\stopsection
84
85\startsection[title=Hooks]
86
87Some mechanisms have label support built in, most noticeably sections
88heads and numbered items, like figure captions.
89
90\startbuffer
91\definehead
92  [myhead]
93  [subsection]
94
95\setuphead
96  [myhead]
97  [bodypartlabel=bodypartmyhead]
98
99\setuplabeltext
100  [en]
101  [bodypartmyhead=My Head: ]
102
103\myhead{Welcome}
104\stopbuffer
105
106\typebuffer \getbuffer
107
108The head text label class can be used as follows:
109
110\startbuffer
111\setupheadtext
112  [SomeHead=Just A Title]
113
114\subsection
115  [title=\headtext{SomeHead}]
116\stopbuffer
117
118\typebuffer \getbuffer
119
120A label will obey the style settings, as in:
121
122\startbuffer
123\definehead
124  [MyFancyHead]
125  [subsection]
126  [style={\bs\setcharactercasing[Words]}]
127
128\setupheadtext
129  [SomeHead=just another title]
130
131\MyFancyHead
132  [title=\headtext{SomeHead}]
133\stopbuffer
134
135\typebuffer \getbuffer
136
137\stopsection
138
139\stopchapter
140
141\stopcomponent
142