[OS X TeX] Re: gnu fmt, or equivalent, for TeX?

Ramón Figueroa-Centeno ramonf at hawaii.edu
Thu Apr 1 21:36:12 CEST 2010


I tried using the one line command, via an applescript, to reformat LaTeX
from TeXShop with AUCTeX as follows:

--Applescript direct
-- Script to call Emacs AUCTeX to reformat LaTeX
-- Ramon Figueroa-Centeno (April 1, 2010)

property UNIXfilterPrefix : "emacs -batch -Q -eval '(load \"auctex.el\" nil
t t)' "
property UNIXfilterSuffix : " -eval '(progn (LaTeX-fill-buffer nil)
tell application "TeXShop"
	set the front_document to the front document
	set the_selection to the content of the selection of the front_document
	-- the Applescript command "do shell script" chokes if given a large amount
of data
	-- the workaround is to dump the data into a temporary file
	if the_selection is not "" then
		tell me
			set texpath to do shell script "mktemp /tmp/XXXXXXXX"
			do shell script "mv " & texpath & " " & texpath & ".tex"
			set texpath to texpath & ".tex"
			set TMP to POSIX file texpath
			open for access TMP with write permission
			write the_selection to TMP
			close access TMP
		end tell
		-- Convert the line endings to Unix ones, as is expected by most command
line programs
		-- (we use flip which is part of the standard TeXShop distribution)
		tell me to do shell script "~/Library/TeXShop/bin/flip -u " & texpath
		set command to UNIXfilterPrefix & texpath & UNIXfilterSuffix
		tell me
			do shell script command
			set filtered to do shell script "cat " & texpath
		end tell
		set the content of the selection of the front_document to filtered
		try -- to delete the temporary file
			tell me to do shell script "rm -f " & POSIX path of TMP
		end try
	end if
end tell

When I select the whole (minus some comments) document in the TeXShop front
window then it works. The only quirk I noticed is that it mangles things

% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = pdflatexmk

by making them one comment, but that is easily solved by not selecting those

However, when I select a portion AUCTeX chokes and I get errors like:

Applying style hooks...
Applying style hooks... done
Sorting environment...
Removing duplicates...
Removing duplicates... done
Applying style hooks...
Applying style hooks... done
Formatting buffer 6qkUnoC9.tex ... 0%
Formatting buffer 6qkUnoC9.tex ... 3%

Where "6qkUnoC9.tex" is the random name given to the file where we dumped
the selection.

By the way Emacs comes with OS X, but one needs to install AUCTeX for this
to work:

1. Download it from
2. Decompress it and go to the directory you created in the Terminal.
3. Configure it by typing: ./configure --without-texmf-dir --disable-preview
(this install a minimal version, which is all I need for because otherwise I
use AUCTeX from Aquamacs).
4. Compile: make
5. Install: sudo make install

Hopefully this is enough for one of you to be able to figure what is wrong.


View this message in context: http://n2.nabble.com/gnu-fmt-or-equivalent-for-TeX-tp4832589p4839203.html
Sent from the MacOSX-TeX mailing list archive at Nabble.com.

More information about the macostex-archives mailing list