[texworks] Script: open files in master document \input(myFileName.tex)

Paul A Norman paul.a.norman at gmail.com
Thu Mar 18 01:41:57 CET 2010


Hi All,

Hope this may help others -

When using a master document say myMainDoc.tex you often have lots of
input{} files and it is useful to be able to open these easily, and
directly sometimes.

If the user highlights a file name in an \input{myFileName.tex}

Assuming that  myMainDoc.tex is in the same directory as its 'children
files' ...

----------

// TeXworksScript
// Title: Open Highlighted File Name
// Description: Opens Highlighted File Name
// Author: Paul A Norman
// Version: 0.1
// Date: 2010-03-18
// Script-Type: standalone

// Assuming that  myMainDoc.tex is in the same directory as its 'children files'

// debugger;

var openFileName = TW.target.selection;

   if ((openFileName != '') & (openFileName != null))
	   {
		
		// couldn't find a property for current directory for master
document - work around
    var currentFileName =  TW.target.fileName;
		
		 if (currentFileName.indexOf("/") > -1) // OS Win and Nix only not
sure what Mac looks like
		     {
				   pathSlash = "/";
					 }
				else
			  	 {
				   pathSlash = "\\";
				    } 	
		
   var currentDirectoryLastDelim =  currentFileName.lastIndexOf(pathSlash);
	
	   var  currentDirectory =
currentFileName.substr(0,currentDirectoryLastDelim +1)
		
		  TW.app.openFile(currentDirectory + openFileName);
		
		  } // end if currentFileName


More information about the texworks mailing list