[texworks] About the native PDF viewer (feature request and a question)

Paul A Norman paul.a.norman at gmail.com
Thu May 5 02:11:59 CEST 2011

On 5 May 2011 04:55, Stefan Löffler <st.loeffler at gmail.com> wrote:
> Hi,
> On 2011-05-02 16:01, Edoardo Vacchi wrote:
>>> Can we make TeXworks monitor a  port we could safely address in  a
>>> running copy of TeXworks - would be ideal and have a certain list of
>>> accepted registered commands like open this .tex document (if not
>>> already open) at this line number, and bring the appropriate editor
>>> window into focus? Perhaps also a 'port' command in the acceptable
>>> list that says insert this text at cursor position/line number?
>> many applications (such as texniccenter or texmaker) accomplish this
>> by allowing only one instance and looking at command line switches
> This actually applies to TeXworks as well. It is a single-instance, and
> it supports the --position=... switch (or the short form -p ...), which
> currently can be used to jump to a specific line (for .tex files) or
> page (for .pdf files).

That got me hunting - sounded really useful :)

I couldn't find it in the manual - searched over the files - did I
miss it or is it yet to go in the manual?

At -

-- Found this reference in the source code - are these all of the
command line switches?


Form the cmd shell on Xp only one set of these worked ...

.B --help, -?
Display a short overview over all command line options"

texworks --help
texworks -h

Nothing happens at all TeXworks does not appear as a running process
as far as I can tell, however if Tw is open already, but not in focus,
it is brought to the front of the desktop.

No message on the command line.

.B --position=, -p
Open the next specified file at the given position (line or page)

texworks -p=1000 "/some/path/myTex.tex"
texworks -p=10 "/some/path/myTex.pdf"

Very nice.

The switch MUST appear BEFORE the file name.

.B --version, -v
Display version information"

texworks --version
texworks -v

Nothing happens at all, however if Tw is open already, but not in
focus, it is brought to the front of the desktop.

No message on the command line.


texworks -p=10 "/some/path/myTex.pdf"

The source is not opened with it (just a note not a complaint)

And with

texworks -p=1000 "/some/path/myTex.tex"

I have object modules (PhpJs ($P), twConst, msgBox, twPan ($tw) as in
FileTracker.js ) loaded when Tw starts and there is no problem with
them at all.

// Script-Type: hook
// Hook: TeXworksLaunched

All is fine there.

But I have a hookscript that works on ...

// Hook: LoadFile

That gets interfered with. That script monitors and records all files
opened by TeXworks to give me an exhaustive list of unique filenames
for when I need to look back beyond the Recent Files list.

The .tex opens, and then it does not jump to line 1000 until I clear
my hookscript error message in the Debugger. Once the debugger is
cleared, the editor jumps correctly to line 1000 as indicated above.

The error is that my script wants to open its monitoring file, but it
can't find it - when I am using -p=someIntegerLineNumber while opening
a .tex file

As might be expected, this does not happen when opening a .pdf to a
page number -p=12

My script ( FileTracker.js)  fails when something like this is used on
the command line:

texworks -p=1000 "/some/path/myTex.tex"

 FileTracker.js is below - as I say it always manages to find its
record file (in same directory as script itself) undedr normal
circumstances (i.e. when not using -p=someLineNumber switch).

Any advice appreciated please.


> Stefan

Sample of filelist.txt

- Experiments/tw_OBJECT.js


// TeXworksScript
// Title:  File Tracker
// Description: Keeps track of first opening of a file
// Author:  Paul Norman
// Version: 0.3
// Script-Type: hook
// Hook: LoadFile

 eval(TW.app.getGlobal("helper_twPan")); //  Comment if NOT Needed -
This includes PhpJs ($P), twConst, msgBox, twPan ($tw)

    function writeFileList(thisPath)
           , fileList
           + thisPath
           + PhpJs.chr(13) + PhpJs.chr(10)

 var  currentFile  = TW.target.fileName;

 var  fileList = twPan.file_get_contents("fileList.txt");

   if (fileList == undefined)// first usage
       fileList = "";
        if (fileList.indexOf(currentFile) == -1)



More information about the texworks mailing list