aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc/grosciteco.tes
blob: 648242fb3571d070a9e1dfd9ab9aea89f9613040 (plain)
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
#!/usr/local/bin/sciteco -m
!* grosciteco.tes [-t <output-tec>] [--] <output-woman> <input> *!

0,2EJ !* FIXME: Memory limiting is too slow *!

:EMQ[$SCITECOPATH]/getopt.tes

!* Process command-line options *!
[optstring]t: M[getopt]"F (0/0) '
LR 0X[output-woman] 2LR 0X[input] HK
:Q[getopt.t]"< EU[getopt.t]Q[output-woman].tec '

EBN[input]

! skip whitespace characters !
@#sw{
  <0A-^^ "N 1; ' :C;>
}

!* skip N (string) arguments beginning with current one *!
@#sa{
  "~1'<
    <0A-^^ "= 1; ' 0A-10"= 1; ' :C;> :M#sw
  >
}

!* get next integer argument, skipping it *!
@#gi{
  \ (0A-^^-"= :C ' <0A"D :C; | 1; '> :M#sw)
}

!* skip end of command *!
@#sc{
  0A-10"= :C '
}

0U[text.lines] 0U[pos.v] 0U[pos.h]

!* move to (pos.h,pos.v) relative to origin, making space if necessary *!
@[move]{ [.n
  U.n J
  Q[pos.v]-Q[text.lines]">
    ZJ Q[pos.v]-Q[text.lines]<I^J>
    Q[pos.v]U[text.lines]
  |
    Q[pos.v]L
  '
  Q[pos.h]<.-Z"= I  | 0A-10"= I  | C' '>
  Q.n<.-Z"= 1; ' 0A-10"= 1; ' D>
].n }

1U[default-style]
@[style]{ [.l
  U.l Q[font]-Q[default-style]"N
    .-Q.lESSTARTSTYLING Q[font],Q.lESSETSTYLING
  '
].l }

[topics]

!*
 * Special characters
 * FIXME: Use UTF8 characters once available
 *!
[glyphs.**]*
[glyphs.\-]-
[glyphs.aa]'
[glyphs.dq]"
[glyphs.hy]-
[glyphs.la]<
[glyphs.ra]>
[glyphs.lq]"
[glyphs.rq]"
[glyphs.rs]\
[glyphs.+]+

!* process formatter commands *!
@[format]{ <
  .-Z"= 1; '
  0AU[cmd] C
  Ocmd.U[cmd]

  !cmd.x!
    :M#sw
    0AU[cmd] C
    Ocmd.xU[cmd]

    !cmd.xT!
      2:M#sa :M#sc F<
    !cmd.xr!
      :M#sa :M#giU[res] :M#giU[res.h] :M#giU[res.v] :M#sc F<
    !cmd.xi!
      :M#sa :M#sc F<
    !cmd.xF!
      L F<
    !cmd.xX!
      :M#sw .(W).X.w
      Ocmd.xXQ.w
      !cmd.xXsciteco_topic!
        !*
         * FIXME: The buffer position of this topic might still
         * change due to movement commands (esp. when formatting
         * a table). Only the line+column should no longer change.
         * Either store line+column or use markers.
         *!
        [* EB 0:M[move] .U.d ]*
        :EU[topics]\.d:
        C :X[topics]
        L F<
      !cmd.xXsciteco_tt!
        [* EB 0:M[move] .U[ttstart] ]*
        L F<
      !cmd.xXsciteco_tt_end!
        [* EB 0:M[move]
          .-Q[ttstart]<
            Q[ttstart]ESSTARTSTYLING Q[ttstart]ESGETSTYLEAT+16,1ESSETSTYLING
          %[ttstart]>
        ]*
        L F<
      !cmd.xXtty!
      !cmd.xXdevtag!
        L F<

    !cmd.xf!
      :M#sa :M#giU.n Q.n+16U.#nt .(:M#sa).X[font] :M#sc
      :Q[fonts.\.n]"F F< ' -U[fonts.\.n]
      @:EU[styles]{\.#ntESSTYLESETFONTCourier^J}
      Ocmd.xfQ[font]
      !cmd.xfR!
        Q.nU[default-style]
        @:EU[styles]{16ESSTYLESETFONTCourier^J}
        F<
      !cmd.xfB!
        @:EU[styles]{1,\.nESSTYLESETBOLD 1,\.#ntESSTYLESETBOLD^J}
        F<
      !cmd.xfBI!
        @:EU[styles]{1,\.nESSTYLESETBOLD 1,\.#ntESSTYLESETBOLD^J}
      !cmd.xfI!
        @:EU[styles]{1,\.nESSTYLESETITALIC 1,\.#ntESSTYLESETITALIC^J}
        @:EU[styles]{0EJ-1"= 1,\.nESSTYLESETUNDERLINE 1,\.#ntESSTYLESETUNDERLINE '^J}
        F<

    !cmd.xt!
      :M#sa :M#sc F<
    !cmd.xs!
      1;

  !cmd.F!
    L F<

  !cmd.p!
    :M#sw :M#gi Q[pos.v]U[origin.v] :M#sc F<

  !cmd.f!
    :M#sw :M#giU[font] :M#sc F<

  !cmd.s!
    :M#sw :M#gi :M#sc F<

  !cmd.V!
    :M#sw :M#gi/Q[res.v]-1+Q[origin.v]U[pos.v] :M#sc F<

  !cmd.v!
    :M#sw :M#gi/Q[res.v]%[pos.v] :M#sc F<

  !cmd.H!
    :M#sw :M#gi/Q[res.h]U[pos.h] :M#sc F<

  !cmd.h!
    :M#sw :M#gi/Q[res.h]%[pos.h] :M#sc F<

  !cmd.m!
    :M#sw
    0AU[cmd] C
    Ocmd.mU[cmd]

    !cmd.md!
      :M#sc F<

  !cmd.D!
    :M#sw
    0AU[cmd] C
    Ocmd.DU[cmd]

    !cmd.DF!
      :M#sw
      0AU[cmd] C
      Ocmd.DFU[cmd]

        !cmd.DFd!
          :M#sc F<

    !cmd.Dl!
      :M#sw :M#gi/Q[res.h]+Q[pos.h]U.[to.h] :M#gi/Q[res.v]+Q[pos.v]U.[to.v] :M#sc
      [* EB
      Q.[to.h]-Q[pos.h]"=
        ! vertical line !
        Q.[to.v]-Q[pos.v]"< Q[pos.v]U.v Q.[to.v]U[pos.v] | Q.[to.v]U.v '
        1:M[move] I+ %[pos.v]
        Q.v-Q[pos.v]<
          1:M[move] I| %[pos.v]
        >
        1:M[move] I+
        Q.[to.v]U[pos.v]
      |
        ! horizontal line !
        Q.[to.h]-Q[pos.h]"< Q[pos.h]U.h Q.[to.h]U[pos.h] | Q.[to.h]U.h '
        1:M[move] I+ %[pos.h]
        Q.h-Q[pos.h]<
          1:M[move] I- %[pos.h]
        >
        1:M[move] I+
        Q.[to.h]U[pos.h]
      '
      ]* F<

  !cmd.t!
    :M#sw .(:M#sa).X.w
    [* EB :Q.w:M[move]
    G.w :Q.w:M[style] ]*
    :Q.w%[pos.h] :M#sc F<

  !cmd.C!
    :M#sw .(:M#sa).X.w
    [* EB 1:M[move]
    G[glyphs.Q.w] 1:M[style] ]* :M#sc F<

  !cmd.c!
    :M#sw 0AU.w C
    [* EB 1:M[move]
    G[glyphs.U.w] 1:M[style] ]* :M#sc F<

  !cmd.n!
    :M#sw :M#gi :M#gi :M#sc F<

  !cmd.w!
    :M#sc F<
> }

!*
 * Inline local macro invocations in [format]
 * This speeds up runtime by 25%
 *!
EQ[format]
  J<FR:M[move]Q[move];>
  J<FR:M[style]Q[style];>
  J<FR:M#saQ#sa;>
  J<FR:M#giQ#gi;>
  J<FR:M#swQ#sw;>
  J<FR:M#scQ#sc;>
  !*
   * Compress whitespace, kind of dangerous:
   * J<FRS ;>
   *!
Q*U*

:M[format]

!*
 * Generate the styling instructions based on the styles
 * of the womanpage buffer. The styles are configured according
 * to their font positions (already in `styles`).
 * Styles are NOT generated in `styles` immediately during
 * formatting, since the buffer positions of text to style
 * can still change with `move` operations that add whitespace.
 * Also, here we can generate a minimal list of styling operations
 * ending up with much smaller *.tec files.
 * TODO: The size can still be improved by using SCI_SETSTYLINGEX
 * if appropriate.
 *!
EB J 0U#cs 0U#cd
<
  .ESGETSTYLEATUs Qs"< Qs= '
  .-Z"< Qs-Q#cs"= C F< ' '
  Q#cs"N
    .-Q#cd Ul
    @:EU[styles]{\#cdESSTARTSTYLING \#cs,\lESSETSTYLING^J}
  '
  QsU#cs .U#cd
:C;>

!*
 * Save the clear-text part of the document into <output-woman>
 *!
2EL EWQ[output-woman]

EQ[styles]

!* Generate topic index *!
J I!*Q[topics]*!^J

2EL EWQ[getopt.t]

-EX