[texworks] newbie texworks scripting questions
st.loeffler at gmail.com
Sun Jul 3 12:22:08 CEST 2011
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.
More information about the texworks