# [texworks] SCRIPT: Insert a new \label{key} - checks for potential duplicate conflict

Paul A Norman paul.a.norman at gmail.com
Sat Nov 13 02:44:31 CET 2010

Dear Tyler,

I am slowly bringing some notes together drawn from our experiences in
using QtScript (built into TeXworks) - its not an official manual or
anything, but I am trying to gear it towards both people trying
scripts for the first time, and also those who have some experience in
programming.

There are other modules, Python and Lua which are both very good
script languages, but I am focussing on what I have definite
experience with - QtScript which is very like the JavaScript used in
modern web browsers. I understand that at the moment there are some
things which only QtScript can do.

Stefan Löffler currently the main active C++ developer on the Tw
project, has offered to supply information as time permits - so
hopefully you will see something worth while building up.

You can check out the work as it comes along at:

twscript.paulanorman.com  and http://twscript.paulanorman.com/docs/

http://twscript.paulanorman.com/docs/html/TexWorksQtScripting.htm

Again I'm sorry that it has taken so long for anything definite to
happen to be able to get back to you,

Paul

On 22 May 2010 01:01, Tyler Estler <w.t.estler at gmail.com> wrote:
> Dear All,
>
> I am migrating from WinEdt to TexWorks, which I really like for its
> simplicity.
>
> I am looking for some kind of tutorial introduction to the use of scripts
> such as the one described here. I have done a reasonable amount of LaTeX
> writing, but I am a novice when it comes to scripts etc.
>
> Could someone provide a simple step-by-step guide to the use of scripts,
> hooks, etc?
>
> Thanks for any help, and also for your efforts to expand the functionality
> of TexWorks.
>
> Tyler Estler
>
> On Fri, May 21, 2010 at 5:01 AM, Paul A Norman <paul.a.norman at gmail.com>
> wrote:
>>
>> Hi,
>>
>> Insert a new \label{key}
>>
>>
>> If text is selected first in the Tw editor, the script endeavours to
>> use this as the key to make a new \label{key}
>>
>> Checks through the current document, and offers a drop-down box with
>> either a blank area to type in, or if the user has selected some text,
>> that as the proposed label key. The drop-down shows any already
>> existing label keys in the document.
>>
>> If the user Ok-s the drop-down box, the script then checks through
>> existing labels to avoid reproducing the same key.
>>
>> If the key has already been used in another \label{key} statement, the
>> user is shown the pre-existing key, and asked to try making a new
>> label up again. The same checks are performed recursively until either
>> a unique key is made, or the user cancels.
>>
>> Successful use, inserts \label{usersKey}
>>
>> (Companion script to insertCrossRef.js)
>>
>> Paul
>
>