// -*- ASCII:EDT -*- // ConTeXt.edt // (schlicht 20030124) //-------------------- // Save this file as %b\Exec\ConTeXt.edt, assign a menu entry to it in the Accessories // menu, and adjust the following options to your liking: Assign("BATCH-ConTeXt","0"); // don't do this, or the rest of the options will be ignored Assign("Background-ConTeXt","1"); // run ConTeXt in the background Assign("Errors-ConTeXt","1"); // show errors Assign("Warnings-ConTeXt","0"); // show warnings Assign("Viewer-ConTeXt","1"); // run the viewer Assign("Search-ConTeXt","0"); // forward search (this only works with yap, of course) Assign("dvi-ConTeXt","1"); // default ConTeXt output is dvi (not pdf) // ------------------------------------------------------------------------------------------------- Requires(20020323); // Requires this build of WinEdt to work properly SetOK(1); // Just in case ... SetErrorFlag(0); // Try to be smart: // If we find the statement `\setupoutput[*]' in the preamble of the // document, we'll start the appropriate viewer. GetPreamble("\starttext",0); FindInString("%!0","<@{{^{\\|%}}}\\setupoutput\[*pdf*\]",1,2,1); IfOK("Assign('dvi-ConTeXt','0');"); FindInString("%!0","<@{{^{\\|%}}}\\setupoutput\[*dvi*\]",1,2,1); IfOK("Assign('dvi-ConTeXt','1');"); // If the output format is dvi AND the global register %0 contains "--src", // then let's assume you want source specials also for ConTeXt: IfStr("%$('dvi-ConTeXt');%0","1--src","=",> "Assign('-passon','--passon=""--src""');",> "Release('-passon');"); // We need to wait, if we want any of these options: IfNum("%$('Errors-ConTeXt');%$('Warnings-ConTeXt');%$('Viewer-ConTeXt');",0,">",> "Assign('Wait-ConTeXt','1');","Assign('Wait-ConTeXt','0');"); // Close the current Document in Acrobat (Reader) using DDE // Avoid the error message because Acrobat locks the ".pdf" file for writing... IfStr("%$('dvi-ConTeXt');","0","=",!`> IfFileLocked("%P\%N.pdf", 00110, // Acrobat is probably Locking it!<> !*SendMessage("%$(:Acro-Title:); - ", $0000, $0000); // Dummy Message<> IfOK(!|> DDEOpen("%$(""AcroRead"")","acroview","control");> DDEExe("[DocOpen(""%P\%N.pdf"")]"); // Has to be Opened via DDE DocOpen<> DDEExe("[DocClose(""%P\%N.pdf"")]"); // for DocClose to work...<> DDEClose;> StartWorking('Closing PDF Document...');> LetRegNum(0,0);> Loop(!||LetRegNum(0,%!0+1);IfNum(%!0,9999,'>','Stop;'); // Prevent an Infinite Loop<> IfFileLocked("%P\%N.pdf", 00110,> !'SendMessage("%$(:Acro-Title:); - ", $0000, $0000);',> !'Stop;',!'Stop;');||);> StopWorking;> |);*);> `); SetOK(1); // Just in case ... SetErrorFlag(0); CloseFile("%b\_Run.log",1); IfStr("%$('Wait-ConTeXt');","1","=",|StartWorking("ConTeXt %N%T");|); // Delete the working output files... IfFileExists("%P\%N.log",!"DeleteFile('%P\%N.log')"); IfStr("%$('dvi-ConTeXt');","1","=",> `IfFileExists("%P\%N.dvi",!"DeleteFile('%P\%N.dvi')");`,> `IfFileExists("%P\%N.pdf",!"DeleteFile('%P\%N.pdf')");`); UpdateStatus; // If you want BATCH mode, you have to create the file ConTeXt.bat yourself. IfStr("%$('BATCH-ConTeXt');","1","=",> !|Run('%~B\Bin\TeX\ConTeXt.bat "%N%T"',"%P", 0,0, "ConTeXt ...",0,1);> StopWorking;Exit;|); LetReg(0,"0"); Release('-batch'); IfStr("%$('Background-ConTeXt');","1","=",|LetRegNum(0,"%!0+10000");Assign('-batch','--batch');|); //// detached mode doesn't work with texexec: //IfStr("%$('Detached-ConTeXt');","1","=",|LetRegNum(0, "%!0+1000");Assign('-batch','--batch');|); //// neither does redirecting the output: //IfStr("%$('Log-ConTeXt');","1","=",|LetRegNum(0, "%!0+10");Assign('-batch','--batch');|); IfStr("%$('Wait-ConTeXt');","1","=",|LetRegNum(0,"%!0+100");|); // *** Execute it!!! SetOK(1); // Just in case ... WinExe('','texexec %$(|-batch|); %$(|-passon|); "%N%T"','%P','ConTeXt ...',%!0,"%$('Wait-ConTeXt');","","",""); IfOK('Relax;','StopWorking;> Prompt("Error starting ConTeXt!%\> See WinEdt''s TeX Configuration Wizard%\> for detailed diagnosis of your TeX system.");> UpdateStatus;ErrorLogUpdate;Exit;'); UpdateStatus; IfStr("%$('Wait-ConTeXt');","1","=",|Relax;|,|Exit;|); ErrorLogUpdate; // Only "real / serious" Errors (not Warnings) IfStr("%$('Errors-ConTeXt');","1","=",> |> IfLogErrors(!"StopWorking;FindError(0,1,0,1,-1,-1,-1,6);Exit;",> `IfStr("%$('Warnings-ConTeXt');","1","<>","ShowErrorLog(0);");`,0,1,-1,-1,-1,6);> |); // All Enabled Errors and Warnings IfStr("%$('Warnings-ConTeXt');","1","=",> |> IfLogErrors(!"ShowErrorLog(1);","ShowErrorLog(0);",0,1,1,1,1,6);> |); IfStr("%$('dvi-ConTeXt');","1","=","LetReg(9,'dvi');","LetReg(9,'pdf');"); IfFileExists("%P\%N.%!9",> !`IfStr("%$('Viewer-ConTeXt');","1","=",> !``IfStr("%$('dvi-ConTeXt');","0","=",> *Run(|%$('AcroRead'); "%P\%N.pdf"|,'%P',0,0,'',1,1);*,> !*IfStr("%$('Search-ConTeXt');","1","=",> :Run(|%$('DVIView'); -1 -s "%!l %p\%n%t" "%P\%N.dvi"|,'%P',0,0,'',1,1);:,> :Run(|%$('DVIView'); -1 "%P\%N.dvi"|,'%P',0,0,'',0,1);:);*);``);`,> // Something is wrong with your TeX system or your document> // Nothing WinEdt can do for you at this stage...> !`Prompt("ConTeXt failed to create a %!9 file.%\> For possible explanations start the command from the Command Prompt...");`); StopWorking; End;