summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/statrep/sas/statrep_tagset.sas
blob: 819157c07d5da1b73075e3566cef1d570fc6556f (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
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
proc template;
   define style styles.StatRep;
      parent = styles.statistical;
      class colors /
         'link2' = cx0000FF
         'link1' = cx800080
         'docbg' = cxFFFFFF
         'contentbg' = cxFFFFFF
         'systitlebg' = cxFFFFFF
         'titlebg' = cxFFFFFF
         'proctitlebg' = cxFFFFFF
         'headerbg' = cxFFFFFF
         'captionbg' = cxFFFFFF
         'captionfg' = cx000000
         'bylinebg' = cxFFFFFF
         'notebg' = cxFFFFFF
         'tablebg' = cxFFFFFF
         'batchbg' = cxFFFFFF
         'systitlefg' = cx000000
         'titlefg' = cx000000
         'proctitlefg' = cx000000
         'bylinefg' = cx000000
         'notefg' = cx000000;
      class Header /
         color = cx000000
         backgroundcolor = cxFFFFFF
         bordercolor = cxB0B7BB
         bordercollapse = collapse;
      class RowHeader /
         color = cx000000
         backgroundcolor = cxFFFFFF
         bordercolor = cxB0B7BB
         bordercollapse = collapse;
      class Footer /
         color = cx000000
         backgroundcolor = cxFFFFFF
         bordercolor = cxB0B7BB
         bordercollapse = collapse;
      class RowFooter /
         color = cx000000
         backgroundcolor = cxFFFFFF
         bordercolor = cxB0B7BB
         bordercollapse = collapse;
      class batch /
         borderwidth = 0px;
      class Data /
         font = fonts('DocFont')
         backgroundcolor = _undef_
         bordercolor = cx919191
         bordercollapse = collapse;
      class DataEmphasis /
         font = fonts('DocFont')
         backgroundcolor = _undef_
         bordercolor = cx919191
         bordercollapse = collapse;
   end;
run;

proc template;
define tagset Tagsets.StatRep;
   notes "This is the StatRep LaTeX definition";

   define event initialize;
      trigger set_options;
   end;

   define event set_options;
      set $options["junk" ] "junk" /if ^$options;
      unset $cell_align;

      do /if cmp( $options["CELL_ALIGN"], "yes");
         set $cell_align "True";
      done;

   end;

   define event title_format_section;
      put value;
   end;

   define event cell_is_empty;
      put " ";
   end;

   define event list;
      start:
         put "\begin{itemize}" NL;

      finish:
         put "\end{itemize}" NL;
   end;

   define event list_item;
      put "\item ";
   end;

   define event list_entry;
      put "\item ";
   end;

   define event image;
      put "\sasgraph{";
      put BASENAME /if ^exists( NOBASE);
      put URL;
      put "}" NL;
   end;

   define event line;
      put "\rule{\linewidth}{" colwidth;
      put "pt}" NL;
   end;

   define event text;
      start:
         put "\par " NL;
   end;

   define event paragraph;
      start:
         put VALUE;
      put NL;
      put NL;
   end;

   define event preformat;
      start:
         put "\verb?" NL;

      finish:
         put "?" NL;
   end;

   define event center;
      start:
         put "\begin{center}" NL;

      finish:
         put "\end{center}" NL;
   end;

   define event styles;
      start:
         put NL;
         put "\RequirePackage[T1]{fontenc}" NL;
         put "\RequirePackage{times}" NL;
         put "\RequirePackage{fancyvrb}" NL;
         put "\RequirePackage{array}" NL;
         put "\RequirePackage{graphicx}" NL;
         put NL;
         put "\newbox\sas@fig" NL;
         put "\newlength\sas@figwidth" NL;
         put NL;
         put "\newif\ifsas@color" NL;
         put "\sas@colorfalse" NL;
         put NL;
         put "\DeclareOption{color}{\sas@colortrue}" NL;
         put "\ProcessOptions" NL;
         put NL;

      finish:
         put %nrstr("%% Set cell padding") NL;
         put "\renewcommand{\arraystretch}{1.3}" NL NL;
         put %nrstr("%% Headings") NL;
         put %nrstr("\newcommand{\sasheading}[3][c]{{%%") NL;
         put %nrstr("   \if#1r\flushright\else\if#1l\flushleft\else\centering\fi\fi%%") NL;
         put %nrstr("   {\csname sasS#2\endcsname #3}\mbox{}\\[0.1\baselineskip]%%") NL;
         put %nrstr("   \if#1r\endflushright\else\if#1l\endflushleft\else\fi\fi%%") NL;
         put "}}" NL;
         put NL;
         put "\newcommand{\sasbyline}[2][c]{\sasheading[#1]{byline}{#2}}" NL;
         put "\newcommand{\sassystemtitle}[2][c]{\sasheading[#1]{systemtitle}{#2}}" NL;
         put "\newcommand{\sassystemfooter}[2][c]{\sasheading[#1]{systemfooter}{#2}}" NL;
         put "\newcommand{\sasproctitle}[2][c]{\sasheading[#1]{proctitle}{#2}}" NL;
         put "\newcommand{\sascaption}[2][l]{\marginpar[#1]{\fbox{\parbox{0.7in}{\sasScaption{#2}}}}}" NL;
         put NL;
         put %nrstr("%% Declare new verbatim type") NL;
         put %nrstr("\DefineVerbatimEnvironment{sasverbatim}{BVerbatim}%%") NL;
         put "                          {fontsize=\footnotesize," NL;
         put "                           commandchars=\\\{\}," NL;
         put "                           formatcom=\sasSbatch}" NL;
         put NL;
         put %nrstr("%% Declare new column types") NL;
         put "\newcolumntype{S}[2]{>{\csname sasS#1\endcsname}#2}" NL;
         put "\newcolumntype{d}{r}" NL;
         put NL;
         put %nrstr("%% Set warning box style") NL;
         put "\newlength\notewidth" NL;
         put "\setlength\notewidth{4in}" NL;
         put "\newcommand*{\saswarn}[2][c]{\sasmsg{warn}{#1}{#2}}" NL;
         put "\newcommand*{\saserror}[2][c]{\sasmsg{error}{#1}{#2}}" NL;
         put "\newcommand*{\sasnote}[2][c]{\sasmsg{note}{#1}{#2}}" NL;
         put "\newcommand*{\sasfatal}[2][c]{\sasmsg{fatal}{#1}{#2}}" NL;
         put %nrstr("\newcommand*{\sasmsg}[3]{%%") NL;
         put %nrstr("   \ifsas@color\let\columncolor\undefined\fi%%") NL;
         put %nrstr("   \begin{center}%%") NL;
         put %nrstr("   \begin{tabular}{ll}\hline%%") NL;
         put %nrstr("   \multicolumn{1}{|S{#1banner}{p{0.7in}}|}{#1} & %%") NL;
         put %nrstr("   \multicolumn{1}{|S{#1content}{p{\notewidth}}|}{#3{\newline}}\\\hline%%") NL;
         put %nrstr("   \end{tabular}%%") NL;
         put %nrstr("   \end{center}%%") NL;
         put %nrstr("   \ifsas@color\let\columncolor\sascolumncolor\fi%%") NL;
         put "}" NL;
         put NL;
         put "\ifsas@color\RequirePackage{colortbl}\fi" NL;
         put NL;
         put %nrstr("%% Hack colortbl to allow \columncolor in macros") NL;
         put "\let\CT@extract@org\CT@extract" NL;
         put "\def\CT@extract{\futurelet\CT@NEXT\CT@extract@next}" NL;
         put %nrstr("\def\CT@extract@next{%%") NL;
         put "  \ifx\CT@NEXT\csname" NL;
         put %nrstr("    \@ReturnAfterFi{%%") NL;
         put "      \expandafter\expandafter\expandafter" NL;
         put %nrstr("    }%%") NL;
         put "  \fi" NL;
         put "  \CT@extract@org" NL;
         put "}" NL;
         put "\long\def\@ReturnAfterFi#1\fi{\fi#1}" NL;
         put "" NL;
         put "\ifsas@color" NL;
         put "" NL;
         put "   \newcommand{\foreground}[1]{\color[rgb]{#1}}" NL;
         put "   \newcommand{\sascolumncolor}[2][]{}" NL;
         put "   \let\columncolor\sascolumncolor" NL;
         put "   \newcommand{\documentforeground}[1]{\AtBeginDocument{\color[rgb]{#1}}}" NL;
         put "   \newcommand{\documentbackground}[1]{\AtBeginDocument{\pagecolor[rgb]{#1}}}" NL;
         put "   \def\sastable{\let\columncolor\undefined\tabular}" NL;
         put "   \def\endsastable{\endtabular\let\columncolor\sascolumncolor}" NL;
         put "   \def\stackedcell{\bgroup\renewcommand{\arraystretch}{1}\tabular}" NL;
         put "   \def\endstackedcell{\endtabular\egroup}" NL;
         put NL;
         put "\else" NL;
         put NL;
         put "   \providecommand{\foreground}[1]{}" NL;
         put "   \providecommand{\color}[2][]{}" NL;
         put "   \newcommand{\sascolumncolor}[2][]{}" NL;
         put "   \let\columncolor\sascolumncolor" NL;
         put "   \newcommand{\documentforeground}[1]{}" NL;
         put "   \newcommand{\documentbackground}[1]{}" NL;
         put "   \def\sastable{\tabular}" NL;
         put "   \def\endsastable{\endtabular}" NL;
         put "   \def\stackedcell{\bgroup\renewcommand{\arraystretch}{1}\tabular}" NL;
         put "   \def\endstackedcell{\endtabular\egroup}" NL;
         put "" NL;
         put "\fi" NL;
         put NL;
         put %nrstr("%%\let\sasgraph\includegraphics") NL;
         put %nrstr("%% Scale graphics so they always fit on the page") NL;
         put %nrstr("\newcommand\sasgraph[2][]{%%") NL;
         put %nrstr("   \savebox{\sas@fig}{\includegraphics[#1]{#2}}%%") NL;
         put %nrstr("   \settowidth{\sas@figwidth}{\usebox{\sas@fig}}%%") NL;
         put %nrstr("   \ifthenelse{\lengthtest{\sas@figwidth > \textwidth}}{%%") NL;
         put %nrstr("      \resizebox{0.95\textwidth}{!}{\usebox{\sas@fig}}}{%%") NL;
         put "      \usebox{\sas@fig}}" NL;
         put "}" NL;
         put NL;
   end;

   define event style_class;
      start:
         put "\def\sasS" lowcase(HTMLCLASS) %nrstr("{%%") NL;
         put "   " FONT_SIZE %nrstr("%%") NL /if exists( FONT_SIZE);
         put "   " FONT_WEIGHT %nrstr("%%") NL /if exists( FONT_WEIGHT);
         put "   " FONT_STYLE %nrstr("%%") NL /if exists( FONT_STYLE);
         put "   " FONT_FACE %nrstr("%%") NL /if exists( FONT_FACE);
         put "   \color[rgb]{" FOREGROUND %nrstr("}%%") NL /if exists( foreground);
         put "   \columncolor[rgb]{" BACKGROUND %nrstr("}%%") NL /if exists( background);
         set $foreground foreground /if cmp( htmlclass, "body");
         set $background background /if cmp( htmlclass, "body");

      finish:
         put "}" NL;
   end;

   define event caption;
      start:
         set $sascaption "true";
         block table;
         block row;
         block colspecs;
         block colspec_entry;
         put "\sascaption[";
         put "l" /if cmp( TYPE, "L");
         put "r" /if cmp( TYPE, "R");
         put "b" /if cmp( TYPE, "B");
         put "t" /if cmp( TYPE, "T");
         put "]{";

      finish:
         put "}" NL;
         unblock table;
         unblock row;
         unblock colspecs;
         unblock colspec_entry;
         set $sascaption "false";
   end;

   define event table;
      start:
         put NL;
         put NL;
         put "\begin{sastable}";

         trigger alignment;

      finish:
         put "\end{sastable}" NL;
         put NL;
   end;

   define event verbatim_text;
      put VALUE;
      put NL;
   end;

   define event verbatim_container;
      start:
         put NL;
         put NL;
         put "\begin{center}" NL /if cmp( just, "c");
         put "\begin{sasverbatim}" NL;

      finish:
         put "\end{sasverbatim}" NL;
         put "\end{center}" NL /if cmp( just, "c");
         put NL;
   end;

   define event alignment;
      start:
         put "[c]" /if cmp( just, "c");
      put "[c]" /if cmp( just, "d");
      put "[r]" /if cmp( just, "r");
      put "[l]" /if cmp( just, "l");
      flush;
   end;

   define event colspecs;
      start:
         put "{";

      finish:
         put "}\hline" NL;
   end;

   define event colspec_entry;
      put just /if ^cmp( just, "d");
      put "r" /if cmp( just, "d");
   end;

   define event row;

      finish:
         put NL "\\\hline" NL;
   end;

   define event rowspanfillsep;
      put %nrstr(" & ") NL;
   end;

   define event rowspancolspanfill;
      put "   ";
      put "\multicolumn{";
      put colspan;
      put "1" /if ^exists( colspan);
      put "}";
      put "{|S{";
      put lowcase(HTMLCLASS);
      put "data" /if ^htmlclass;
      put "}{";
      put just;
      put "}|}{~}";
   end;

   define event header;
      start:

         trigger data;

      finish:

         trigger data;
   end;

   define event data;
      start:
         put VALUE /if cmp( $sascaption, "true");
         break /if cmp( $sascaption, "true");
         put %nrstr(" & ") NL /if ^cmp( COLSTART, "1");
         put "   ";
         put "\multicolumn{";
         put colspan;
         put "1" /if ^colspan;
         put "}";
         put "{";
         put "|" /if ^$instacked;
         put "S{";
         put lowcase(HTMLCLASS);
         put "}{";
         put just;
         put "}";
         put "|" /if ^$instacked;
         put "}";
         put "{";
         put tranwrd(VALUE,"-","$-$") /if contains( lowcase(HTMLCLASS), "data");
         put VALUE /if ^contains( lowcase(HTMLCLASS), "data");

      finish:
         break /if cmp( $sascaption, "true");
         put "}";
   end;

   define event data_note;
      start:

         trigger data;

      finish:

         trigger data;
   end;

   define event stacked_cell;
      start:
         put NL;
         put "\begin{stackedcell}";

         trigger alignment;

      finish:
         put "\end{stackedcell}" NL;
   end;

   define event stacked_value;
      start:
         unset $instacked;
         set $instacked "true";

         trigger data;

      finish:

         trigger data;
         unset $instacked;
   end;

   define event stacked_value_header;
      start:

         trigger stacked_value;

      finish:

         trigger stacked_value;
   end;

   define event stacked_cell_colspecs;
      start:
         put "{";

      finish:
         put "}" NL;
   end;

   define event stacked_cell_colspec_entry;
      put just /if ^cmp( just, "d");
      put "r" /if cmp( just, "d");
   end;

   define event stacked_cell_row;

      finish:
         put NL "\\" NL;
   end;

   define event put_value;
      put VALUE;
   end;

   define event put_value_cr;
      put VALUE NL;
   end;

   define event byline;
      put NL;
      put "\sasbyline";

      trigger alignment;
      put "{";
      put VALUE;
      put "}" NL;
   end;

   define event proc_title;
      put "\sasproctitle";

      trigger alignment;
      put "{";
      put VALUE;
      put "}" NL;
   end;

   define event note;
      put "\sasnote";

      trigger alignment;
      put "{";
      put VALUE;
      put "}" NL;
   end;

   define event Error;
      put "\saserror";

      trigger alignment;
      put "{";
      put VALUE;
      put "}" NL;
   end;

   define event Warn;
      put "\saswarn";

      trigger alignment;
      put "{";
      put VALUE;
      put "}" NL;
   end;

   define event Fatal;
      put "\sasfatal";

      trigger alignment;
      put "{";
      put VALUE;
      put "}" NL;
   end;

   define event system_title;
      put "\sassystemtitle";

      trigger alignment;
      put "{";
      put VALUE;
      put "}" NL;
   end;

   define event system_footer;
      put "\sassystemfooter";

      trigger alignment;
      put "{";
      put VALUE;
      put "}" NL;
   end;

   image_formats = "png,pdf";
   split = " {\newline} ";
   nobreakspace = "~";
   mapsub = %nrstr("/\%%/\$/\&/\{/\}/\~/\^/\#/{\textunderscore}/{\textbackslash}/");
   map = %nrstr("%%$&{}~^#_\");
   output_type = "latex";
   stacked_columns = OFF;
   embedded_stylesheet;
   private;
end;
run;