-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtr2latex
3579 lines (3375 loc) · 87.1 KB
/
tr2latex
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
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Path: uunet!rs
From: [email protected] (Rich Salz)
Newsgroups: comp.sources.unix
Subject: v10i032: Translate troff to LaTex
Message-ID: <[email protected]>
Date: 2 Jul 87 03:05:04 GMT
Organization: UUNET Communications Services, Arlington, VA
Lines: 3569
Approved: [email protected]
Mod.Sources: Volume 10, Number 32
Submitted by: Kamal Al-Yahya <[email protected]>
Archive-name: tr2latex
This program translates troff documents to latex. You will notice that the
translation is not always 100%, but it relieves one from manual translation,
where the user might need to touch up on the translated document to customize
the translation.
There is a testfile and a manual page in the package that can be used
to test the translator. Try some UNIX manual pages too.
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
# tr2tex.c
# tr.c
# subs.c
# setups.h
# simil.h
# greek.h
# flip.h
# forbid.h
# macros.h
# maths.h
# makefile
# makefile.msc
# troffms.sty
# troffman.sty
# tr2tex.9
# tr2tex.9-tex-orig
# README
# testfile
# testfile.tex-orig
# diffs.tex
# This archive created: Sun Mar 8 12:05:26 1987
export PATH; PATH=/bin:$PATH
if test -f 'tr2tex.c'
then
echo shar: will not over-write existing file "'tr2tex.c'"
else
cat << \SHAR_EOF > 'tr2tex.c'
/* COPYRIGHT (C) 1987 Kamal Al-Yahya */
/* tr2tex: troff to tex translator */
/* Author: Kamal Al-Yahya, Stanford University, 9/4/86 */
/* Last modified: 1/1/87 */
/* Keyword: convert translate tex troff */
char *documentation[] = {
" SYNTAX",
" tr2tex [-m] file1 file2 ...",
"or",
" tr2tex [-m] < file1 file2 ...",
"",
" Use the -m flag for manual",
"",
};
int doclength = { sizeof documentation/sizeof documentation[0] };
#include "setups.h"
#ifdef tops20
#define TEMPFILE "texXXXXXX"
#else
#define TEMPFILE "/tmp/texXXXXXX"
#endif
FILE *out_file;
#if HAVE_SGTTY
struct sgttyb ttystat;
#endif
extern char *mktemp();
char scratch_file[MAXWORD];
int man;
int xargc;
char **xargv;
int
main(argc,argv)
int argc;
char *argv[];
{
char *inbuf, *outbuf;
FILE *temp,*scr;
register char *cptr;
int piped_in;
int i;
long timeval; /* clock value from time() for ctime() */
char *document = "article"; /* document type */
char *options = "[troffms,11pt]"; /* style options */
/* Allocate large arrays dynamically to conserve stack space */
if (((inbuf = (char *)malloc(MAXLEN*sizeof(char))) == (char *)NULL) ||
((outbuf = (char *)malloc(MAXLEN*sizeof(char))) == (char *)NULL))
{
fprintf(stderr,"tr2tex: Cannot malloc() internal buffer space\n\
Need two arrays of %d characters each\n",MAXLEN);
exit(-1);
}
/* If no arguments, and not in a pipeline, self document */
#if HAVE_SGTTY
piped_in = ioctl ((fileno (stdin)), TIOCGETP, &ttystat);
#else /* if no sggty, it cannot distinguish piped input from no input */
piped_in = (argc == 1);
#endif
if (argc == 1 && !piped_in)
{
for( i=0; i<doclength; i++)
printf("%s\n",documentation[i]);
exit (0);
}
/* initialize spacing and indentation parameters */
strcpy(linespacing.def_units,"\\normalbaselineskip");
strcpy(linespacing.old_units,"\\normalbaselineskip");
strcpy(indent.def_units,"em"); strcpy(indent.old_units,"em");
strcpy(tmpind.def_units,"em"); strcpy(tmpind.old_units,"em");
strcpy(space.def_units,"\\baselineskip");
strcpy(space.old_units,"\\baselineskip");
strcpy(vspace.def_units,"pt"); strcpy(vspace.old_units,"pt");
linespacing.value = 1.; linespacing.old_value = 1.;
indent.value = 0.; indent.old_value = 0.;
tmpind.value = 0.; tmpind.old_value = 0.;
space.value = 1.; space.old_value = 1.;
vspace.value = 1.; vspace.old_value = 1.;
linespacing.def_value = 0;
indent.def_value = 0;
tmpind.def_value = 0;
space.def_value = 1;
vspace.def_value = 1;
out_file = stdout; /* default output */
math_mode = 0; /* start with non-math mode */
de_arg = 0; /* not a .de argument */
/* process option flags */
xargc = argc;
xargv = argv;
for (xargc--,xargv++; xargc; xargc--,xargv++)
{
cptr = *xargv;
if( *cptr=='-' )
{
while( *(++cptr))
{
switch( *cptr )
{
case 'm':
man = 1;
strcpy(options,"[troffman]");
break;
default:
fprintf(stderr,
"tr2tex: unknown flag -%c\n",*cptr);
break;
}
}
}
}
/* start of translated document */
timeval = time(0);
fprintf(out_file,"%% -*-LaTeX-*-\n\
%% Converted automatically from troff to LaTeX by tr2tex on %s",ctime(&timeval));
fprintf(out_file,"%% tr2tex was written by Kamal Al-Yahya at Stanford University\n\
%% (Kamal%%[email protected])\n\n\n");
/* document style and options */
fprintf(out_file,"\\documentstyle%s{%s}\n\\begin{document}\n",options,document);
/* first process pipe input */
if(piped_in)
{
/* need to buffer; can't seek in pipes */
/* make a temporary and volatile file */
strcpy(scratch_file,TEMPFILE);
mktemp(scratch_file);
if ((scr=fopen(scratch_file,"w")) == (FILE *)NULL)
{
fprintf(stderr,
"tr2tex: Cannot open scratch file [%s]\n",scratch_file);
exit(-1);
}
scrbuf(stdin,scr);
fclose(scr);
scr=fopen(scratch_file,"r");
unlink(scratch_file);
tmpbuf(scr,inbuf);
fclose(scr);
troff_tex(inbuf,outbuf,0,0);
fprintf(out_file,"%%\n%% input file: stdin\n%%\n");
fputs(outbuf,out_file);
}
/* then process input line for arguments and assume they are input files */
xargc = argc;
xargv = argv;
for (xargc--,xargv++; xargc; xargc--,xargv++)
{
cptr = *xargv;
if( *cptr=='-' ) continue; /* this is a flag */
if((temp=fopen(cptr,"r")) != (FILE *)NULL)
{
tmpbuf(temp,inbuf);
fclose(temp);
troff_tex(inbuf,outbuf,0,0);
fprintf(out_file,"%%\n%% input file: %s\n%%\n",cptr);
fputs(outbuf,out_file);
}
else
fprintf(stderr,"tr2tex: Cannot open %s\n",cptr);
}
/* close translated document */
fputs("\\end{document}\n",out_file);
exit(0);
}
SHAR_EOF
fi # end of overwriting check
if test -f 'tr.c'
then
echo shar: will not over-write existing file "'tr.c'"
else
cat << \SHAR_EOF > 'tr.c'
/* COPYRIGHT (C) 1987 Kamal Al-Yahya */
/*
This program has the HARD-WIRED rules of the translator.
It should handled with care.
*/
#define IN_TR 1
#include "setups.h"
int def_count = 0;
int mydef_count = 0;
void
troff_tex(inbuf,outbuf,mid,rec)
char *inbuf,*outbuf;
int mid,rec;
{
char eqn_no[MAXWORD], w[MAXWORD], ww[MAXLINE], tmp[MAXWORD], tmp2[MAXWORD];
char *p;
int len,c,c1,c2,i,j;
int ref = 0;
int put_brace = 0;
int first_word = 1;
int no_word = 1;
int arg = 0;
int par = 0;
int illegal = 0;
int floating = 0;
static int delim_defd = 0; /* whether math delimiter has been defined */
static char *DELIM = "$";
float flen;
int N;
int RSRE = 0; /* block indentation */
int thisfont = 1; /* default font is roman */
int lastfont = 1; /* default last font is roman */
int offset = 0; /* amount to offset inbuf */
extern man; /* man flag */
*outbuf = NULL; w[0] = NULL; ww[0] = NULL;
tmp[0] = NULL; tmp2[0] = NULL;
while (*inbuf != NULL)
{
len = getword(inbuf,w);
c1 = *--inbuf;
c2 = *++inbuf;
inbuf += len;
if (isspace(w[0]) == 0) no_word = 0;
/* first check if we are in math mode */
if (math_mode)
{
len = get_till_space(inbuf,ww);
sprintf(tmp,"%s%s",w,ww);
if (strcmp(w,"delim") == 0)
{
delim_defd = 1;
inbuf += skip_white(inbuf);
DELIM[0] = *inbuf;
inbuf = skip_line(inbuf);
}
/* check if it is a math delimiter; switch to non-math mode if so */
else if (delim_defd && strcmp(w,DELIM) == 0)
{
math_mode = 0;
*outbuf++ = '$';
}
/* check for illegal macros here */
else if (len > 0 && def_count > 0 && (i=is_def(tmp)) >= 0)
{
inbuf += len;
outbuf = strapp(outbuf,def[i].replace);
}
/* See if it is a (legally) defined macro */
else if (def_count > 0 && (i=is_def(w)) >= 0)
{
if (def[i].illegal)
outbuf = strapp(outbuf,def[i].replace);
else
{
outbuf = strapp(outbuf,"\\");
outbuf = strapp(outbuf,w);
}
}
/* Search for commands in some order; start with non-alphanumeric symbols */
else if (strcmp(w,"#") == 0 || strcmp(w,"&") == 0
|| strcmp(w,"%") == 0 || strcmp(w,"_") == 0)
{
outbuf = strapp(outbuf,"\\");
outbuf = strapp(outbuf,w);
}
else if (strcmp(w,"=") == 0)
{
if (*inbuf == '=')
{
inbuf++;
outbuf = strapp(outbuf,"\\equiv");
}
else
outbuf = strapp(outbuf,"=");
}
else if (strcmp(w,"<") == 0 || strcmp(w,">") == 0)
{
if (*inbuf == '=')
{
inbuf++;
if (strcmp(w,"<") == 0)
outbuf = strapp(outbuf,"\\le");
else
outbuf = strapp(outbuf,"\\ge");
}
}
else if (strcmp(w,"-") == 0)
{
if (*inbuf == '>')
{
inbuf++;
outbuf = strapp(outbuf,"\\to");
}
else if (*inbuf == '+')
{
inbuf++;
outbuf = strapp(outbuf,"\\mp");
}
else
*outbuf++ = '-';
}
else if (strcmp(w,"+") == 0)
{
if (*inbuf == '-')
{
inbuf++;
outbuf = strapp(outbuf,"\\pm");
}
else
*outbuf++ = '+';
}
else if (strcmp(w,"\"") == 0)
{
len = get_no_math(inbuf,ww);
inbuf += len+1;
if (len > 1)
{
sprintf(tmp,"\\ \\it\\hbox{%s}",ww);
outbuf = strapp(outbuf,tmp);
}
else if (len == 1)
*outbuf++ = ww[0];
}
/* Now search for symbols that start with a captial */
else if (strcmp(w,".EN") == 0)
{
math_mode = 0;
if ((len=strlen(eqn_no)) > 0)
{
sprintf(tmp,"\\eqno %s",eqn_no);
outbuf = strapp(outbuf,tmp);
}
eqn_no[0] = NULL;
c1 = *--outbuf;
c2 = *--outbuf;
if (c1 == '\n' && c2 == '$')
*--outbuf = NULL;
else
{
outbuf += 2;
outbuf = strapp(outbuf,"$$");
}
}
/* Now search for symbols that start with a small letter */
else if (strcmp(w,"bold") == 0 || strcmp(w,"roman") == 0 ||
strcmp(w,"italic") == 0)
{
inbuf += get_arg(inbuf,ww,1);
if (strcmp(w,"bold") == 0)
{
sprintf(tmp,"{\\bf %s}",ww);
outbuf = strapp(outbuf,tmp);
}
else if (strcmp(w,"roman") == 0)
{
sprintf(tmp,"{\\rm %s}",ww);
outbuf = strapp(outbuf,tmp);
}
else
{
sprintf(tmp,"{\\it %s}",ww);
outbuf = strapp(outbuf,tmp);
}
}
else if (strcmp(w,"define") == 0)
{
if (def_count >= MAXDEF)
{
fprintf(stderr,
"Too many defines. MAXDEF=%d\n",MAXDEF);
exit(-1);
}
for (i=0; *--outbuf != '$' && i < MAXLEN; i++)
tmp[i] = *outbuf;
tmp[i] = NULL;
strcat(tmp,"$$");
*--outbuf = NULL;
inbuf += skip_white(inbuf);
inbuf += get_defword(inbuf,w,&illegal);
inbuf += skip_white(inbuf);
inbuf += getdef(inbuf,ww);
if (illegal)
{
def[def_count].illegal = 1;
fprintf(stderr,
"illegal TeX macro, %s, replacing it\n",w);
p = (char *)malloc((unsigned)(strlen(ww)+1)*
sizeof(char));
strcpy(p,ww);
def[def_count].replace = p;
}
else
{
def[def_count].illegal = 0;
sprintf(tmp2,"\\def\\%s{%s}\n",w,ww);
outbuf = strapp(outbuf,tmp2);
}
p = (char *)malloc((unsigned)(strlen(w)+1)*sizeof(char));
strcpy(p,w);
def[def_count++].def_macro = p;
inbuf += skip_white(inbuf);
for (j=i+1; j >= 0; j--)
*outbuf++ = tmp[j];
tmp[0] = NULL;
}
else if (strcmp(w,"gsize") == 0 || strcmp(w,"gfont") == 0)
inbuf = skip_line(inbuf);
else if (strcmp(w,"left") == 0 || strcmp(w,"right") == 0)
{
sprintf(tmp,"\\%s",w);
outbuf = strapp(outbuf,tmp);
inbuf += skip_white(inbuf);
len = getword(inbuf,ww);
if (strcmp(ww,"floor") == 0)
{
inbuf += len;
if (strcmp(w,"left") == 0)
outbuf = strapp(outbuf,"\\lfloor");
else
outbuf = strapp(outbuf,"\\rfloor");
}
else if (strcmp(ww,"nothing") == 0 || ww[0] == '\"')
{
inbuf += len;
*outbuf++ = '.';
if (ww[0] == '\"') inbuf++;
}
else if (*inbuf == '{' || *inbuf == '}')
*outbuf++ = '\\';
}
else if (strcmp(w,"over") == 0)
{
if (!first_word)
{
outbuf--;
for (i=0; *outbuf == ' ' || *outbuf == '\t' ||
*outbuf =='\n'; i++)
tmp[i] = *outbuf--;
if (*outbuf == '}' && put_brace == 0)
*outbuf = ' ';
else
{
for (; !(*outbuf == ' ' || *outbuf == '\t'
|| *outbuf =='\n' || *outbuf == '$'); i++)
tmp[i] = *outbuf--;
put_brace = 0;
*++outbuf = '{';
}
for (j=i-1; j >= 0; j--)
*++outbuf = tmp[j];
*++outbuf = NULL;
}
outbuf = strapp(outbuf,"\\over");
inbuf += skip_white(inbuf);
*outbuf++ = ' ';
if (*inbuf == '{')
inbuf++;
else
{
inbuf = get_over_arg(inbuf,ww);
outbuf = strapp(outbuf,ww);
if (*inbuf != NULL || !first_word)
*outbuf++ = '}';
}
}
else if (strcmp(w,"size") == 0)
inbuf += get_arg(inbuf,ww,0);
else if (strcmp(w,"sup") == 0 || strcmp(w,"to") == 0 ||
strcmp(w,"sub") == 0 || strcmp(w,"from") == 0)
{
while ((c = *--outbuf) == ' ' || c == '\t' || c == '\n') ;
*++outbuf = NULL;
if (strcmp(w,"sup") == 0 || strcmp(w,"to") == 0)
outbuf = strapp(outbuf,"^");
else
outbuf = strapp(outbuf,"_");
inbuf += skip_white(inbuf);
len = get_sub_arg(inbuf,ww);
inbuf += len;
if (len > 1)
{
sprintf(tmp,"{%s}",ww);
outbuf = strapp(outbuf,tmp);
len = skip_white(inbuf);
inbuf += len;
(void) getword(inbuf,ww);
if (strcmp(ww,"over") == 0)
put_brace = 1;
inbuf -= len;
}
else
outbuf = strapp(outbuf,ww);
}
else if (strcmp(w,"up") == 0 || strcmp(w,"down") == 0
|| strcmp(w,"fwd") == 0 || strcmp(w,"back") == 0)
{
if (strcmp(w,"up") == 0)
{
outbuf = strapp(outbuf,"\\raise");
strcpy(tmp,"ex");
}
else if (strcmp(w,"down") == 0)
{
outbuf = strapp(outbuf,"\\lower");
strcpy(tmp,"ex");
}
else if (strcmp(w,"fwd") == 0)
{
outbuf = strapp(outbuf,"\\kern");
strcpy(tmp,"em");
}
else if (strcmp(w,"back") == 0)
{
outbuf = strapp(outbuf,"\\kern-");
strcpy(tmp,"em");
}
inbuf += skip_white(inbuf);
inbuf += getword(inbuf,ww);
len = atoi(ww); flen = len/100.;
ww[0] = NULL;
sprintf(tmp2,"%4.2f%s",flen,tmp);
outbuf = strapp(outbuf,tmp2);
}
/* Now check if the word is a member of a group */
else if (CAP_GREEK(w) > 0)
{
GR_to_Greek(w,ww);
outbuf = strapp(outbuf,ww);
}
else if (is_flip(w) >= 0)
{
if (!first_word)
{
len = skip_white(inbuf);
inbuf += len;
(void) getword(inbuf,ww);
if (is_flip(ww) >= 0)
{
inbuf += strlen(ww);
outbuf = flip_twice(outbuf,w,ww);
}
else
{
inbuf -= len;
outbuf = flip(outbuf,w);
}
}
else
{
outbuf = strapp(outbuf,"\\");
outbuf = strapp(outbuf,w);
}
}
else if (is_mathcom(w,ww) >=0 )
outbuf = strapp(outbuf,ww);
else if (similar(w) > 0)
{
outbuf = strapp(outbuf,"\\");
outbuf = strapp(outbuf,w);
}
/* if none of the above math commands matched, it is an ordinary symbol;
just copy it */
else outbuf = strapp(outbuf,w);
}
/* check if it is a math delimiter; switch to math mode if so */
else if (strcmp(w,"$") == 0 && de_arg > 0)
{
de_arg++;
*outbuf++ = '#';
}
else if (delim_defd && strcmp(w,DELIM) == 0)
{
math_mode = 1;
*outbuf++ = '$';
}
else if (strcmp(w,"$") == 0)
outbuf = strapp(outbuf,"\\$");
/* check if it is a non-math troff command */
else if ((c2 == '.') && !(mid) && (c1 == '\n' || (first_word)))
{
/* Search in some order; start with non-alphanumeric characters */
if (strcmp(w,".") == 0)
{
c1 = *inbuf;
c2 = *++inbuf;
if (c1 == '\\' && c2 == '\"')
{
++inbuf;
inbuf += get_line(inbuf,ww,0);
outbuf = strapp(outbuf,"%");
outbuf = strapp(outbuf,ww);
}
else
{
fprintf(stderr,
"I cannot translate troff macro .%c%c\n",c1,c2);
inbuf += get_line(inbuf,ww,0);
sprintf(tmp,"%%.%c%c",c1,c2);
outbuf = strapp(outbuf,tmp);
outbuf = strapp(outbuf,ww);
if (*inbuf == NULL) *outbuf++ = '\n';
}
}
/* Now search for commads that start with a capital */
else if (strcmp(w,".AB") == 0)
{
inbuf += get_arg(inbuf,ww,0);
if (strcmp(ww,"no") == 0)
outbuf = strapp(outbuf,"\\bigskip");
else
outbuf = strapp(outbuf,"\\begin{abstract}");
}
else if (strcmp(w,".B") == 0 || strcmp(w,".bf") == 0 ||
strcmp(w,".I") == 0 || strcmp(w,".it") == 0 ||
strcmp(w,".R") == 0 || strcmp(w,".rm") == 0)
{
if (strcmp(w,".R") == 0 || strcmp(w,".rm") == 0)
strcpy(w,"rm");
else if (strcmp(w,".B") == 0 || strcmp(w,".bf") == 0)
strcpy(w,"bf");
else
strcpy(w,"it");
inbuf += get_arg(inbuf,ww,1);
if (ww[0] == NULL)
{
outbuf = strapp(outbuf,"\\");
outbuf = strapp(outbuf,w);
}
else
{
sprintf(tmp,"{\\%s %s}",w,ww);
outbuf = strapp(outbuf,tmp);
}
}
else if (man && (strcmp(w,".BR") == 0 || strcmp(w,".BI") == 0
|| strcmp(w,".IR") == 0 || strcmp(w,".IB") == 0 ||
strcmp(w,".RI") == 0 || strcmp(w,".RB") == 0))
{
outbuf = alternate(inbuf,outbuf,w);
inbuf = skip_line(inbuf);
*outbuf++ = '\n';
}
else if (strcmp(w,".BX") == 0)
{
inbuf += get_arg(inbuf,ww,1);
sprintf(tmp,"\\fbox{%s}",ww);
outbuf = strapp(outbuf,tmp);
}
else if (strcmp(w,".EQ") == 0)
{
math_mode = 1;
put_brace = 0;
outbuf = strapp(outbuf,"$$");
len = get_arg(inbuf,eqn_no,0);
if (strcmp(eqn_no,"I") == 0 || strcmp(eqn_no,"L") == 0)
{
fprintf(stderr,"lineups are ignored\n");
inbuf += len;
len = get_arg(inbuf,eqn_no,0);
}
if ((strlen(eqn_no)) > 0)
inbuf += len;
len = get_arg(inbuf,tmp,0);
if (strcmp(tmp,"I") == 0 || strcmp(tmp,"L") == 0)
{
fprintf(stderr,"lineups are ignored\n");
inbuf += len;
}
}
else if (strcmp(w,".IP") == 0)
{
inbuf += get_arg(inbuf,ww,1);
inbuf = skip_line(inbuf);
if (IP_stat == 0)
outbuf = strapp(outbuf,"\\begin{itemize}\n");
sprintf(tmp,"\\item[{%s}]\n",ww);
outbuf = strapp(outbuf,tmp);
if (de_arg > 0) mydef[mydef_count].par = 2;
else IP_stat = 1;
}
else if (strcmp(w,".KE") == 0)
{
if (floating)
outbuf = strapp(outbuf,"\\end{figure}");
else
outbuf = strapp(outbuf,"}");
floating = 0;
}
else if (strcmp(w,".KF") == 0)
{
floating = 1;
outbuf = strapp(outbuf,"\\begin{figure}");
}
else if (strcmp(w,".QP") == 0)
{
if (de_arg > 0) mydef[mydef_count].par = 4;
else QP_stat = 1;
outbuf = strapp(outbuf,"\\begin{quotation}");
}
else if (strcmp(w,".RE") == 0)
{
RSRE--;
if (RSRE < 0)
fprintf(stderr,".RS with no matching .RE\n");
sprintf(tmp,"\\ind{%d\\parindent}",RSRE);
outbuf = strapp(outbuf,tmp);
}
else if (strcmp(w,".RS") == 0)
{
RSRE++;
sprintf(tmp,"\\ind{%d\\parindent}",RSRE);
outbuf = strapp(outbuf,tmp);
}
else if (strcmp(w,".Re") == 0)
{
if (ref == 0)
outbuf = strapp(outbuf,"\\REF\n");
ref++;
inbuf = skip_line(inbuf);
inbuf += get_ref(inbuf,ww);
sprintf(tmp,"\\reference{%s}",ww);
outbuf = strapp(outbuf,tmp);
}
else if (man && (strcmp(w,".TP") == 0 || strcmp(w,".HP") == 0))
{
if (IP_stat && TP_stat)
{
outbuf = strapp(outbuf,"\\end{itemize}%\n");
IP_stat = 0;
}
if (QP_stat && TP_stat)
{
outbuf = strapp(outbuf,"\\end{quotation}%\n");
QP_stat = 0;
}
inbuf = skip_line(inbuf);
inbuf += get_line(inbuf,ww,1);
if (TP_stat == 0)
{
sprintf(tmp,"\\begin{TPlist}{%s}\n",ww);
outbuf = strapp(outbuf,tmp);
}
sprintf(tmp,"\\item[{%s}]",ww);
outbuf = strapp(outbuf,tmp);
if (de_arg > 0) mydef[mydef_count].par = 3;
else TP_stat = 1;
}
else if (man && (strcmp(w,".TH") == 0))
{
/* expect something like .TH LS 1 "September 4, 1985"*/
outbuf = strapp(outbuf,"\\phead");
for (j = 1; j <= 3; ++j)
{
inbuf += get_arg(inbuf,ww,0);
sprintf(tmp,"{%s}",ww);
outbuf = strapp(outbuf,tmp);
}
*outbuf++ = '\n';
}
else if (strcmp(w,".TS") == 0)
{
fprintf(stderr,"I am not very good at tables\n\
I can only do very simple ones. You may need to check what I've done\n");
inbuf = skip_line(inbuf);
outbuf = do_table(inbuf,outbuf,&offset);
inbuf += offset;
offset = 0; /* reset */
}
/* Now search for commands that start with small letters */
else if (strcmp(w,".TE") == 0)
{
fprintf(stderr,"Oops! I goofed. I told you I am not very good at tables.\nI have encountered a table end but I am not in table mode\n");
}
else if (strcmp(w,".de") == 0)
{
de_arg = 1;
if (mydef_count >= MAXDEF)
{
fprintf(stderr,
"Too many .de's. MAXDEF=%d\n",MAXDEF);
exit(-1);
}
inbuf += skip_white(inbuf);
inbuf += get_defword(inbuf,w,&illegal);
inbuf += skip_white(inbuf);
inbuf += get_mydef(inbuf,ww);
mydef[mydef_count].arg_no = de_arg;
if (illegal)
{
mydef[mydef_count].illegal = 1;
fprintf(stderr,
"illegal TeX macro, %s, replacing it\n",w);
p = (char *)malloc((unsigned)(strlen(ww)+2)*
sizeof(char));
sprintf(p,"%s",ww);
mydef[mydef_count].replace = p;
}
else
{
mydef[mydef_count].illegal = 0;
sprintf(tmp,"\\def\\%s",w);
outbuf = strapp(outbuf,tmp);
for (j=1; j<de_arg; j++)
{
sprintf(tmp,"#%d",j);
outbuf = strapp(outbuf,tmp);
}
sprintf(tmp,"{%s}\n",ww);
outbuf = strapp(outbuf,tmp);
}
p = (char *)malloc((unsigned)(strlen(w)+2)*sizeof(char));
sprintf(p,".%s",w);
mydef[mydef_count++].def_macro = p;
inbuf = skip_line(inbuf);
de_arg = 0;
}
else if (strcmp(w,".ds") == 0)
{
inbuf += get_arg(inbuf,w,0);
inbuf += skip_white(inbuf);
inbuf += get_line(inbuf,ww,1);
if (strcmp(w,"LH") == 0)
{
sprintf(tmp,"\\lefthead{%s}",ww);
outbuf = strapp(outbuf,tmp);
}
else if (strcmp(w,"RH") == 0)
{
sprintf(tmp,"\\righthead{%s}",ww);
outbuf = strapp(outbuf,tmp);
}
else if (strcmp(w,"CF") == 0)
{
if (index(ww,'%') == 0)
{
sprintf(tmp,"\\footer{%s}",ww);
outbuf = strapp(outbuf,tmp);
}
else
outbuf = strapp(outbuf,
"\\footer{\\rm\\thepage}");
}
else
{
fprintf(stderr,"I do not understand .ds %s\n",w);
sprintf(tmp,"%%.ds %s %s",w,ww);
outbuf = strapp(outbuf,tmp);
}
}
else if (strcmp(w,".sp") == 0)
{
inbuf += get_arg(inbuf,ww,0);
(void) get_size(ww,&space);
sprintf(tmp,"\\par\\vspace{%3.1f%s}",
space.value,space.units);
outbuf = strapp(outbuf,tmp);
}
else if (strcmp(w,".in") == 0)
{
inbuf += get_arg(inbuf,ww,0);
(void) get_size(ww,&indent);
sprintf(tmp,"\\ind{%3.1f%s}",indent.value,indent.units);
outbuf = strapp(outbuf,tmp);
}
else if (strcmp(w,".ls") == 0)
{
inbuf += get_arg(inbuf,ww,0);
(void) get_size(ww,&linespacing);
sprintf(tmp,"\\baselineskip=%3.1f%s",linespacing.value,
linespacing.units);
outbuf = strapp(outbuf,tmp);
}
else if (strcmp(w,".so") == 0)
{
inbuf += get_arg(inbuf,ww,0);
sprintf(tmp,"\\input %s",ww);
outbuf = strapp(outbuf,tmp);
}
else if (strcmp(w,".ti") == 0)
{
inbuf += get_arg(inbuf,ww,0);
tmpind.value = indent.value;
strcpy(tmpind.units,indent.units);
(void) get_size(ww,&tmpind);
sprintf(tmp,"\\tmpind{%3.1f%s}",
tmpind.value,tmpind.units);
outbuf = strapp(outbuf,tmp);
}
else if (strcmp(w,".vs") == 0)
{
inbuf += get_arg(inbuf,ww,0);
(void) get_size(ww,&vspace);
sprintf(tmp,"\\par\\vspace{%3.1f%s}",
vspace.value,vspace.units);
outbuf = strapp(outbuf,tmp);
}
/* check if it is a member of a group */
else if (mydef_count > 0 && (i=is_mydef(w)) >= 0)
{
if (mydef[i].par > 0)
{
if (de_arg > 0)
mydef[mydef_count].par = mydef[i].par;
else
{
outbuf = end_env(outbuf);
outbuf = strapp(outbuf,"\n");
}
}
if (mydef[i].illegal)
outbuf = strapp(outbuf,mydef[i].replace);
else
{
w[0] = '\\'; /* replace dot by backslash */
outbuf = strapp(outbuf,w);
}
for (j=1; j <mydef[i].arg_no; j++)
{
inbuf += get_arg(inbuf,ww,1);
sprintf(tmp,"{%s}",ww);
outbuf = strapp(outbuf,tmp);
}
if (de_arg == 0) envoke_stat(mydef[i].par);
}