[texworks] several replacements

GM gm at marris.fr
Sat Feb 18 10:07:19 CET 2012


Le 18/02/2012 02:16, Paul A Norman a écrit :
> Hi GM,

Bonjour,

> Have you done some scripting before

No, but I still tried to understand ... and it seems that this is what I 
asked.

Did I not write too much nonsense?

Thanks
GM

===========
// TeXworksScript
// Title:  ReplaceByGM
// Description: Nettoyage du texte
// Author:  G.M.
// Version: 0.1
// Date: 2012-02-18
// Script-Type: standalone
// Context: TeXDocument
// Shortcut: Alt+E, Alt+R

String.prototype.replacebyGM = function() {
     var x=this.toString();
     x=x.replace(/\\text\{A\}/g,"A");
     x=x.replace(/\\text\{B\}/g,"B");
     x=x.replace(/\\text\{C\}/g,"C");
     x=x.replace(/\\text\{D\}/g,"D");
     x=x.replace(/\\text\{E\}/g,"E");
     x=x.replace(/\\text\{e\}/g,"\\e");
     x=x.replace(/\\text\{i\}/g,"\\ii");
     return x;
};

var txt = TW.target.selection;
if (txt != "") {
   var pos = TW.target.selectionStart;
   txt = txt.replacebyGM();
   TW.target.insertText(txt);
   TW.target.selectRange(pos, txt.length);
}

undefined;
===========


>
> Paul
>
> On 18 February 2012 08:38, GM<gm at marris.fr>  wrote:
>
>> Hello,
>>
>> I need your help to write a script that would perform several replacements
>> in a tex file.
>>
>> ===================
>> \text{A} ->  A
>> \text{B} ->  B
>> ...
>> \text{i} ->  \ii
>> \text{e} ->  \e
>> \Ouv ->  \ouv
>> ...
>> (1 tab) ->  (4 spaces)
>> etc.. etc.
>> ===================
>>
>> Thank you to specialists javascript to tell me how I could do that.
>>
>>
>



More information about the texworks mailing list