[TxMt] Re: latex_watch.pl modification?

René Schwaiger sanssecours at f-m.fm
Fri Mar 27 12:13:58 UTC 2015


Hi Zvi,

> On 26 Mar 2015, at 16:18 , Zvi Biener <zvistrash at gmail.com> wrote:
> 
> Hi TextMaters,
> 
> I have a very superficial knowledge of perl, so I wonder if someone can help.
> Setup: before I compile my LaTeX document, I need to run a shell script (using sed) to find/replace certain strings. [There is a long story for why I need to do this, and why its not easily avoidable.]
> 
> Possible solution: I was wondering if I can insert something in the latex_watch.pl script that would run this shell script, without causing latex_watch to go into an infinite loop (since the shell script changes the underlying LaTeX file/s).
> 
> I've tried inserting the relevant code in several locations, but I can't seem to avoid the loop. That's not surprising, since I don't really know perl. Does anyone know if there is easy way to
> 
> 1) modify latex_watch.pl so it executes a shell script that modifies the underlying LaTeX file without going in to a loop?
> or

since the main loop of `latex_watch.pl` triggers the compilation after file changes, I don't think there is an easy way to execute your script in there, without causing an infinite loop.

> 2) cause the shell script to run on the file whenever the file changes by some other means?

That sounds like a good idea. You can use `callback.document.will-save` for that. A command with this semantic class will be called just before you save a file. E.g. To replace every occurrence of the word `bla` with the word `blubb` in tex files, create a command with the following content:

    #!/bin/bash

    sed s/bla/blubb/g

Use the following options:

Scope Selector: text.tex
Semantic Class: callback.document.will-save
Save: Nothing
Input: Document
  Format: Text
Output: Replace Input
  Format: Text
Caret Placement: Line Interpolation

I included a bundle with one command called “Replace Strings” which does exactly that. You can extend this command by replacing `sed s/bla/blubb/g` with the name of your shell script. Just make sure that your shell script works with input from standard input (`STDIN`).

> Thanks!
> Zvi

Kind regards,
  René

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Zvi?s Bundle.tmbundle.zip
Type: application/zip
Size: 2585 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20150327/2af5ec7e/attachment.zip>


More information about the textmate mailing list