latexmk from macvim

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

latexmk from macvim

rabee-2

Hi

I use macvim to write latex documents every day. (Thanks so much for
the best
gvim implementation I've ever used).

My setup is very simple. I fire up the document in macvim and
in terminal.app I cd to the relevant directory and run

latexmk.pl -pvc <filename.tex>

which  automates  the process of compiling the LaTeX document; skim is
opened, etc.

Essentially latexmk  runs the required programs every time I :w in
vim.

I looking for a simple vim script (recipe) which does the following

everytime a .tex file is opend in macvim a new terminal.app window is
opened and the commands
cd <directory of filename.tex>
latexmk.pl -pvc <filename.tex>

is run.

PS. I'm not so interested in the vim-latex suite or in ways of
implementing latexmk within vim
(using onchange etc)
I'm happy with the present setup of using an external program
(latexmk) to do the latex-thinking for me.


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_mac" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: latexmk from macvim

Andrew Stewart


On 2 Jun 2008, at 02:59, rabee wrote:
> I looking for a simple vim script (recipe) which does the following
>
> everytime a .tex file is opend in macvim a new terminal.app window is
> opened and the commands
> cd <directory of filename.tex>
> latexmk.pl -pvc <filename.tex>
>
> is run.


One quick tip that might also help: when you fire up MacVim, press '0  
to open the most recently used file, with the cursor where you left  
it.  Similarly, '1 through to '9 (numbered marks) open earlier files.

Anyway, the following will achieve what you want.  I hope somebody can  
post a neater way, but in the meantime this will get you up and running:

1.  In your "own" vim's filetype file (probably at ~/.vim/
filetype.vim), make it watch for tex files by adding this line:

   au BufRead *.tex setfiletype tex

2.  Save the following shell script as "term" somewhere in your path,  
and make it executable:

#!/bin/sh
#
# Open a new Mac OS X terminal window with the command given
# as argument.
#
# - If there are no arguments, the new terminal window will
#   be opened in the current directory, i.e. as if the command
#   would be "cd `pwd`".
# - If the first argument is a directory, the new terminal will
#   "cd" into that directory before executing the remaining
#   arguments as command.
# - If there are arguments and the first one is not a directory,
#   the new window will be opened in the current directory and
#   then the arguments will be executed as command.
# - The optional, leading "-x" flag will cause the new terminal
#   to be closed immediately after the executed command finishes.
#
# Written by Marc Liyanage <http://www.entropy.ch>
#
# Version 1.0
#

if [ "x-x" = x"$1" ]; then
     EXIT="; exit"; shift;
fi

if [[ -d "$1" ]]; then
     WD=`cd "$1"; pwd`; shift;
else
     WD="'`pwd`'";
fi

COMMAND="cd $WD; $@"
echo "$COMMAND $EXIT"

osascript 2>/dev/null <<EOF
     tell application "Terminal"
         activate
         do script with command "$COMMAND $EXIT"
     end tell
EOF

(Via http://www.entropy.ch/blog/Mac+OS+X/2005/02/28/Terminal_tricks_8220_term_8221_and_8220_clone_8221.html)

3.  Assuming you named the shell script "term", create this file to  
tell vim what to do when you read a tex file:

   In ~/.vim/ftplugin/tex.vim:

   silent !term %:p:h latexmk.pl -pvc %

And now every time you open a tex file in vim, a new Terminal will be  
opened in the file's directory, and the latexmk command will be run.

You could combine steps 1 and 3 by moving the "silent ..." onto the  
"au BufRead ..." line. I thought it was a little cleaner, and more  
flexible, to separate them.

Hope that helps.

Regards,
Andy Stewart

-------
AirBlade Software
http://airbladesoftware.com





--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_mac" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: latexmk from macvim

Guy Gur-Ari
In reply to this post by rabee-2
rabee <rabeetourky@...> writes:
>
> I looking for a simple vim script (recipe) which does the following
>
> everytime a .tex file is opend in macvim a new terminal.app window is
> opened and the commands
> cd <directory of filename.tex>
> latexmk.pl -pvc <filename.tex>
>
> is run.

I have a similar setup (I use my own script instead of latexmk).
I couldn't find an elegant way to do this, but the following works.

The first part is a Perl script that you can call 'launch_latexmk'.
It receives as a parameter the name of
the .tex file, does a few things, and eventually
launches a terminal window running latexmk -pvc
yourtexfile. Here it is:

#!/usr/bin/perl -w

use IO::File;
use strict;

my $texfile = $ARGV[0];

my $tmpfile = "/tmp/my_launch_latexmk";

my $dir = `pwd`;
chomp $dir;

my $f = IO::File->new("> $tmpfile");
$f->print("#!/bin/bash
# Automatically created by launch_latexmk
cd $dir
latexmk.pl -pvc $texfile
");
system("chmod +x $tmpfile");
system("open -a /Applications/Utilities/Terminal.app $tmpfile");


The second part is a vim binding to run this when
entering a new tex file is opened (assuming this
launch_latexmk is in your $path):

au BufRead *.tex silent !launch_latexmk %:p



--
You received this message from the "vim_mac" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: latexmk from macvim

ThornD
This post has NOT been accepted by the mailing list yet.
In reply to this post by Andrew Stewart
Hi,

I happened to come across this thread and find your code, which automatically starts Terminal and LaTeXmk. It was something I've been looking for. It is extremely useful for me, given my coding ability. But there is one thing I want to know.

I use the code to start Terminal/LaTeXmk manually rather than automatically (i.e. invoking "term" in gVim). But whenever I do, two terminal windows are opened: one is a starting Terminal and the other is for LaTeXmk. I do not use the first one. So, I wonder if you can tell me how to close the first starting Terminal automatically. In your message, you wrote

# - The optional, leading "-x" flag will cause the new terminal
#   to be closed immediately after the executed command finishes.

Is this something related to my question?

Your help is much appreciated.

ThornD

Given that Andy's message was sent more than two years ago, I quote his entire message below:

<quote author="Andrew Stewart-6">
On 2 Jun 2008, at 02:59, rabee wrote:
> I looking for a simple vim script (recipe) which does the following
>
> everytime a .tex file is opend in macvim a new terminal.app window is
> opened and the commands
> cd <directory of filename.tex>
> latexmk.pl -pvc <filename.tex>
>
> is run.


One quick tip that might also help: when you fire up MacVim, press '0  
to open the most recently used file, with the cursor where you left  
it.  Similarly, '1 through to '9 (numbered marks) open earlier files.

Anyway, the following will achieve what you want.  I hope somebody can  
post a neater way, but in the meantime this will get you up and running:

1.  In your "own" vim's filetype file (probably at ~/.vim/
filetype.vim), make it watch for tex files by adding this line:

   au BufRead *.tex setfiletype tex

2.  Save the following shell script as "term" somewhere in your path,  
and make it executable:

#!/bin/sh
#
# Open a new Mac OS X terminal window with the command given
# as argument.
#
# - If there are no arguments, the new terminal window will
#   be opened in the current directory, i.e. as if the command
#   would be "cd `pwd`".
# - If the first argument is a directory, the new terminal will
#   "cd" into that directory before executing the remaining
#   arguments as command.
# - If there are arguments and the first one is not a directory,
#   the new window will be opened in the current directory and
#   then the arguments will be executed as command.
# - The optional, leading "-x" flag will cause the new terminal
#   to be closed immediately after the executed command finishes.
#
# Written by Marc Liyanage <http://www.entropy.ch>
#
# Version 1.0
#

if [ "x-x" = x"$1" ]; then
     EXIT="; exit"; shift;
fi

if [[ -d "$1" ]]; then
     WD=`cd "$1"; pwd`; shift;
else
     WD="'`pwd`'";
fi

COMMAND="cd $WD; $@"
echo "$COMMAND $EXIT"

osascript 2>/dev/null <<EOF
     tell application "Terminal"
         activate
         do script with command "$COMMAND $EXIT"
     end tell
EOF

(Via http://www.entropy.ch/blog/Mac+OS+X/2005/02/28/Terminal_tricks_8220_term_8221_and_8220_clone_8221.html)

3.  Assuming you named the shell script "term", create this file to  
tell vim what to do when you read a tex file:

   In ~/.vim/ftplugin/tex.vim:

   silent !term %:p:h latexmk.pl -pvc %

And now every time you open a tex file in vim, a new Terminal will be  
opened in the file's directory, and the latexmk command will be run.

You could combine steps 1 and 3 by moving the "silent ..." onto the  
"au BufRead ..." line. I thought it was a little cleaner, and more  
flexible, to separate them.

Hope that helps.

Regards,
Andy Stewart

-------
AirBlade Software
http://airbladesoftware.com





--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_mac" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---
</quote>