Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Can someone please show me an example script in Kile?

I want a example.

.

.

.

.

enter image description here

share|improve this question

1 Answer 1

up vote 13 down vote accepted

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! :)

share|improve this answer
    
Perfect, this is already beginning to get me to touch it. Thank you. And Merry Christmas to you too. –  Regis da Silva Dec 25 '11 at 1:47
    
Now, how to find (or locate) text (CTRL+F), using this method? –  Regis da Silva Dec 25 '11 at 2:08
    
@Regis: Good question! I'm afraid there's no easy solution. :( Kile's scripting API seems to be promising, but as stated in the manual, it's under heavy development and likely to change in the future. IMHO the provided list of methods is quite limited. A possible workaround is to implement your own find method, that is, map the whole text to a data structure and manipulate lines and columns, and use one of Kile's methods to set the cursor position on-screen. I'm not sure if it's worth. As I see it, the scripting API provides just a basic interation experience. :( –  Paulo Cereda Dec 25 '11 at 9:47
    
But you did not say it gives to use javascript? Does it not to try this way? –  Regis da Silva Dec 25 '11 at 12:19
    
@Regis: Yes, you can use JS, but IMHO the problem resides in the document interface provided by the Kile API. The available methods are scarce, so there's nothing much to do. JS can help a lot, but you are always bounded by the API. Of course, I'm not very well versed in JS, so maybe anyone else might come up with an answer to this particular issue. But my programmer intuition tells me there's nothing we can do unless hacking the API implementation itself. –  Paulo Cereda Dec 25 '11 at 13:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.