Problem to include macro/script

reliak
2014-03-29
2014-04-02
  • reliak
    reliak
    2014-03-29

    Hey there,

    I'm trying to include another script/macro. According to the manual, this should be possible via the "include" function.
    I have created a macro named "Test" with "var bla = "hello";" and tried to include it in another script
    via "include("Test");". When I try to access "bla", it gives me the error "Can't find variable abc".
    I also tried to include a script from the filesystem; same problem.

    Any idea what I am doing wrong?

     
  • Tim Hoffmann
    Tim Hoffmann
    2014-04-01

    var bla = "hello";

    By defining the variable with var you indicate that it should be visible only in the local context. To make a variable global (and thus accessible in other scripts) just leave out the var:

    bla = "hello";
    
     
  • reliak
    reliak
    2014-04-01

    Thanks, that worked!

    I have another question :)
    Is it possible to access the "Find Dialog" via scripting?
    Or is there a more detailed document, where I can find the objects that I can access via scripting (I already know the manual: http://texstudio.sourceforge.net/manual/current/usermanual_en.html)

     
    Last edit: reliak 2014-04-01
    • Tim Hoffmann
      Tim Hoffmann
      2014-04-01

      You can start the Find Dialog via scripting, but I don't think it's possible to control it.

      There is no further documentation apart from the manual and the example links in the wiki. It would be too much effort to maintain such a document because scripting has access to a good part of the internal structures in TXS.

      You can find out what properties an object has by introspection. See the "Show all properties of an object" in the manual. However, it will also show you a lot of internal stuff you most likely will never use. Maybe you also have to look up the original source to find out what a function exactly does.

       
  • Tim Hoffmann
    Tim Hoffmann
    2014-04-01

    But when I define a function in an included script, it is not callable.
    But when I assign it to a variable it works, for example:
    function getBla(){ return ""; }
    is not callable, but:
    bla = function getBla(){ return ""; }
    is callable via "bla();"

    I have no problem with assigning a function to a variable, but I would prefer it, if I could just call the function. Is that possible?

    Currently not. The context was not transfered to the calling script. I've implemented that now (hg 4349 (ec3dc6cca625)). will be included in the next release.

     
  • reliak
    reliak
    2014-04-02

    Thanks for the answers and also for the best LaTeX Editor I know :)