#pragma rtGlobals=3 #pragma version=0.1 Static strconstant theFileName = "LaTeX2PICT" Function LaTeX2PICT(LTXstr,fsize, style, iname, [prterr]) string LTXstr, iname variable fsize, style, prterr if (ParamIsDefault(prterr)) prterr = 0 endif iname = CleanUpName(iname,0) make/FREE/T/N=2 tS="" // set the style switch(style) case 0: // straight up latex break case 1: // in-line equation tS = "$" break endswitch // encode the equation string theEQN = tS[0] + LTXstr + tS[1] // encode the preamble string thePreamble sprintf thePreamble, "\documentclass[%dpt,class=scrreprt]{standalone}\r",fsize string theLaTeX = thePreamble + "\begin{document}\r" + theEQN + "\r\end{document}" string theTempFolder = SpecialDirPath("Temporary",0,0,0) string theTempFolderU = SpecialDirPath("Temporary",0,1,0) string theTempFile, theCmd, theSys // define the files string theTeXFile = theFileName + ".tex" string theDVIFile = theFileName + ".dvi" string thePDFFile = theFileName + ".pdf" string theEPSFile = theFileName + ".eps" // open and write to the tex file variable refNum, rtn NewPath/O/Q LaTeX2PDF theTempFolder close/A // precaution to flush any open files first open/Z/P=LaTeX2PDF refNum as theTeXFile fprintf refNum, "%s", theLaTeX close refNum // set the path where it all happened theTempFile = theTempFolderU + theFileName theTempFolderU = RemoveEnding(theTempFolderU) // run the compiler and get the picture theSys = IgorInfo(2) StrSwitch (theSys) case "Windows": theCmd = generateWinCmd(theTempFolderU, theTempFile) break case "Macintosh": theCmd = generateMacCmd(theTempFolderU, theTempFile) ExecuteScriptText/UNQ/Z theCmd if (V_flag==0) LoadPICT/Q/O/P=LaTeX2PDF thePDFFile, $iname rtn = 0 else switch(prterr) case 0: break case 1: print "No compilation. See log at " + theTempFolderU break case 2: print S_value break endswitch rtn = -1 endif break endswitch return rtn end Function/S generateMacCmd(theTFU, theTF) string theTFU, theTF string theCmd sprintf theCmd, "/Library/TeX/texbin/pdflatex -output-directory='%s' '%s'", theTFU, theTF sprintf theCmd, "do shell script \"%s\"", theCmd return theCmd end Function/S generateWinCmd(theTFU, theTF) string theTFU, theTF string theCmd = "" return theCmd end