I am using Gnu Emacs 22 GTK with AucTeX under Ubuntu. I am not a
programmer but I have built up a nice .emacs file with help from all
the kind folks. When I load a (La)TeX file, I can get all the nice
menus related to LaTeX such as Preview, LaTeX, Command, Math, Ref etc.
Under he Command menu, I see a set of options called TeXing Options
which has things like PDF Mode, Run Interactively, and others.
I would like to include in one of these menus (preferably under the
Command menu) the option to run xetex/xelatex also so that I can use
Emacs to compile XeLaTeX files. So far, I am having to go to the
Terminal to issue
xelatex
command while I edit these files in Emacs. This seems rather awkward
(if not an outright insult to Emacs!).
I would appreciate some advice and help.
Regards,
Tariq
> I would like to include in one of these menus (preferably under the
> Command menu) the option to run xetex/xelatex also so that I can use
> Emacs to compile XeLaTeX files.
You could do it with hook:
(add-hook 'LaTeX-mode-hook #'my-latex-mode-hook)
(defun my-latex-mode-hook ()
(add-to-list 'TeX-command-list
'("XeLaTeX" "%`xelatex%(mode)%' %t" TeX-run-TeX nil t)))
The following is a fancier version of the hook. It sets XeLaTeX the
default compiler when it finds fontspec or mathspec package being loaded
with \usepackage{}.
(defun my-latex-mode-hook ()
(add-to-list 'TeX-command-list
'("XeLaTeX" "%`xelatex%(mode)%' %t" TeX-run-TeX nil t))
(setq TeX-command-default
(save-excursion
(save-restriction
(widen)
(goto-char (point-min))
(let ((re (concat "^\\s-*\\\\usepackage\\(?:\\[.*\\]\\)?"
"{.*\\<\\(?:font\\|math\\)spec\\>.*}")))
(if (re-search-forward re 3000 t)
"XeLaTeX"
"LaTeX"))))))
Thank you so much for the code for two hooks. Consider this my naivity
but I cannot tell the difference (if any) in the behaviour of Emacs
when using the first or the second (fancier) hook. Specifically, I see
the appearance of XeLaTeX under the Command menu after opening a .tex
file and this is the case with either code. Similarly, when I select
(in TeXing Options) PDF Mode, I still need to press XeLaTeX in Command
menu.
I got the impression from your description that with the fancier code,
the LaTeX option would execute XeLaTeX if the file has
\usepackage{fontspec} in it. this does not appear to be the case. Most
likely, I am confused about something. What specifically is the
difference in the expected behaviour of these two codes? I would
appreciate if you could elaborate. Regards,
Tariq
Perhaps I am being too demanding here (but considering this is Emacs
we are talking about, it should come as no surprise): it possible to
have a little icon or something show up (along with other icons below
the main menu) indicating XeLaTeX and one could just click with mouse
to run xelatex? I see LaTeX (or pdf) icons among others that do this
for pdflatex or latex.
Best regards,
Tariq
> Thank you so much for the code for two hooks. Consider this my naivity
> but I cannot tell the difference (if any) in the behaviour of Emacs
> when using the first or the second (fancier) hook. Specifically, I see
> the appearance of XeLaTeX under the Command menu after opening a .tex
> file and this is the case with either code. Similarly, when I select
> (in TeXing Options) PDF Mode, I still need to press XeLaTeX in Command
> menu.
The "fancy" version sets the default compiler command for the document
when you load a tex file or switch to latex-mode. I think you'll notice
the difference when you use C-c C-c to compile a document. With the
"fancy" version it's either XeLaTeX or LaTeX, depending on whether there
is \usepackage{fontspec} (or mathspec) within the first 3000 characters
of the document.
Or that's how it works in my system. I don't know Auctex very deeply and
its different versions may behave differently.
Hi Teemu
Thanks for the tip. You're right, I noticed the Ctrl-c Ctrl-c
behaviour exactly as you described.
I'll stick with the fancy version because I can just use the keyboard
for faster compilation.
Best,
Tariq
> Perhaps I am being too demanding here (but considering this is Emacs
> we are talking about, it should come as no surprise): it possible to
> have a little icon or something show up (along with other icons below
> the main menu) indicating XeLaTeX and one could just click with mouse
> to run xelatex? I see LaTeX (or pdf) icons among others that do this
> for pdflatex or latex.
How about upgrading AUCTeX and making use of `TeX-engine'?
--
Ralf
I installed Emacs 22 and AucTeX from the Ubuntu 9.10 repositories only
two days ago. That is the latest version they have. Since I have never
done these installations manually, I am not sure how to go about it
such that my existing system would not break.
If you can give some hints as to how to proceed, I would definitely
like to upgrade AucTeX and would certainly appreciate.
Regards,
Tariq