以下 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++;
}
}
此代码旨在自动用唯一标签标记方程式。假设“\label{key}”在 tex 文件中。但是,当我运行 texstudio 时,它停止了。有没有办法在 texstudio 环境之外编译它以进行调试?
答案1
下面的代码可以代替
%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+"}")
}