Loading ...
Sorry, an error occurred while loading the content.
 

latexmk from macvim

Expand Messages
  • rabee
    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
    Message 1 of 3 , Jun 1, 2008
      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
      -~----------~----~----~----~------~----~------~--~---
    • Andrew Stewart
      ... 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,
      Message 2 of 3 , Jun 2, 2008
        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
        -~----------~----~----~----~------~----~------~--~---
      • Guy Gur-Ari
        ... 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
        Message 3 of 3 , May 20, 2010
          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
        Your message has been successfully submitted and would be delivered to recipients shortly.