Nicolae Garleanu | 8 Aug 22:48

macro help

Hello.

I would like to do the following with the help of a macro: if run from file XXX_YYY.tex, I would like it to take the name of the file, i.e., `XXX_YYY’, strip the specified string `YYY’ (alternatively, everything following the last `_’) and replace it with another string ‘_ZZZ’, after which it would run a set of commands on XXX_ZZZ.tex.

What is the easiest way to generate the string `XXX_ZZZ.tex’ and make sure that winedt runs the commands on a file with that name? Can you perhaps point to macros already distributed from which I can lift the appropriate pieces of code? (It would be faster and safer for me to modify existing code than writing some from scratch.)

Thank you very much.

Nicolae

 

David Huffer | 11 Aug 17:15

RE: macro help

On Friday, August 08, 2008 4:49, Nicolae Garleanu wrote:

 > ...I would like to do the following with the
 > help  of  a  macro:   if   run   from   file
 > XXX_YYY.tex,  I  would  like  it to take the
 > name of the file, i.e., `XXX_YYY', strip the
 > specified   string   `YYY'   (alternatively,
 > everything  following  the  last  `_')   and
 > replace it with another string '_ZZZ', after
 > which it would run  a  set  of  commands  on
 > XXX_ZZZ.tex...What  is  the  easiest  way to
 > generate the string `XXX_ZZZ.tex'  and  make
 > sure that winedt runs the commands on a file
 > with that name? Can  you  perhaps  point  to
 > macros  already distributed from which I can
 > lift the appropriate  pieces  of  code?  (It
 > would  be  faster and safer for me to modify
 > existing   code   than   writing  some  from
 > scratch.)...

Something like this

   DosToUnix("%p\%n%t",0);
   Prompt("File name is %!0.");
   FindInString( "%!0", "_*\.tex", 1, 2, 1);
   ReplaceInString( "%!0", "_ZZZ\.tex", %!1, %!2, 1, 3);
   Prompt("File name replaced is %!3.");
   End;

is probably one of the easiest ways to generate the string
'XXX_ZZZ.tex' from  XXX_YYY.tex. it replaces anything in the
filename following an underscore and before .tex with _ZZZ.

--
 David

Nicolae Garleanu | 12 Aug 00:58

RE: macro help

Hi David.
Thanks a lot! This looks great (or, to be honest, it works great when I test it).
I then realized the even more embarrassing fact that I did not know how to apply a macro I had written to run
from a given file --- that is, a macro SomeMacro.edt that I invoke from a .tex file to run a sequence of
standard macros like 'Latex.edt' and 'dvi2ps.edt' --- in the new situation --- that is, when the input
file is the one whose name is in a register (e.g., %3). (I tried playing with the command WinExe, but clearly
did not stumble upon the correct way.) This is a very basic WinEdt issue, I am aware.
Best,
Nicolae

-----Original Message-----
From: David Huffer [mailto:David.Huffer <at> csosa.gov]
Sent: Monday, August 11, 2008 8:16 AM
To: winedt+list <at> wsg.net
Subject: RE: [WinEdt] macro help

On Friday, August 08, 2008 4:49, Nicolae Garleanu wrote:

 > ...I would like to do the following with the
 > help  of  a  macro:   if   run   from   file
 > XXX_YYY.tex,  I  would  like  it to take the
 > name of the file, i.e., `XXX_YYY', strip the
 > specified   string   `YYY'   (alternatively,
 > everything  following  the  last  `_')   and
 > replace it with another string '_ZZZ', after
 > which it would run  a  set  of  commands  on
 > XXX_ZZZ.tex...What  is  the  easiest  way to
 > generate the string `XXX_ZZZ.tex'  and  make
 > sure that winedt runs the commands on a file
 > with that name? Can  you  perhaps  point  to
 > macros  already distributed from which I can
 > lift the appropriate  pieces  of  code?  (It
 > would  be  faster and safer for me to modify
 > existing   code   than   writing  some  from
 > scratch.)...

Something like this

   DosToUnix("%p\%n%t",0);
   Prompt("File name is %!0.");
   FindInString( "%!0", "_*\.tex", 1, 2, 1);
   ReplaceInString( "%!0", "_ZZZ\.tex", %!1, %!2, 1, 3);
   Prompt("File name replaced is %!3.");
   End;

is probably one of the easiest ways to generate the string
'XXX_ZZZ.tex' from  XXX_YYY.tex. it replaces anything in the
filename following an underscore and before .tex with _ZZZ.

--
 David

WinEdt Team | 12 Aug 20:04
Favicon

Re: macro help

> Thanks a lot! This looks great (or, to be honest, it works
> great when I test it). I then realized the even more
> embarrassing fact that I did not know how to apply a macro I
> had written to run from a given file --- that is, a macro
> SomeMacro.edt that I invoke from a .tex file to run a sequence
> of standard macros like 'Latex.edt' and 'dvi2ps.edt' --- in the
> new situation --- that is, when the input file is the one whose
> name is in a register (e.g., %3). (I tried playing with the
> command WinExe, but clearly did not stumble upon the correct
> way.) This is a very basic WinEdt issue, I am aware.

Take a look at the Compile Selected.edt macro in Exec\MIKTeX
Folder. The easiest way to go is to temporarily reset the main
file (as all the standard macros run on this file) and after a
call to LaTeX.edt reset the file back.

  Assign('Main_File','%!F');
  SetMainFile('your _zzz.tex file');
  // SetMainFile('%!3');  if this is the register that contains the input 
filename

  Exe('%b\Exec\MiKTeX\LaTeX.edt');

  SetMainFile("%$(|Main_File|);");   // Reset the Main File

Alternative is to forget about standard latex.edt files and use
WinExe or Run with appropriate parameters directly in your
script. These functions are indexed in the macro manual and all
their parameters are explained there. Run is simpler to use
than WinExe (but it cannot do some fancy stuff with detached
execution, etc...).

Best regards,

alex


Gmane