TeXShop Engine to use Acrobat as previewer

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

TeXShop Engine to use Acrobat as previewer

Ramón Figueroa-Centeno
Aloha,

Just to see if it could be done, I wrote a TeXShop engine that uses Acrobat as a previewer.

(It has a neat trick, that might be useful, i.e., how to close a TeXShop preview window at the end of the execution of an engine).

Save it in, say, "~/Library/TeXShop/Engines/Acrobat-Preview.engine" and make it executable.

To us it place the line "% !TEX TS-program = Acrobat-Preview" (no quotes, of course) at the beginning of your LaTeX file (first 20 lines). Then Typeset.

It will typeset, show the result in Acrobat (closing any previous preview) and then close in the background the preview that TeXShop created.

Now, obviously it does not do SyncTeX, but it does remember the page.

I only tested it with Acrobat Pro (version 9.0.0). If you want to test it with Acrobat Reader you have to change the line

tell application "Adobe Acrobat Pro"

to reflect that.

Enjoy!

Ramón

--------------------------code starts below this line-------------------------------
#!/bin/bash

PATH="$PATH:/usr/texbin:/usr/local/bin"

name=$(basename "$1" .tex)
basefname="`pwd`/${name}"

# Change this line to whatever typesetting command you like that produces PDFs.
pdflatex --file-line-error --shell-escape --synctex=1 "$1"
# comment the line above and uncomment the one below if you wish to use an
# installed TeXShop engine. Here we use pdflatexmk as an example.
~/Library/TeXShop/Engines/pdflatexmk.engine "$1"

# Close any preview taht already exists (if any) and ope the new one.
/usr/bin/osascript  <<END
tell application "Adobe Acrobat Pro"
        activate
        set pg to 1
        try
                set pg to page number of the PDF Window of the document "$name.pdf"
                close document "$name.pdf"
        end try
        open POSIX file "$basefname.pdf"
        try
                goto PDF Window of the document "$name.pdf" page pg
        end try
end tell
END

# We close the pdf window in TeXShop
close_window="tell application \"TeXShop\" to close (every window whose name contains \"$name.pdf\")"

nohup /usr/bin/osascript  -e "$close_window" &

Reply | Threaded
Open this post in threaded view
|

Re: TeXShop Engine to use Acrobat as previewer

Ramón Figueroa-Centeno
Oops!

In my previous post I made a little mistake.

The line

~/Library/TeXShop/Engines/pdflatexmk.engine "$1"

should be

#~/Library/TeXShop/Engines/pdflatexmk.engine "$1"

That is it should be commented.

Sorry,

Ramón
Reply | Threaded
Open this post in threaded view
|

Re: TeXShop Engine to use Acrobat as previewer

Victor Ivrii
In reply to this post by Ramón Figueroa-Centeno
2010/5/22 Ramón Figueroa-Centeno <[hidden email]>:
>
> Aloha,
>
> Just to see if it could be done, I wrote a TeXShop engine that uses Acrobat
> as a previewer.
>

Thanks! It could be useful for doing things where only AR or AA do
proper jobs (like inserting movies, 3D, animations or Javascript.

D.P.Story did much more than this - to use AA as postprocessor - but I
am not aware of any successful attempts to make it work on Mac (Unix
out of luck due to lack of AA)

Victor



========================
Victor Ivrii, Professor, Department of Mathematics, University of Toronto
http://www.math.toronto.edu/ivrii
----------- Please Consult the Following Before Posting -----------
TeX FAQ: http://www.tex.ac.uk/faq
List Reminders and Etiquette: http://email.esm.psu.edu/mac-tex/
List Archive: http://tug.org/pipermail/macostex-archives/
TeX on Mac OS X Website: http://mactex-wiki.tug.org/
List Info: http://email.esm.psu.edu/mailman/listinfo/macosx-tex

Reply | Threaded
Open this post in threaded view
|

Re: TeXShop Engine to use Acrobat as previewer

Ramón Figueroa-Centeno
In reply to this post by Ramón Figueroa-Centeno
Aloha Again,

I added some functionality to the engine I posted yesterday: assuming that you have, like me, chosen in the preferences to have "[a]ll windows start at fixed position" then the modifications to the engine will place the preview in Acrobat where the preview would be in TeXShop.

----------------------------------code begins below this line--------------------------------------------
#!/bin/bash

PATH="$PATH:/usr/texbin:/usr/local/bin"

name=$(basename "$1" .tex)
basefname="`pwd`/${name}"

# Change this line to whatever typesetting command you like that produces PDFs.
# pdflatex --file-line-error --shell-escape --synctex=1 "$1"
# comment the line above and uncomment the one below if you wish to use an
# installed TeXShop engine. Here we use pdflatexmk as an example.
~/Library/TeXShop/Engines/pdflatexmk.engine "$1"

# Get TeXShop's PDF window position
window=`defaults read TeXShop "NSWindow Frame PdfKitWindow"`
# replace every space run by a single space
window=`echo $window | sed 's/ +/ /g'`

x=`echo "$window" | cut -d ' ' -f 1`
y=`echo "$window" | cut -d ' ' -f 2`
w=`echo "$window" | cut -d ' ' -f 3`
h=`echo "$window" | cut -d ' ' -f 4`

# Close any preview that already exists (if any) and open the new one.
/usr/bin/osascript  <<END
tell application "Adobe Acrobat Pro"
        activate
        set pg to 1
        try
                set pg to page number of the PDF Window of the document "$name.pdf"
                set b to bounds of the PDF Window of the document "$name.pdf"
                close document "$name.pdf"
        on error
                set b to {$x, 0, $x + $w, $y + $h}
        end try
        open POSIX file "$basefname.pdf"
        try
                set bounds of (the PDF Window of the document "$name.pdf") to b
                goto PDF Window of the document "$name.pdf" page pg
        end try
end tell
END

# We close the pdf window in TeXShop
close_window="tell application \"TeXShop\" to close (every window whose name is \"$name.pdf\")"

/usr/bin/nohup /usr/bin/osascript  -e "$close_window" &

Reply | Threaded
Open this post in threaded view
|

Re: TeXShop Engine to use Acrobat as previewer

Ramón Figueroa-Centeno
Aloha,

Alas the engine I posted only works fully for Adobe Acrobat Pro and not Adobe Reader, since although they have the same applescript dictionary Acrobat Reader does not have many of the commands implemented.

Not all is lost as one can implement most of the functionality using System Events, but the preview will always open on page 1. Moreover, the Acrobat engine will set the preview position to the TeXShop default on its first run, but once there is a preview open it will position subsequent previews in the place the user chooses (until she closes it). The Reader engine always opens the preview in the same place, as defined by TeXShop.

Finally, you must open System Preferences and check Enable Access for Assistive Devices in the Universal Access preference pane, for this engine to work.

Enjoy! (but not as much)

Ramón

---------------------------code starts after this line--------------------------
#!/bin/bash

PATH="$PATH:/usr/texbin:/usr/local/bin"

name=$(basename "$1" .tex)
basefname="`pwd`/${name}"

# Change this line to whatever typesetting command you like that produces PDFs.
# pdflatex --file-line-error --shell-escape --synctex=1 "$1"
# comment the line above and uncomment the one below if you wish to use an
# installed TeXShop engine. Here we use pdflatexmk as an example.
~/Library/TeXShop/Engines/pdflatexmk.engine "$1"

# Get TeXShop's PDF window position
window=`defaults read TeXShop "NSWindow Frame PdfKitWindow"`
# replace every space run by a single space
window=`echo $window | sed 's/ +/ /g'`

x=`echo "$window" | cut -d ' ' -f 1`
y=`echo "$window" | cut -d ' ' -f 2`
width=`echo "$window" | cut -d ' ' -f 3`
height=`echo "$window" | cut -d ' ' -f 4`

# Close any preview that already exists (if any) and open the new one.
/usr/bin/osascript  <<END
activate application "Adobe Reader"
tell application "System Events"
        tell process "Adobe Reader"
                try
                        click button 1 of window "$name.pdf"
                end try
        end tell
end tell

set x to $x
set y to $y - 115
set h to $height + 115
set w to $width

tell application "Adobe Reader"
        open POSIX file "$basefname.pdf"
end tell

tell application "System Events"
        tell process "Adobe Reader"
                set position of window "$name.pdf" to {x, y}
                set size of window "$name.pdf" to {w, h}
        end tell
end tell

END

# We close the pdf window in TeXShop
close_window="tell application \"TeXShop\" to close (every window whose name is \"$name.pdf\")"

/usr/bin/nohup /usr/bin/osascript  -e "$close_window" &
Reply | Threaded
Open this post in threaded view
|

Re: TeXShop Engine to use Acrobat as previewer

Herbert Schulz

On May 22, 2010, at 8:39 PM, Ramón Figueroa-Centeno wrote:

>
> Aloha,
>
> Alas the engine I posted only works fully for Adobe Acrobat Pro and not
> Adobe Reader, since although they have the same applescript dictionary
> Acrobat Reader does not have many of the commands implemented.
>
> Not all is lost as one can implement most of the functionality using System
> Events, but the preview will always open on page 1. Moreover, the Acrobat
> engine will set the preview position to the TeXShop default on its first
> run, but once there is a preview open it will position subsequent previews
> in the place the user chooses (until she closes it). The Reader engine
> always opens the preview in the same place, as defined by TeXShop.
>
> Finally, you must open System Preferences and check Enable Access for
> Assistive Devices in the Universal Access preference pane, for this engine
> to work.
>
> Enjoy! (but not as much)
>
> Ramón
>
> ---------------------------code starts after this
> line--------------------------
> #!/bin/bash
>
> PATH="$PATH:/usr/texbin:/usr/local/bin"
>
> name=$(basename "$1" .tex)
> basefname="`pwd`/${name}"
>
> # Change this line to whatever typesetting command you like that produces
> PDFs.
> # pdflatex --file-line-error --shell-escape --synctex=1 "$1"
> # comment the line above and uncomment the one below if you wish to use an
> # installed TeXShop engine. Here we use pdflatexmk as an example.
> ~/Library/TeXShop/Engines/pdflatexmk.engine "$1"
>
> # Get TeXShop's PDF window position
> window=`defaults read TeXShop "NSWindow Frame PdfKitWindow"`
> # replace every space run by a single space
> window=`echo $window | sed 's/ +/ /g'`
>
> x=`echo "$window" | cut -d ' ' -f 1`
> y=`echo "$window" | cut -d ' ' -f 2`
> width=`echo "$window" | cut -d ' ' -f 3`
> height=`echo "$window" | cut -d ' ' -f 4`
>
> # Close any preview that already exists (if any) and open the new one.
> /usr/bin/osascript  <<END
> activate application "Adobe Reader"
> tell application "System Events"
> tell process "Adobe Reader"
> try
> click button 1 of window "$name.pdf"
> end try
> end tell
> end tell
>
> set x to $x
> set y to $y - 115
> set h to $height + 115
> set w to $width
>
> tell application "Adobe Reader"
> open POSIX file "$basefname.pdf"
> end tell
>
> tell application "System Events"
> tell process "Adobe Reader"
> set position of window "$name.pdf" to {x, y}
> set size of window "$name.pdf" to {w, h}
> end tell
> end tell
>
> END
>
> # We close the pdf window in TeXShop
> close_window="tell application \"TeXShop\" to close (every window whose name
> is \"$name.pdf\")"
>
> /usr/bin/nohup /usr/bin/osascript  -e "$close_window" &
>

Howdy,

Been off the net for a short while so couldn't add that this is a much nicer way of dealing with things than using a Macro. Using the pdflatexmk engine would definitely be the way to go (assuming you would be using pdflatex for compilation) but folks should make sure that those engines, found in ~/Library/TeXShop/Engines/Inactive/Latexmk/ are activated already.

Good Luck,

Herb Schulz
(herbs at wideopenwest dot com)



----------- Please Consult the Following Before Posting -----------
TeX FAQ: http://www.tex.ac.uk/faq
List Reminders and Etiquette: http://email.esm.psu.edu/mac-tex/
List Archive: http://tug.org/pipermail/macostex-archives/
TeX on Mac OS X Website: http://mactex-wiki.tug.org/
List Info: http://email.esm.psu.edu/mailman/listinfo/macosx-tex