P.S. <div><br></div><div>If you are going to processing a number of documents with similar but different settings (as in changing your custom LaTeX to meet a publisher's requirements), you could change the script to actually choose the version of  "<b>myReplacements.txt</b>"  to use...</div>
<div><br></div><div><a href="http://twscript.paulanorman.com/docs/html/getOpenFileNameQString.html">http://twscript.paulanorman.com/docs/html/getOpenFileNameQString.html</a></div><div>and</div><div><a href="http://twscript.paulanorman.com/docs/html/readFile.html">http://twscript.paulanorman.com/docs/html/readFile.html</a></div>
<div><br></div><div>And if you want 
 "<b>myReplacements.txt</b>"    to allow for line(s) in it to be temporarily suspended, or for comments, start the line with a % </div><div><div><br></div><div><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">
\text{A} -> A</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">%\text{B} -> B</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">\text{i} -> \ii</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">% put a note/comment here</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">\text{e} -> \e</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">\Ouv -> \ouv</p></div><div><br></div><div>\text{B} -> B  would not get processed.</div><div><br></div><div>and change..<div><br></div><div>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"><b>function altertext</b>(txt)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">  {</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">    for (count in myReplacementList)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">       {</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">              </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">       if (myReplacementList[count].substr(0,1) == "%")</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">        {</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">        continue;</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">        }     </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">                         </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">   </p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">var actionThis = myReplacementList[count].split(" -> ");</p>
<div><br></div><div> ... the  rest of function</div><div>}</div><div><br></div><div>Also bulk alterations in "<b>myReplacements.txt</b>"  could be for anything not just LaTeX </div><div><br></div><div>Paul</div>
<br><div class="gmail_quote">On 19 February 2012 01:15, Paul A Norman <span dir="ltr"><<a href="mailto:paul.a.norman@gmail.com">paul.a.norman@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi GM,<div><br></div><div>No worries ... I'm afraid that the English language can be a little ambiguous at times "
<span>I need your help to write a script that would</span> " could imply both scenarios.</div><div><br></div><div>What you have done looks great.</div><div><br></div><div>You could try encapsulating the list of things to do as an array, or even better perhaps  as an external text file that you can edit separately from your script if you need to change or add items.<br>

<br>An external text file, say,  "<b>myReplacements.txt</b>" could look similar to what you first indicated if you wished (but with only one space be fore and after our -> ), write/edit it in TeXworks so we get the correct line-breaks. Save it into the same directory as your script.</div>

<div><br></div><div>something[space]->[space]somethingElse<div class="im"><br><br>\text{A} ->  A<br>\text{B} ->  B<br></div><div class="im">\text{i} ->  \ii<br>\text{e} ->  \e<br>\Ouv ->  \ouv</div></div>
<div><br></div><div>  We'll get script to handle the \escaping, so that you/your Users can just write plain text with no extra backslashes required in <b>myReplacements.txt </b></div>
<div><i><br></i></div><div><i>  I have not thought through all that needs to be in</i><b> function escapeNeedle()</b> - its a bit late at night here now! So you may need to add anything else that would interfere with a regular expression.</div>

<div><br></div><div><br></div><div>//====== Script ======</div><div><br></div><div><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">function escapeNeedle(needle)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">           {</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">           </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">          needle = needle.replace(/\\/g, "\\\\");</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">  needle = needle.replace(/\{/g, "\\{");</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">  needle = needle.replace(/\}/g, "\\}");</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">    needle = needle.replace(/\[/g, "\\[");</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">    needle = needle.replace(/\]/g, "\\]");</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">            </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"><br></p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">            // and others as needed</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">            </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"><br></p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">          return needle; </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">           }</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">           </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">           </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">   function altertext(txt)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">           {</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">           for (count in myReplacementList)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">              {</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">               </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">  var actionThis = myReplacementList[count].split(" -> "); // 0 = find, 1 = replace with</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">               </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"> </p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">      actionThis[0] = escapeNeedle(actionThis[0]);</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">               </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"><br></p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">  var regExprsn = new RegExp(actionThis[0], "g"); </p>


<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">      // TW.information(null,"",regExprsn);</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">               </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"><br></p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">  txt = txt.replace(regExprsn, actionThis[1]); </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">                             </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">               } </p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">           return txt;</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">           }</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"> </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">   // this will give us an array element for each line in file   </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">   // assuming file has been set, or script is pointless                      </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">   var myReplacementList = TW.readFile("myReplacements.txt").result.split("\n");</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">

<br></p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">// could split above into steps and check for status first see <a href="http://twscript.paulanorman.com/docs/html/TexWorksQtScripting.html?readFile.html" target="_blank">http://twscript.paulanorman.com/docs/html/TexWorksQtScripting.html?readFile.html</a></p>

<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">   </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"><br></p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">   var txt = TW.target.selection;              </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">   var pos = TW.target.selectionStart;</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">   </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"><br></p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">     if (myReplacementList == false) // file is probably empty</p>


<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"> {</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">  TW.information(null,"","Please Create and populate myReplacements.txt in Script's folder.\n\n"</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">                     +" Format:\nsomething[space]->[space]somethingElse\ne.g.\n"</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">                     +"\\text{A} ->  A");</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">    }</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"> else</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">  if (txt != "")</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">   {</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">      </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">    txt = altertext(txt);</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">    </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">    TW.target.insertText(txt);</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">    TW.target.selectRange(pos, txt.length);</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">      </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">  }                           </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">     else</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">     {</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">  TW.information(null,"","Please Select Some text First");</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">     }    </p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"><br></p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">

//===== End Script ====</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"><br></p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">Hope that this helps, thanks I'll probably use it myself from time to time!</p>
<span class="HOEnZb"><font color="#888888">
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"><br></p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px">Paul     </p></font></span><div><div class="h5"><br><div class="gmail_quote">
On 18 February 2012 22:06, GM <span dir="ltr"><<a href="mailto:gm@marris.fr" target="_blank">gm@marris.fr</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Le 18/02/2012 02:16, Paul A Norman a écrit :<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi GM,<br>
</blockquote>
<br>
Bonjour,<div><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Have you done some scripting before<br>
</blockquote>
<br></div>
No, but I still tried to understand ... and it seems that this is what I asked.<br>
<br>
Did I not write too much nonsense?<br>
<br>
Thanks<br>
GM<br>
<br>
===========<br>
// TeXworksScript<br>
// Title:  ReplaceByGM<br>
// Description: Nettoyage du texte<br>
// Author:  G.M.<br>
// Version: 0.1<br>
// Date: 2012-02-18<br>
// Script-Type: standalone<br>
// Context: TeXDocument<br>
// Shortcut: Alt+E, Alt+R<br>
<br>
String.prototype.replacebyGM = function() {<br>
    var x=this.toString();<br>
    x=x.replace(/\\text\{A\}/g,"A"<u></u>);<br>
    x=x.replace(/\\text\{B\}/g,"B"<u></u>);<br>
    x=x.replace(/\\text\{C\}/g,"C"<u></u>);<br>
    x=x.replace(/\\text\{D\}/g,"D"<u></u>);<br>
    x=x.replace(/\\text\{E\}/g,"E"<u></u>);<br>
    x=x.replace(/\\text\{e\}/g,"\\<u></u>e");<br>
    x=x.replace(/\\text\{i\}/g,"\\<u></u>ii");<br>
    return x;<br>
};<br>
<br>
var txt = TW.target.selection;<br>
if (txt != "") {<br>
  var pos = TW.target.selectionStart;<br>
  txt = txt.replacebyGM();<br>
  TW.target.insertText(txt);<br>
  TW.target.selectRange(pos, txt.length);<br>
}<br>
<br>
undefined;<br>
===========<div><div><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Paul<br>
<br>
On 18 February 2012 08:38, GM<<a href="mailto:gm@marris.fr" target="_blank">gm@marris.fr</a>>  wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
<br>
I need your help to write a script that would perform several replacements<br>
in a tex file.<br>
<br>
===================<br>
\text{A} ->  A<br>
\text{B} ->  B<br>
...<br>
\text{i} ->  \ii<br>
\text{e} ->  \e<br>
\Ouv ->  \ouv<br>
...<br>
(1 tab) ->  (4 spaces)<br>
etc.. etc.<br>
===================<br>
<br>
Thank you to specialists javascript to tell me how I could do that.<br>
<br>
<br>
</blockquote>
<br>
</blockquote>
<br>
</div></div></blockquote></div><br></div></div></div>
</blockquote></div><br></div></div></div>