[Tex/LaTex] Kile: show me script example

kilescripts

Can someone please show me an example script in Kile?

I want a example.

.

.

.

.

enter image description here

Best Answer

First things first. :)

According to The Kile Handbook, chapter 13, "Kile's scripting feature allows for the execution of ECMAScript code. Scripts can be managed through the scripting panel in the sidebar." As a reference, both JavaScript and ActionScript are dialects of ECMAScript.

Unfortunately, my answer won't TeX-related. But here we go. :)

A quick look into the ECMAScript Language Specification plus the section 13.2 (API Reference) of The Kile Handbook made me come up with the following example:

  1. I created a new script and called myscript.js with the content described as follows; Kile seems to save them in a specific scripts folder.

    var myCurrentDoc = (kile).currentTextDocument()
    var myName = (kile).getInputValue("Answer the question!", "What is your name?")
    myCurrentDoc.insertText("Hello " + myName)
    

    In line 1, I get a KileTextDocument object which reflects the currently active text document. Please note that my code has no error checking! In line 2, the getInputValue method opens a dialog with the given caption and label; the variable myName gets the returned value. In line 3, I simply insert the text.

    Kile 1

  2. I saved the script and now it's available on the sidebar:

    Kile 2

  3. Let's say I create a dummy test.tex file with the following content:

    \documentclass{article}
    
    \begin{document}
    
    | % suppose the cursor is here.
    
    \end{document}
    

    Kile 3

  4. Running the script:

    Kile 4

  5. The result:

    Kile 5

    When clicking OK:

    Kile 6

There we go! My first script in Kile. :)

Take a look in the API Reference. It might have some useful methods, but beware! According to the handbook:

Please note that the scripting API has not been finalized yet. The API described below might change in future versions of Kile.

Sorry to come up with this simple example, that's the only idea I had in such short time. :)

By the way: boas festas, amigo! :)

Related Question