// -*- ASCII:EDT -*- // append strings to all instances of // all word of a word list // (schlicht 20010622) ///////////////////////////// // This is the string to put before the insertion: Assign("indexing1","\index{"); // This is the string to put after the insertion: Assign("indexing2","}"); // so that a string "Text" will become "Text\index{NewText}" // This is your main file: ReadFile("%p\%n%t",9) IfFileExists("%p\%n.index",> // This is your word list: "ReadFile('%p\%n.index',0);",> "Prompt('I cannot find the wordlist file ''%n.index''!',2,1);Exit;"); GetLength(6,"%$('indexing1');%$('indexing2');"); Assign("indexinglength","%!6"); GetLength(6,"%!0"); LetRegNum(3,0); StartWorking("Indexing..."); Loop(!`> Release("working");> Repeat("76-((%!3*75)/%!6",!"Assign('working','%$(|working|);|');");> StartWorking("%$('working')");> SetOK(1);> FindInString("%!0","<*>",2,3,1011,%!3);> IfOK(!"> ExtractByIndex(1,'%!0',%!2,%!3);> FindInString('%!1','{+ }-\>{@ }',2,4,0001,0);> IfOK(!'> ExtractByIndex(7,''%!1'',0,%!2-1);> GetLength(2,''%!1'');> ExtractByIndex(8,''%!1'',%!4+1,%!2-3);> IfStr(''%!8'','''',''='',!''LetReg(8,|%!7|);'');> GetLength(2,''%!8'');> LetRegNum(5,0);> Loop(!''> SetOK(1);> // The word can be preceded and followed by a space, a new line, // parentheses, quotation marks, or punctuation: FindInString(|%!9|,|[''''""``(]||{\{}||{\[}||{ }||{><}%!7{[,;:)!?''''""]||{\.}||{\}}||{\]}||{\\}||{ }}||{><}|,4,5,1011,%!5);> IfOK(!|> // This puts the \index{} command *after* the words: ReplaceInString(||%!9||,||%!7%$(*indexing1*);%!8%$(*indexing2*);||,%!4+1,%!5-1,0,9);> // use this line instead, if you want the command appear *before* the words: // ReplaceInString(||%!9||,||%$(*indexing1*);%!8%$(*indexing2*);%!7||,%!4+1,%!5-1,0,9);> LetRegNum(5,||%!5+%!2+%$(*indexinglength*);||);> |,> |Stop;|);> '');> ');> ",> !"OpenOutput('%p\%n.index%t');> WrS('%!9'); > CloseOutput;> Prompt('I''m finished!%\I wrote the new file ""%n.index%t"". %\> If you are happy with it, simply save it as ""%n%t"".'); > Open('%p\%n.index%t');> Exit;> ");> `); StopWorking; End; ////////////////////////////////////////////////////////////// // This macro can be used to append \index{} commands to all // instances of all words of a word list. // // Invoke it on a file (let's call it 'Fishy.tex'), if you // have a list of all terms to be indexed in a file // 'Fishy.index' of the following form: //-------------------- red herring -> herring!red herring -> herrings -> herring //------------------ etc. // Here, every instance of the phrase "red herring" will // become "red herring\index{herring!red}", etc. // // - There must be one pair of terms in a line. // - Lines without a "->" will be ignored. // - If the string in the index command is the same as the // word, you can just leave it blank (as for "herring"). // - Parts of words will not be recognized (i.e. "herring-pond" // will not get indexed). // - If the last word of a phrase coincides with a single word // that you want to index as well (like "red herring" and // "herring"), put the phrase *before* the word. Then only // the phrase will be indexed. (This doesn't work if you // want to put the \index{} command *before* the word.) // - If you want to index "red" and "red herring", both will // be indexed. Sorry! // - If you use translation tables (in Options | Settings) you // need to change the file first so that it really contains // accented letters. You can do this by applying the // Translation Tables to your document. // // Note that the index you'll get won't be a very good one. To // get an index that is usable you'll still have to edit it a // lot (mainly removing those \index command, where the term // is not used in a substantial way). // // To get a list of all words of a file you can use the macro // "%B\Macros\text\allwords.edt". If it's not in your WinEdt // installation, you can get it from // // // This will produce a file %N.index. // Sort this twice using the 'Tools | Sort Lines' tool: // 1. case sensitive, remove multiple entries // 2. case insensitive // Remove all words you don't want to be indexed. // Append the string " -> " to all lines using WinEdt's tool: // 'Edit | Move | Insert String' (check "Append"). // Add index strings that are different from the terms to be // indexed. // // The macro will not edit your file directly but produce the // new file '%n.%index%t' (in our case 'Fishy.index.tex'). // If you are happy with all \index commands you can simply // rename it to 'Fishy.tex' (but I wouldn't do this before // being absolutely sure that I don't want to change anything // to the original text). // // You can use indexing.edt for any other append job of course // by changing the first two lines. // // R Schlicht w.m.l@gmx.net ////////////////////////////////////////////////////////////// $Id: indexing.edt,v 1.5 2001-11-13 18:46:47+01 standard Exp standard $