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
|
%quit_jed;
!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("{");eol(); insert("}");
insert ("\n\\else\n");
insert (line); newline ();
%insert ("\\newcommand"); insert(macro); insert("}{}\n");
insert ("\\fi\n");
}
}
fixup_urldefs ();
save_buffer ();
quit_jed ();
|