-- TeXFixes.tioga of April 11, 1984 8:14:29 pm PST --- Stolfi
-- Does several simple replacements for conversion to new TEX macros
(as of October 13, 1983 4:46 pm)

SaveSelectionA
MatchLiterally MatchCase MatchAnywhere DoReplace
SearchFor "\\cr\\va" ReplaceBy "\\cr\\vsk3" DoSubstitute
SearchFor "\\cr\\vb" ReplaceBy "\\cr\\vsk4" DoSubstitute
SearchFor "\\cr\\vc" ReplaceBy "\\cr\\vsk6" DoSubstitute
SearchFor "\\cr\\vd" ReplaceBy "\\cr\\vsk8" DoSubstitute
SearchFor "\\equiv" ReplaceBy "\\eqv" DoSubstitute
SearchFor "\\txiff" ReplaceBy "\\rmiff" DoSubstitute
SearchFor "\\txand" ReplaceBy "\\rmand" DoSubstitute
SearchFor "\\rpike" ReplaceBy "\\rpoint" DoSubstitute
SearchFor "\\ctrline" ReplaceBy "\\ctrpar\\textwidth pt" DoSubstitute
SearchFor "\\ety" ReplaceBy "\\empty" DoSubstitute
SearchFor "\\lpike" ReplaceBy "\\lpoint" DoSubstitute
SearchFor "\174" ReplaceBy "\026" DoSubstitute
SearchFor "\007" ReplaceBy "\140" DoSubstitute
-- Kinetic framework fixes (as of October 13, 1983 4:46 pm)

SaveSelectionA
MatchLiterally MatchCase MatchAnywhere DoReplace
SearchFor "\\stdir" ReplaceBy "\\di" DoSubstitute
SearchFor "\\sttan" ReplaceBy "\\ta" DoSubstitute
SearchFor "\\stpos" ReplaceBy "\\po" DoSubstitute
SearchFor "\\timrev" ReplaceBy "\\ne" DoSubstitute
SearchFor "\\span" ReplaceBy "\\sp" DoSubstitute
-- Fixes \figs, \fignos and \figcaps for new TEX macros
(as of October 13, 1983 4:46 pm)

SaveSelectionA
MatchAnywhere MatchCase DoReplace
MatchLiterally
SearchFor "\\figcap" ReplaceBy "\\caption" RestoreSelectionA DoSubstitute
SearchFor "\\figno" ReplaceBy "\\numfig" RestoreSelectionA DoSubstitute
SearchFor "\\fig" ReplaceBy "\\figspace" RestoreSelectionA DoSubstitute
MatchPattern
SearchFor "\\indent$\\bu" ReplaceBy "\\item " DoSubstitute
SearchFor "\\numfig$\'(<x>\')<y:@>" ReplaceBy "\\numfig <y>cm\'{(<x>)\'}" RestoreSelectionA DoSubstitute
SearchFor "\\numfig$\'(<x>\')\'{<y>\'}" ReplaceBy "\\numfig <y>cm\'{(<x>)\'}"
RestoreSelectionA DoSubstitute
SearchFor "\\footfig$<y:@>$\'(<x>\')" ReplaceBy "\\footfig <x>cm<y>"
RestoreSelectionA DoSubstitute
SearchFor "\\footfig$\\dag$\'(<x>\')" ReplaceBy "\\footfig <x>cm\dag"
RestoreSelectionA DoSubstitute
SearchFor "\\figspace$<x:@>" ReplaceBy "\\figspace <x>cm"
RestoreSelectionA DoSubstitute
SearchFor "\\figspace$\'{<x>\'}" ReplaceBy "\\figspace <x>cm"
RestoreSelectionA DoSubstitute
SearchFor "\\mfig$<x:@>" ReplaceBy "\\mfig <x>cm"
RestoreSelectionA DoSubstitute
SearchFor "\\mfig$\'{<x>\'}" ReplaceBy "\\mfig <x>cm"
RestoreSelectionA DoSubstitute
-- Fixes \algorithm and \step for new TEX macros
(as of October 13, 1983 4:46 pm)

SaveSelectionA
MatchPattern MatchCase MatchAnywhere DoReplace
SearchFor "\\step$\'{$\\sno<x:@>$$" ReplaceBy "\\step\'{<x>\'}\'{"
RestoreSelectionA DoSubstitute
SearchFor "\\step$\'{$\\sno\'{<x>\'}$$" ReplaceBy "\\step\'{<x>\'}\'{"
RestoreSelectionA DoSubstitute
SearchFor "\\step$\'{$\\nono$$" ReplaceBy "\\unstep\'{"
RestoreSelectionA DoSubstitute
-- Replaces all "<blanks><cr><blanks><cr><blanks>" by "<cr><nodebreak>"

SaveSelectionA Everything
SaveSelectionB MatchPattern MatchAnywhere
SearchFor "\032*\n" DoReplace ReplaceBy "\n" RestoreSelectionA DoSubstitute
SearchFor "\n$\n$$" DoOperations Operations "Delete InsertLineBreak Break"
RestoreSelectionB DoSubstitute
RestoreSelectionA
-- Puts page marks in front of "\section" and % Begin nodes after them

SaveSelectionA Everything
MatchAnywhere MatchLiterally SearchFor "\\section"
DoOperations Operations "GrowSelection GrowSelection CaretBefore \"\\014 \" GrowSelection GrowSelection CaretAfter Break \"% Begin\" DoSubstitute
RestoreSelectionA
-- Nests everyting twice but UnNests nodes containing Page marks, \section, and \subsection

SaveSelectionB Everything CaretBefore 1 GoToNextNode
Nest SaveSelectionA MatchAnywhere
MatchPattern SearchFor "|#" DoOperations Operations "Nest Nest"
RestoreSelectionA SubstituteAfterSel DoSubstitute
SearchFor "\\subsection" Operations "UnNest"
RestoreSelectionA DoSubstitute
MatchPattern SearchFor "|\\section" DoOperations Operations "UnNest UnNest"
RestoreSelectionA DoSubstitute
SearchFor "\014" DoOperations Operations "UnNest UnNest"
RestoreSelectionA DoSubstitute
RestoreSelectionB
-- Puts $ $ around selection

MakeNotPendingDelete SaveSelectionA CaretAfter "$" RestoreSelectionA CaretBefore "$" RestoreSelectionA
-- Set "c" looks of TeX comments (from % to <CR>)

SaveSelectionB MatchAnywhere
MatchPattern SearchFor "\'%*'\n" DoOperations Operations "SaveSelectionA LooksChars \"c\" RestoreSelectionA DoSetLooks"
RestoreSelectionB DoSubstitute
-- Puts a CR in front of node and removes its last char (hopefully CR)

MakePointSelection GrowSelection GrowSelection GrowSelection CaretBefore "\n" GrowSelection GrowSelection GrowSelection CaretAfter 1 BackSpace