[texworks] Scripting root file behaviour
Henrik Skov Midtiby
henrikmidtiby at gmail.com
Sat Apr 14 11:49:04 CEST 2012
Hi Thomas
In my autocomple script the following function is used to go through
all the open files and according to the filename do something with the
file contents. This shows how to access the filename of open windows.
function getTextFromAllOpenWindows()
{
var windows = TW.app.getOpenWindows();
var fullText = "";
for (var editor in windows)
{
var targetDocument = windows[editor];
var filename = targetDocument.fileName;
var hasTexExtension = new RegExp(".*tex");
if(hasTexExtension.test(filename))
{
fullText = fullText + targetDocument.text + " ";
}
// TODO: Search for citations if the file ends on .bib
var hasBibExtension = new RegExp(".*bib");
if(hasBibExtension.test(filename))
{
fullText = fullText + " " + getBibtexKeys(targetDocument.text) + " ";
}
}
return(fullText);
}
The full autocomplete script can be found at
https://github.com/henrikmidtiby/TeXworks-scripts/blob/master/autocomplete/autocomplete.js
On 14 April 2012 11:18, Thomas Fehige <thomas at fehige.de> wrote:
> Thanks for the input. What I have now as a skeleton is this:
> //---------------------------------------------------
>
> if (TW.app.hasGlobal("main_file")){
>
> TW.app.getGlobal("main_file") // that's where the /path/and/filename.tex are
> stored by another script
>
> var windows = TW.app.getOpenWindows();
>
> for (Win in windows){
>
> // here I'd want to see if the main_file is open in an editor
> window,
>
> // if necessary, load it and finally call its target.typeset() function.
>
> // But I don't get the filenames of the editor windows but empty information
> messages instead:
>
> TW.information(null, "File in Window:", Win.fileName);
>
> }
>
> } else {
>
> // typeset the file in the current window
> }
>
> //---------------------------------------------------
>
> It seems I've missed something, but what?
>
> Thanks and all the best -- Thomas
>
> Am 13.04.2012 14:04, schrieb Stefan Löffler:
>
>> Hi,
>>
>> On 2012-04-10 20:18, Henrik Skov Midtiby wrote:
>>>
>>> I think you can activate the compilation of the current document with
>>>
>>> TW.target.typeset();
>>>
>>> Something similar should be available for all the open documents [1]
>>>
>>> TW.app.getOpenWindows()
>>>
>>> The idea is to get the window of the main document and trigger the
>>> compilation from there.
>>> There might be a better solution somewhere, but I have no knowledge of it
>>> (yet).
>>
>> I think this is a fairly good solution (actually, that's basically what
>> Tw does internally).
>>
>> Cheers,
>> Stefan
>
>
More information about the texworks
mailing list