1

What is wrong with the following code for script of the texstudio

var linenumber = 0;
var keynumber = 1;

dialog = UniversalInputDialog(["a","b","c","d","e","g","h","i","j","k"],"Insert The Postfix:","com")
dialog.setWindowTitle("Insert The Postfix")
if (dialog.exec() != ""){
    var postfix = dialog.get("com");
}
while(!cursor.atEnd()) {
    linenumber++;
    line = editor.text(linenumber);
    ind = line.search('\\label{');
    if (ind == -1) {
        continue;
    }
    var env = editor.document().getLastEnvName(linenumber)
    if (env.localeCompare("equation") && env.localeCompare("equation*") && env.localeCompare("eqnarry") && env.localeCompare("gather")) {
        continue;
    }
    cursor.moveTo(linenumber, ind + 6);
    // Serparating key
    var str = line.substring(ind + 6, line.length);
    var ind2 = str.search('}');
    var key = str.substring(0, ind2);
    // Checking what is the key and writing
    if (!key.localeCompare("")) {
        editor.write(keynumber.toString());
        keynumber++;
    } else if (!key.localeCompare("key")) {
        cursor.deleteChar();
        cursor.deleteChar();
        cursor.deleteChar();
        editor.write(keynumber.toString());
        keynumber++;
    }
}

This code is intended to label automatically equations with unique labels. Assuming that "\label{key}" is in the tex file. However, when I run texstudio stops. Is there a way to compile it outside the texstudio environment for debugging?

0

The following code will work instead

%SCRIPT
dialog = UniversalInputDialog(["","a","b","c","d","e","g","h","i","j","k"],"Insert The Postfix:","com")
dialog.setWindowTitle("Insert The Postfix")
if (dialog.exec() != ""){ 
var postfix = dialog.get("com")
}
cur = editor.document().cursor(1,0,20)
for(i = 1;i<100;i++){
    editor.replace("\\begin{equation}\\label{key}","",cur,"\\begin{equation}\\label{"+i+postfix+"}")
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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