[texworks] Sweave with Texworks - Update

Paul A Norman paul.a.norman at gmail.com
Thu Aug 5 11:10:38 CEST 2010


If you have a relatively recent development scriptable version of the
Tw editor ...

For various system needs QtScript in TexWorks can run a system call.

In the Tw Editor, goto Menu/  Edit/Preferences/ Scripts  tab,  and
tick everything in the  panel. Ok out

To see all available TwScript commands available to lua, python and
QtScript, run this as a TeXWorks .js script

// TeXworksScript
// Title: Debug
// Description: Starts the Debugger
// Author: Jonathan Kew
// Version: 0.1
// Date: 2010-03-18
// Script-Type: standalone

debugger;
//----------------

Then look for TW object and under it "app" and "target"

(Also you can search for Script in the Tw issues list. Ther are
already some worked examples there of some things.)

So QtScript can also obtain the curent filename of the edit document.

So if you want to do it from within TexWorks, on the current file, you
could iterate through the necessary steps reassigning  in script a
relevent filename and run system latex etc commands/ or whatever on
it. Note the need for "cmd /c " as a prefix if under Windows.

You can then get TwWorks to open any generated files or whatever from QtScript.

From:  http://code.google.com/p/texworks/wiki/ScriptingTeXworks#Execute_arbitrary_system_commands

Here is an example for interaction with the edit contents but the
principles are obvious.

"Execute arbitrary system commands:
¶
"Through the application object, scripts have the ability to execute
arbitrary system commands. Here is an example "System Command" script:

var cmd = target.selection;
if (cmd != "") {
  var result = app.system(cmd);
  if (result != null) {
    target.insertText(result);
  }
}

"in a TeXworks document, then select the line ls -l and execute this
script (NB: Windows users will need to use cmd /c dir instead): the
line will be replaced by a directory listing. "

Paul

On 5 August 2010 13:17, Christopher Desjardins <cddesjardins at gmail.com> wrote:
>
>
> On Wed, Aug 4, 2010 at 7:23 PM, Duncan Murdoch <murdoch.duncan at gmail.com>
> wrote:
>>
>> On 04/08/2010 8:00 PM, Reinhard Kotucha wrote:
>>>
>>> On 4 August 2010 Christopher David Desjardins wrote:
>>>
>>>  > Yeah, I checked out latexmk. It appears that latexmk can't run
>>>  > Sweave without some modifications (if I reading the information
>>>  > about latexmk correctly). Unfortunately I don't know any perl
>>>  > either.
>>>
>>> As far as I understand, Sweave creates LaTeX files from R files.  And
>>> latexmk creates PDF files from LaTeX files.  Isn't it possible to
>>> combine these steps by providing a simple shell script (on Unix) or a
>>> batch file (on Windows) which just calls Sweave and latexmk?
>>
>> This is easy to do for simple one-file projects; I can show Christopher
>> the details.
>
> Thanks. I am on Debian GNU/Linux. I thought that I might be able to write a
> bash script that I could give to TeXworks but I am not quite sure of the
> proper syntax.
>
>>
>> It's harder for multi-file projects, because there are usually at least
>> two different filenames involved:  the chapter file and the main file.
>> Sweave needs to update the LaTex for the chapter, and pdflatex needs to be
>> given the main file.  TeXworks can currently only pass the name of the main
>> file to the script, so it needs some trickery in the script to extract the
>> chapter names and process them before calling pdflatex.  I haven't worked
>> out the details of this trickery yet.
>>
>> Duncan Murdoch
>
>



More information about the texworks mailing list