#pragma TextEncoding = "UTF-8" #pragma rtGlobals=3 #pragma version=0.2 Static strconstant theFileName = "LaTeX2PICT" // convert a LaTeX string to a PICT Function ltxs2p(lstr) string lstr LaTeX2PICT(lstr) return 0 end // convert a LaTeX notebook to a PICT Function ltxn2p(ntbk) string ntbk Notebook $ntbk, getData=2 LaTeX2PICT(S_value,fulldoc=1) return 0 end // convert a LaTeX string to a PICT // provides additional levels of control Function LaTeX2PICT(LTXstr,[fsize, iname, prterr, fulldoc, xpreamble]) string LTXstr, iname, xpreamble variable fsize, prterr, fulldoc if (ParamIsDefault(fsize)) fsize = 12 endif if (ParamIsDefault(iname)) sprintf iname, "LaTeXPICT%3.0f", abs(enoise(100)) endif iname = CleanUpName(iname,0) if (ParamIsDefault(prterr)) prterr = 0 endif if (ParamIsDefault(fulldoc)) fulldoc = 0 endif if (ParamIsDefault(xpreamble)) xpreamble = "" endif // encode the LaTeX string string thePreamble, theLaTeX if (!fulldoc) if (fsize==0) thePreamble = "\documentclass{standalone}\r" else sprintf thePreamble, "\documentclass[%dpt,class=scrreprt]{standalone}\r",fsize endif theLaTeX = thePreamble + xpreamble + "\begin{document}\r" + LTXstr + "\r\end{document}" else theLaTeX = LTXstr endif // set the folders string theTempFolder = SpecialDirPath("Temporary",0,0,0) string theTempFolderU = SpecialDirPath("Temporary",0,1,0) string theTempFile // 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 NewPath/O/Q LaTeX2PICT theTempFolder // generate the notebook and save it KillWindow/Z LaTeX2PICTNtbk NewNotebook/F=0/K=3/N=LaTeX2PICTNtbk/V=0 Notebook LaTeX2PICTNtbk, text=theLaTeX SaveNotebook/O/S=6/P=LaTeX2PICT LaTeX2PICTNtbk as theTeXFile // set the path where it all happened theTempFile = theTempFolderU + theFileName theTempFolderU = RemoveEnding(theTempFolderU) // run the compiler and get the picture variable rtn string theSys, theCmd theSys = IgorInfo(2) StrSwitch (theSys) case "Windows": // SOMEONE PLEASE WRITE THIS SECTION theCmd = generateWinCmd(theTempFolderU, theTempFile) break case "Macintosh": theCmd = generateMacCmd(theTempFolderU, theTempFile) ExecuteScriptText/UNQ/Z theCmd if (V_flag==0) LoadPICT/Q/O/P=LaTeX2PICT 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