File: fixtex.sl

package info (click to toggle)
slsqlite 0.6.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 604 kB
  • sloc: sh: 3,107; ansic: 1,065; makefile: 186
file content (136 lines) | stat: -rw-r--r-- 2,445 bytes parent folder | download | duplicates (10)
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
%quit_jed;

% Version 0.3.1-0
!if (is_defined ("__argv"))
{
   message ("You need a newer version of jed to run this script");
   quit_jed ();
}

if (__argc != 4)
{
   message ("Usage: jed -script fixtex.sl <filename>");
   quit_jed ();
}

variable file = __argv[3];
() = read_file (file);

% Patch up the >,< signs
bob ();
replace ("$<$", "<");
replace ("$>$", ">");

% It appears that sgml2tex screws up _for in section titles, producing \_{for}.
replace ("ion\\_{", "ion{\\_");

% Make the first chapter a preface
bob ();
if (bol_fsearch ("\\chapter{Preface}"))
{
   push_spot ();
   push_mark ();
   go_right (8); insert ("*");	       %  \chapter{ --> \chapter*{
   () = bol_fsearch ("\\chapter{");
   push_spot ();

   insert("\\tableofcontents\n");
   eol ();
   insert ("\n\\pagenumbering{arabic}");

   pop_spot ();
   narrow ();
   bob ();
   replace ("\\section{", "\\section*{");
   widen ();

   if (bol_bsearch ("\\tableofcontents"))
     delete_line ();
   
   pop_spot ();
   if (bol_bsearch ("\\maketitle"))
     insert ("\\pagenumbering{roman}\n");

}

static define fixup_urldefs ()
{
   % pdflatex cannot grok urldef
   bob ();
   while (bol_fsearch("\\urldef{") and ffind ("\\url{"))
     {
	variable line = line_as_string ();
	bol ();
	insert ("\\ifpdf\n");
	
	deln (7); insert ("\\newcommand");
	push_mark ();
	()=ffind ("}");
	variable macro = bufsubstr ();
	() = ffind ("\\url");
	go_left (1);
	trim ();
	insert("{");

	% pdflatex cannot grok # in urls.  Nuke em.
	if (ffind ("#"))
	  {
	     del_eol ();
	     insert ("}");
	  }
	eol ();
	insert ("}\n\\else\n");
	insert (line); newline ();
	insert ("\\fi\n");
     }
}

static define remove_repeated_urls ()
{
   variable name, url;
   variable names = Assoc_Type[Int_Type, 0];
   while (bol_fsearch ("{\\em "))
     {
	go_right (4);
	skip_white ();
	push_mark ();
	() = ffind ("}");
	!if (looking_at ("} {\\tt "))
	  {
	     pop_mark(0); 
	     continue;
	  }
	name = bufsubstr ();
	if (names[name])
	  {
	     go_right(1);
	     push_mark ();
	     () = ffind ("}");
	     go_right(1);
	     del_region ();
	  }
	else
	  {
	     names[name] = 1;
	     go_right(1);
	     () = ffind ("}");
	     go_right (1);
	  }

	% Now remove empty lines inserted by the broken sgml2latex program.
	skip_white ();
	!if (eolp ())
	  continue;
	go_right(1);
	skip_white ();
	if (eolp ())
	  del ();
     }
}

fixup_urldefs ();
remove_repeated_urls ();
save_buffer ();
quit_jed ();