[texworks] newbie texworks scripting questions

Paul A Norman paul.a.norman at gmail.com
Sat Jul 2 04:00:51 CEST 2011

P.S. I'll be trying to upload some updates to information for
http://twscript.paulanorman.com/docs/index.html later today hopefully.


On 2 July 2011 11:25, Paul A Norman <paul.a.norman at gmail.com> wrote:
> Hi Tim,
> I'll cover what I can here, but there are some file issues needing
> some one else to jump in.
> Some information here: http://twscript.paulanorman.com/docs/index.html
> Python.
> You'll be caught both ways when you say that users might not have
> Python, under  TeXworks (Tw)  Python is a plugin which may or may not
> be present either, and some script features have not been available to
> some plugins, I do not know what the current status is on that.
> With Tw QtScript (native to any installation) you can load files
> directly into memory from disk without them needing to be in an open
> document window first.
> You can write out to disk from script memory without reference to an
> open Tw document.
> Standalone script requires User to initiate directly, a hook script
> responds to a Qt signal from the underlying C++ application, and is in
> that sense like an internet browser event - it is a response to
> something that happens (though all events/signals are at some part of
> their life chain initiated by a User action).
> Standalones are initiated at present by User through either a Script
> (sub) menu item (scripts are self assigning to menus according to
> where they are saved in the Script folder directory tree) or a
> possible Short cut key sequence. Plans are for toolbar buttons,
> context menu, and other options as well.
> You could load libraries or other scripts from disk and eval() them in
> memory, and direct script invocation form other scripts has been
> canvassed here.
> Python freeze.
> Depending on platform/permission issues you can call any ting your
> system will execute form a Tw Script system() call, and optionally
> wait for a return code and or a returned string from your executable.
> Your questions raises the issues of which of the TW File functions
> return TW.target objects (like window.document in browsers).
> Some do not. I have not had cause to work with them all as yet. The
> C++ code is available on
> http://code.google.com/p/texworks/source/browse/trunk  to troll
> through, or you can experiment testing for TW.target.text to see if
> you get the contents of the editor window that you expect.
> There is an application object present called TW.app which loosely
> corresponds to the browser window object.
> And TW.target which as mentioned loosely corresponds to the
> window.document object.
> TW.target represents the current document, whether focussed by the
> User or in Script, and has a function TW.target.typeset() (document
> would need a saved name on disk first though!)
> Of course you could process/save your text in/from script memory to
> disk named as you wish, and then uses TW.system() to execute the
> necessary pdflatex etc TeX utilities directly, you would have to be
> confident of the results as this would not use any of the Tw console
> responses to errors .
> TW.app has these calls
> TW.app.newFile();
> http://twscript.paulanorman.com/docs/html/files/newFile.html
> Creates a new file and sets the focus in the editor. Returns a
> TW.target object ??
> TW.app.open();
> http://twscript.paulanorman.com/docs/html/files/open.html
> Presents the open file dialogue.
> From that point scripting looses 'contact' with the function.
> Does not receive a file filter nor a suggested file name, but will not
> allow the dialogue "Ok" button to be enabled unless the User chooses
> an actual file.
> Upon success, opens the chosen file in a new editor window, (returns
> no value — for neither success nor failure).
> That editor window does not become the new TW.target.
> Moved to top level for security reasons:
> TW.openFileFromScript(QString,int,bool)
> The TW.target object has some similar calls, but there has been little
> discussion/information here about those yet (and some may be
> obsolete?) ...
> TW.target.newFile()
> TW.target.newFromTemplate()
> TW.target.open()
> You can check out what is already available for each of these (not
> much) at http://twscript.paulanorman.com/docs/index.html
> Hope this helps,
> Please share back any gleanings/discoveries or further questions.
> Paul
> On 2 July 2011 03:19, Tim Arnold <jtim.arnold at gmail.com> wrote:
>> hi,
>> I would like to write a script for TeXWorks and I have a few questions
>> before getting started.
>> I have a system outside of TeXWorks now that I've written in Python;
>> the system does two things:
>> (1) parses a tex file, modifies it, writes out a *.ltx file and
>> compiles that file; the original tex file is not compiled.
>> (2) parses a tex file, extracts info from it and writes that output to
>> a *.txt file for other uses.
>> I want to rewrite this capability as a TeXWorks script so it is easily
>> usable for others. My questions:
>> * I suppose I should write it as a standalone script, not a hook script?
>> * Probably I should rewrite my system in JavaScript so users do not
>> need a Python installation?
>> * What if I write it as a python executable using Python freeze (no
>> system Python needed), would that work?
>> * Is it possible to switch the current document? I'm guessing that
>> compiling the modified file, step (1) above, will be the hardest
>> thing--any suggestions? Maybe parse, write a new file, and
>> automatically open and compile the new file?
>> thanks for helping out a newbie scripter.
>> --Tim Arnold

More information about the texworks mailing list