Thus, all the commands need to be issued by Emacs and need to result in a pdf file. Again, I want as much of this to be automated as possible.
Thus, if I type "altpdflatex foo.tex" at a command line, latex is run first, then dvips is run on the dvi file, then ps2pdf is run on the PostScript file; the dvi and the PostScript files are removed. The "altpdflatex" script should run on any unix system (it is available at CTAN).
The .emacs file already contains the following line:
(list "pdfLaTeX" "pdflatex '\\nonstopmode\\input{%t}'" 'TeX-run-LaTeX nil t)This creates a line in the "Command" menu with an item called "pdfLaTeX". This menu item runs the command "pdflatex" on the main tex file, represented by %t.
Thus, I want to add two lines like the above. One which runs "altpdflatex" and one which opens the pdf file in TeXShop.
Here are the first lines I added in my .emacs file (within the command menu list):
(list "altpdf" "altpdflatex '\\nonstopmode\\input{%t}'" 'TeX-run-LaTeX nil t) (list "pdfview" "open -a TeXShop %s.pdf" 'TeX-run-LaTeX nil t)
Now, I want keyboard shortcuts which call the menu items "altpdf", "pdfview" and "pdfLaTeX". For some reason in auctex the way I figure out how to do this is to use an intermediate step of creating a function, which is then bound to a keyboard command. For the keyboard commands I used C-t (i.e. control-t) and M-t (i.e. meta-t, or Apple-t). This clobbers pre-existing emacs keyboard commands for "twiddle", i.e. for reversing two adjacent letters (for C-t) and for reversing two adjacent words (for M-t). I don't mind losing these commands; if you do then pick a different keyboard shortcut.
Here's what I added to create the keyboard shortcut M-t for "pdflatex" (these lines are not added to the command menu list, just add them to the file after the list somewhere):
(global-set-key "\M-t" 'do-pdflatex) (defun do-pdflatex () "pdflatex the current file." (interactive) (TeX-command "pdfLaTeX" 'TeX-master-file))
For "altpdflatex" I created a very similar entry:
(global-set-key "\C-t" 'do-altpdf) (defun do-altpdf () "altpdflatex the current file." (interactive) (TeX-command "altpdf" 'TeX-master-file))
Finally, I created a (better for me) keyboard shortcut for saving a file:
(global-set-key "\M-s" 'save-buffer)
Note that this keyboard shortcut only works (in my version of Emacs anyway) in major modes. Thus, for plain text files it does not work. The reasons why Emacs does this are beyond me; but things like this (so-called global settings not working in certain modes) are a feature of Emacs which I continue to find very frustrating.
You might wonder why I bothered to do this since Emacs has C-x C-s. Well, (1) I don't think something I do as often as save my tex file should require two keyboard commands and (2) I use the dvorak keyboard (actually a dvorak keyboard with further modifications to make tex-ing easier) and "x" and "s" are on different hands, so "C-x C-s" is not at all convenient for me to enter.