Friday, July 06, 2007

Script to open file in TeXniscope from command line

UPDATE 2: A much fancier version of this script is now available. It has options that make it easier to make TeXniscope update its file and position (via PDFSync or DVI source specials) in the background. The options are described briefly with the -h parameter.

UPDATE 1: A more mature version of this script is now available. It has a usage line. It checks for the existence of files. It tries to guess at a file name if the file does not exist. It's a little more convenient for the command-line user.

Here's a script to open a (PDF or PostScript) file in TeXniscope from the command line:
#!/bin/sh

[ "`echo $*|cut -c 1`" == "/" ] || filename_prefix="`pwd`"

exec osascript \
-e "tell application \"TeXniscope\"" \
-e "activate" \
-e "open file ((POSIX file \"$filename_prefix/$*\") as string)" \
-e "refresh of the front document" \
-e "end tell";
or, alternatively,
#!/bin/bash

arguments="$*"
[ "${arguments:0:1}" == "/" ] || filename_prefix="$PWD"

exec osascript \
-e "tell application \"TeXniscope\"" \
-e "activate" \
-e "open file ((POSIX file \"$filename_prefix/$*\") as string)" \
-e "refresh of the front document" \
-e "end tell";

Create an executable script called texniscope (e.g., /usr/local/bin/texniscope that is chmod'd 755) and try texniscope FILENAME where FILENAME is the name of the PDF or PostScript file that you want to open (be sure to include the file extension).

This allows you to use TeXniscope as a LaTeX document viewer in the VIM-LaTeX suite for Vim.

See also: Script to open file in Skim from command line

I use this for Vim/GVim; however, this script was inspired by code in an example in the TeXniscope help file for making TeXniscope work with iTeXMac. See the TeXniscope documentation for information on how to build a script that will let iTeXMac call TeXniscope from the command-line (and even make use of PDFSync [CTAN, iTM]).

No comments: