[texworks] newbie texworks scripting questions
jtim.arnold at gmail.com
Wed Jul 6 20:04:23 CEST 2011
On Sun, Jul 3, 2011 at 6:22 AM, Stefan Löffler <st.loeffler at gmail.com> wrote:
> On 2011-07-01 17:19, Tim Arnold wrote:
>> 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?
> Yes. Paul has already explained this. If you want this to be started by
> the user, it should be a standalone script.
>> need a Python installation?
> In general, yes.
>> * What if I write it as a python executable using Python freeze (no
>> system Python needed), would that work?
> No. Well, not directly, anyway. You need some script inside Tw to access
> Tw itself (and its documents, etc.). Of course, as Paul explained, you
> can run any program on the computer (assuming appropriate security
> settings). So you could keep your core routines as a Python executable
> and write a script that passes all input data and extracts all output
> data as necessary. Depending on how complex your Python code is this
> data passing could easily make up a considerable portion of the overall
> code, however, in which case you should think about if this is worth the
> trouble (both coding-wise and regarding the lowered security settings to
> run the external program).
>> * 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?
> In short: yes and no. As Paul pointed out already, you can write files
> to the hard disk directly from a script (again assuming appropriate
> security settings). This can then be opened by
> TW.app.openFileFromScript, which return (among other things) a handle to
> access the opened document. This is viewed as new topmost window, but
> your script is still running in the context of the old document.
> Regardless, since you have a handle, you can invoke typeset() on it.
Thanks Stefan, Paul. That really helps me understand better how to
approach this problem. I will rewrite my python logic as a standalone
That should keep my busy for a while. Thanks for the quick and
More information about the texworks