0

I'm trying to use latexdiff script in the texstudio. What is the problem with the following script.

%SCRIPT

var cf = app.getCurrentFileName();

var ld = new String(cf);
ld=ld.substring(0,ld.lastIndexOf("/"));

information("Select original file");
fileChooser.setDir(ld);
fileChooser.setFilter("TeX files (*.tex)");
fileChooser.exec();
var fold=new String();
fold=fileChooser.fileName();
fold=fold.substring(fold.lastIndexOf("/")+1);

information("Select revised file");
fileChooser.setDir(ld);
fileChooser.setFilter("TeX files (*.tex)");
fileChooser.exec();
var fnew=new String();
fnew=fileChooser.fileName();
fnew=fnew.substring(fnew.lastIndexOf("/")+1);

information("Select changes tracking file");
fileChooser.setDir(ld);
fileChooser.setFilter("TeX files (*.tex)");
fileChooser.exec(fout);
var fout=new String();
fout=fileChooser.fileName();
fout=fout.substring(fout.lastIndexOf("/")+1);

var cmd=new String();
cmd="cd "+ld+" ; latexdiff-so "+fold+" "+fnew+" > "+fout+"\"";
dialog=new UniversalInputDialog();
dialog.add(cmd,"run command?");
var rpl=dialog.exec();
if(rpl!=null){
    system(cmd);
}

delete(cmd);
delete(dialog);
delete(fold);
delete(fnew);
delete(fout);
delete(ld);

When I'm trying to run this script I get this error:

"The specified stdout redirection is not supported: "> CHANGE.tex"". Please see the manual for details."

2

I struggled a lot dealing with output redirect, as it seems to have been broken since the previous answer. system() now seems to discard anything after and including the '>' sign, even when it is in quotation in the cmd string (TeXstudio 2.12.0 on Windows 10). My solution was to redirect to /dev/null (this is supported), which makes it possible to retrieve the output of latexdiff by the readAllStandardOutputStr() on the process object returned from system() and then write it to file and compile and show the result (guesswork with buildManager).

I hope my version of the TeXstudio latexdiff script can be of use for others. Does not use 'cmd', so it might work on non-windows as well.

%SCRIPT

// Execute latexdiff-so with current file as new file
// optional magic comments in .tex file as input parameters:
//   !TeX latexdiff:original = <original file>
//   !TeX latexdiff:output = <output file>
// Requires perl and latexdiff to be installed

var cf = app.getCurrentFileName();
var ld = new String(cf);
ld=ld.substring(0,ld.lastIndexOf("/")); //Local directory
fnew = cf;

var fold = editor.document().getMagicComment("latexdiff:original");
if(fold == "")
{
fileChooser.setDir(ld);
fileChooser.setFilter("TeX files (*.tex)");
fileChooser.exec();
fold=fileChooser.fileName();
}

var fout = String(editor.document().getMagicComment("latexdiff:output"));
if(fout == "") // if path not given in magic comment
{
fileChooser.setDir(ld);
fileChooser.setFilter("TeX files (*.tex)");
fileChooser.exec();
fout=fileChooser.fileName();
}
else if(!((fout.indexOf(":") != -1) || (fout.indexOf("/")==0)))
fout = ld + '/' + fout; // if relative path, make absolute

var proc = system("latexdiff-so \"" + fold + "\" \"" + fnew + "\" > /dev/null", ld)
proc.waitForFinished();
writeFile(fout, proc.readAllStandardOutputStr());
//app.load(fout); // load diff file
buildManager.runCommand("txs:///quick", fout);
//app.load(fnew); // change back to original file

delete(proc);
delete(fold);
delete(fout);
delete(fnew);
delete(cf);
delete(ld);
3

All commands are executed directly. There is no shell involved. If you need shell functionality you have to wrap the call in a shell:

sh -c "/path/to/testscript foo > bar"

or on Windows:

cmd /C "/path/to/testscript.bat foo > bar"

See section Shell Functionality in the user manual.

  • The link seems to be corrupted. Can you please give the change in the code. I'm using the windows. – Hamid Jul 30 '16 at 14:41
  • @Hamid Link fixed. – Tim Hoffmann Jul 31 '16 at 12:21
1

Christian's script didn't quite work for me. Using Windows. After quite a bit of experimentation, here's what did work:

...
var ldfout = ld+"\\"+fout;
var cmdstr = new String();
cmdstr = "latexdiff-so "+fold+" "+fnew+" > /dev/null";
var proc = system("cmd /C "+cmdstr,ld);
proc.waitForFinished();
writeFile(ldfout, proc.readAllStandardOutputStr());
app.load(ldfout); // load diff file
buildManager.runCommand("txs:///quick", ldfout);

Things to note:

  • "cmd /C " needed in system call for Windows.
  • writeFile writes to TekStudio path, unless fout has global path
1

I got the following script from the link below the youtube video on "how to use Latexdiff by creating a macro", by Chas.

Nothing above worked for me, but this one worked like a charm. I am running windows10, and I installed Active Perl before creating the macro.

%SCRIPT

var cf = app.getCurrentFileName();

var ld = new String(cf);
ld=ld.substring(0,ld.lastIndexOf("/"));

information("old version");
fileChooser.setDir(ld);
fileChooser.setFilter("TeX files (*.tex)");
fileChooser.exec();
var fold=new String();
fold=fileChooser.fileName();
fold=fold.substring(fold.lastIndexOf("/")+1);

information("new version");
fileChooser.setDir(ld);
fileChooser.setFilter("TeX files (*.tex)");
fileChooser.exec();
var fnew=new String();
fnew=fileChooser.fileName();
fnew=fnew.substring(fnew.lastIndexOf("/")+1);

information("diff file by Chas");
fileChooser.setDir(ld);
fileChooser.setFilter("TeX files (*.tex)");
fileChooser.exec(fout);
var fout=new String();
fout=fileChooser.fileName();
fout=fout.substring(fout.lastIndexOf("/")+1);

ldfout = ld+"\\"+fout;

var cmdstr = new String();
cmdstr = "latexdiff-so "+fold+" "+fnew+" > /dev/null";
var proc = system("cmd /C "+cmdstr,ld);
proc.waitForFinished();
writeFile(ldfout, proc.readAllStandardOutputStr());
app.load(ldfout); // load diff file
buildManager.runCommand("txs:///quick", ldfout);

delete(cmdstr);
delete(dialog);
delete(fold);
delete(fnew);
delete(fout);
delete(ld);
delete(ldfout);
  • Why not linking the original source of the script, in your case the video? – epR8GaYuh Dec 11 '18 at 8:41
1

As suggested by epR8GaYuh, here is the original source of the script.

https://www.youtube.com/redirect?v=IAWEywCx9hQ&event=video_description&q=https%3A%2F%2Fgoo.gl%2FXTsv8i&redir_token=1t3DFuFCfMZZsmqSds-otFoISsF8MTU0NTExMTU2NkAxNTQ1MDI1MTY2

Just to be clear, the code is not listed in the video. The link is given when you click on "show more" in the comments below the video.

The correct video is the one with this image for the youtube video, and then butterflies in the beginning. enter image description here

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.