getRelativePath (Experimental)

Parent Previous Next

(Experimental) twPan.getRelativePath(mainPath, wantedPath) : string


Very much need this, and could not find a JavaScript function on the web for it, and it does not appear to be in PhpJs either, so it is experimental.


It was needed for working out relative file paths for graphics from main Tex document especially for use in Portable Tw situations.


MiKTeX and LaTeX endeavour to find a graphic on a relative path.


mainPath could be the main document's path, and wantedPath is the full path to the graphic, above, at or below the main document's position.


Relative path returned, or full path if in different tree.


Could be used as in ...


// TeXworksScript

// Title:  Insert Graphic(s) to Col Width

// Description: Allows multiple selection of file names and inserts with title description and copyright note, using column width

// Author:  Paul Norman

// Version: 0.3

// Script-Type: standalone

// Context: TeXDocument

// Shortcut: Alt+G, Alt+I



 eval(TW.app.getGlobal("helper_twPan")); // Un-Comment if Needed


//  eval(TW.app.getGlobal("helper_PhpJs")); // Un-Comment if Needed

//%: insertGraphics


         

var chosenImages =   TW.app.getOpenFileNames("Image Files (*.jpg *.jpeg *.png *.pdf)");


       

if (chosenImages.length > 0)

                          {

                           for (image in chosenImages)

                                {

         var graphicPath =   twPan.getRelativePath(TW.target.fileName,   chosenImages[image]);

                 

         var graphicCaption = twPan.prompt("Graphic Caption");

             graphicCaption = graphicCaption.toTitleCase();

             

         var copyRightInfo = twPan.prompt("Copyright Info");

         

         var includeGraphicsOptions = twPan.select("Graphic Options", ["[width=\\ScaleIfNeeded]","","[]","[width= ]"])

           

             TW.target.insertText(

                                "\\noindent\\includegraphics"

                                + includeGraphicsOptions

                                +"{"

                                + graphicPath

                                +"}\\captionCentredNote{"

                                + graphicCaption

                                +"}{"

                                + copyRightInfo

                                +"}\n"

                                );                                              

                                                                   

                                   } // End.  for (image in chosenImages)

                           } // End. if (chosenImages.length > 0)



Created with the Personal Edition of HelpNDoc: Free PDF documentation generator