2

In WinEdt there is a toolbar button for compiling current selection of the document. But is it possible to compile current text block without manual selection? By text blocks I means parts of text separated by empty lines.

For example, if I have the following document:

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}% one
\draw[fill=red] (0,0) circle (1);
\end{tikzpicture}

\begin{tikzpicture}% two
\draw[fill=teal] (1,1) circle (2);
\end{tikzpicture}

\begin{tikzpicture}% three
\draw[fill=olive] (2,2) circle (3);
\end{tikzpicture}

\end{document}

and my cursor is inside the second tikzpicture environment, I would like to compile these second text block by pressing some keyboard shortcut or clicking some toolbar button.

4

This is quite easy to achieve. The only restriction is that the cursor can not be in the first line of the block (\begin{tikzpicture}, for instance) when you launch the command we are going to define.

Now, we'll redefine the command 'Compile Selected' to do what you want.

Go to "Options" -> "Options Interface" and double-click the "Main Menu" item:

enter image description here

A local copy of MainMenu.ini gets opened. In this file, substitute the lines

  ITEM="Compile_Selected"
    CAPTION="Compile &Selected"
    CONFIG_FILTER="Default"
    IMAGE="CompileSel"
    MACRO="Exe('%b\Exec\Compile Selected.edt');"
    SHORTCUT="8312::Shift+F9"
    REQ_FILTER=`"%!M=TeX"*"%!m=TeX"`+
               `|"%!M=TeX:STY"|"%!M=TeX:AUX"|"%!m=TeX:STY"|"%!m=TeX:AUX"`
    REQ_DOCUMENT=1
    REQ_SELECTED_TEXT=1

with

  ITEM="Compile_Selected"
    CAPTION="Compile &Selected"
    CONFIG_FILTER="Default"
    IMAGE="CompileSel"
    MACRO="IfSel('0','=',!'ParUp;SelParDown');"+
          "Exe('%b\Exec\Compile Selected.edt');"
    SHORTCUT="8312::Shift+F9"
    REQ_FILTER=`"%!M=TeX"*"%!m=TeX"`+
               `|"%!M=TeX:STY"|"%!M=TeX:AUX"|"%!m=TeX:STY"|"%!m=TeX:AUX"`
    REQ_DOCUMENT=1
    // REQ_SELECTED_TEXT=1

and the lines

  ITEM="TeX:Compile_Selected"
    CAPTION="Compile &Selected"
    CONFIG_FILTER="MiKTeX;TeX Live|Default"
    IMAGE="CompileSel"
    MACRO="Exe('%b\Exec\TeX\Compile Selected.edt');"
    SHORTCUT="8312::Shift+F9"
    REQ_FILTER=`"%!M=TeX"*"%!m=TeX"`+
               `|"%!M=TeX:STY"|"%!M=TeX:AUX"|"%!m=TeX:STY"|"%!m=TeX:AUX"`
    REQ_DOCUMENT=1
    REQ_SELECTED_TEXT=1

with

  ITEM="TeX:Compile_Selected"
    CAPTION="Compile &Selected"
    CONFIG_FILTER="MiKTeX;TeX Live|Default"
    IMAGE="CompileSel"
    MACRO="IfSel('0','=',!'ParUp;SelParDown');"+
          "Exe('%b\Exec\TeX\Compile Selected.edt');"
    SHORTCUT="8312::Shift+F9"
    REQ_FILTER=`"%!M=TeX"*"%!m=TeX"`+
               `|"%!M=TeX:STY"|"%!M=TeX:AUX"|"%!m=TeX:STY"|"%!m=TeX:AUX"`
    REQ_DOCUMENT=1
    // REQ_SELECTED_TEXT=1

At this point press Shift+Ctrl+F9 to reload the file.

That's it.

Now, when you launch the command 'Compile Selected' (Shift+F9), its behavior is the same as before when you have some selected text. But when you have no selected text, it grabs the contents of the block between two empty lines and compiles it.

  • I noticed there is a menu item "Edit->Format->Select Paragraph", but it is strange that when clicking it, only current line is selected. Why? – Z.H. Apr 3 '15 at 9:56
  • If line wrap in enabled, only one line is selected! But I always need line wrap... – Z.H. Apr 5 '15 at 7:16
0

At last I have managed to write a WinEdt macro which overcomes the shortcoming of the solution of Karl Koeller. This macro is modified from Compile Selected.edt file.

// Compiles current paragraph in current TeX Document.

  Requires(20110504); // Requires this build of WinEdt to work properly
  // Already Running...
  IfConsoleRunning(!"ShowConsole(1);>
    Prompt('Another application is already running in WinEdt''s Console.');>
    ShowConsole(1);FocusConsole(1);Exit;");
  SaveDoc;

  PushTagsandRegisters;

  SetOK(1);  // Just in case ...
  SetErrorFlag(0);

  Assign('Compile-Flag','');
  Assign('Main_File','%!F');

  LetReg(7,'%P');
  LetReg(6,'%N');

  SaveFind;
  SetRegEx(1);
  SetFindStr("<>");
  SetFindinFilesCurrent(1);
  SearchReset;
  FindInFiles;
  RestoreFind;
  SetTracking(0);
  SetWrap(-1);
  FindNext(-4,-1);
  Loop(!|>
    GetFindItem(3,3);>
    IfOK(!'>
      IfNum(%!3+1,%!l,"<=",!"LetRegNum(4,%!3+1);","LetRegNum(5,%!3+1);Stop;");>
    ','Stop;');>
    FindNext(1,-1);|);
  //Prompt("%!l  %!4-%!5");
  LetReg(9,"");
  Loop(!|>
    IfNum(%!4,%!5,'<=',!'GetLine(3,%!5);InsertByIndex(9,"%!9","%!3%\");LetRegNum(5,%!5-1);'>
    ,'Stop');>
  |);
  //Prompt("%!9");
  RestoreWrap;
  SetTracking(1);

:Start:: ============================================================

  StartWorking("Compile current paragaph ...");

  // Create Temporary File using the same (unicode) format as the Main File %F...
  OpenOutput("%!7\%!6.tmp",0,0,0,"%F");  // Open temporary TeX file for writing
  WrL("%% -*- Mode: TeX -*-");
  Translate(2,"%!m","%!9",9);            // Translate Output?
  FindInString("%!9",!"<\\begin\{document\}",1,1,11);
  IfOK("JMP('Preamble_OK');");           // Main File already contains \begin{document}
  GetPreamble("\begin{document}",8);     // Get Preamble in Register 8
  // Default Preamble (if necessary add more packages terminated with %\>):
  IfOK(!'Relax;',!|LetReg(8,>
    !'\documentclass{article}%\'+>
    !'\usepackage{amsmath}%\'+>
  );|);
  Translate(2,"%!M","%!8",8);            // Translate Output?
  WrL("%!8");                            // Write String
  WrL("\begin{document}");               // LaTeX begin...
  WrL;                                   // Empty Line (just in case)
:Preamble_OK:: ======================================================
  WrL("%!9");                            // Write String
  WrL;                                   // Empty Line (just in case)
  WrL("\end{document}");                 // LaTeX end...
  CloseOutput;                           // Close temporary file

  SetMainFile("%!7\%!6.tmp");            // Reset the Main File

:PDF:: ==============================================================

  Exe('%b\Exec\TeX\PDFLaTeX.edt');
  IfStr("%$('Compile Status');",!"OK",!"<>",!"JMP('Cleanup');");
  IfFileExists("%P\%N.pdf",!"Relax;",!"JMP('Cleanup');");
  Exe('%b\Exec\PDF\PDF Search.edt');
  JMP('Cleanup');

:Cleanup:: ==========================================================

  SetMainFile("%$(|Main_File|);");       // Reset the Main File
  Exe("%b\Exec\%!C\ExeMode.edt");
  UpdateStatus;
  FocusConsole(-1);

  SetExitHandler;

  PopTagsandRegisters;
  StopWorking;
  Assign('Compile-Flag','');

End;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.