unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Having .emacs distinguish betweeen LaTeX and XeLaTeX
@ 2012-05-27 11:00 Haines Brown
  2012-05-27 11:16 ` Teemu Likonen
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Haines Brown @ 2012-05-27 11:00 UTC (permalink / raw)
  To: help-gnu-emacs


I would like to specify the TeX engine with the emacs command line, such
as with C-c C-c latex and C-c C-c xelatex, rather than having it only
call whichever TeX-engine is specified in AUCTeX configuration or in
.emacs init file. At present I can only switch between processing LaTeX
and XeLaTeX files by inserting or commenting a line in .emacs (setq
TeX-engine 'xetex) and reload emacs.

Simplest would be to have AUCTeX not specify any TeX-engine and instead
use the engine specified at the command prompt. There does not seem to
be any way to do this, and so an alternative might be for .emacs to
specify the TeX engine by distinguishing between LaTeX and XeLaTeX
files.

Someone using the Jed editor does this. He sets the default TeX-engine to
xetex if the document uses packages peculiar to XeTeX:

   if (re_fsearch("\\usepackage.*unicode-math") or
       re_fsearch("\\usepackage.*fontspec") or
       re_fsearch("\\usepackage.*polyglossia")
      )
      define_blocal_var("latex_output", "xetex");

Is it possible to something comparable to this if construction in .emacs
init? I know nothing of lisp, but guess it would be something like:

   ( if 
        (search-forward "\usepackage*fontspec") or
        (search-forward "\usepackage*polyglossia")
     (setq TeX-engine 'xetex))

Haines Brown


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Having .emacs distinguish betweeen LaTeX and XeLaTeX
  2012-05-27 11:00 Having .emacs distinguish betweeen LaTeX and XeLaTeX Haines Brown
@ 2012-05-27 11:16 ` Teemu Likonen
  2012-05-27 13:31   ` Haines Brown
  2012-05-27 17:06   ` Haines Brown
  2012-05-27 12:51 ` XeCycle
  2012-05-27 19:08 ` Ralf Angeli
  2 siblings, 2 replies; 6+ messages in thread
From: Teemu Likonen @ 2012-05-27 11:16 UTC (permalink / raw)
  To: Haines Brown; +Cc: help-gnu-emacs

* Haines Brown [2012-05-27 07:00:44 -0400] wrote:

> Is it possible to something comparable to this if construction in
> .emacs init? I know nothing of lisp, but guess it would be something
> like:
>
>    ( if 
>         (search-forward "\usepackage*fontspec") or
>         (search-forward "\usepackage*polyglossia")
>      (setq TeX-engine 'xetex))

If you know nothing of Lisp this may not help you but I'll paste my
settings anyway. It could be modified to match your needs.


    (add-hook 'LaTeX-mode-hook #'tl-latex-mode-hook)

    (defun tl-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\\>.*}")))
                  (save-match-data
                    (if (re-search-forward re 3000 t)
                        "XeLaTeX"
                      "LaTeX"))))))
      (auto-fill-mode 1)
      (outline-minor-mode 1)
      (abbrev-mode 1)
      (setq fill-column 72))



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Having .emacs distinguish betweeen LaTeX and XeLaTeX
  2012-05-27 11:00 Having .emacs distinguish betweeen LaTeX and XeLaTeX Haines Brown
  2012-05-27 11:16 ` Teemu Likonen
@ 2012-05-27 12:51 ` XeCycle
  2012-05-27 19:08 ` Ralf Angeli
  2 siblings, 0 replies; 6+ messages in thread
From: XeCycle @ 2012-05-27 12:51 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 777 bytes --]

Haines Brown <haines@histomat.net> writes:

> I would like to specify the TeX engine with the emacs command line, such
> as with C-c C-c latex and C-c C-c xelatex, rather than having it only
> call whichever TeX-engine is specified in AUCTeX configuration or in
> .emacs init file. At present I can only switch between processing LaTeX
> and XeLaTeX files by inserting or commenting a line in .emacs (setq
> TeX-engine 'xetex) and reload emacs.

You can do it by creating a custom command, by adding entries to
TeX-command-list.  Then you can change the command to call when
using C-c C-c.

-- 
Carl Lei (XeCycle)
Department of Physics, Shanghai Jiao Tong University
OpenPGP public key: 7795E591
Fingerprint: 1FB6 7F1F D45D F681 C845 27F7 8D71 8EC4 7795 E591

[-- Attachment #2: Type: application/pgp-signature, Size: 489 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Having .emacs distinguish betweeen LaTeX and XeLaTeX
  2012-05-27 11:16 ` Teemu Likonen
@ 2012-05-27 13:31   ` Haines Brown
  2012-05-27 17:06   ` Haines Brown
  1 sibling, 0 replies; 6+ messages in thread
From: Haines Brown @ 2012-05-27 13:31 UTC (permalink / raw)
  To: Teemu Likonen; +Cc: help-gnu-emacs

On Sun, May 27, 2012 at 02:16:46PM +0300, Teemu Likonen wrote:
> * Haines Brown [2012-05-27 07:00:44 -0400] wrote:
> 
> > Is it possible to something comparable to this if construction in
> > .emacs init? I know nothing of lisp, but guess it would be something
> > like:
> >
> >    ( if 
> >         (search-forward "\usepackage*fontspec") or
> >         (search-forward "\usepackage*polyglossia")
> >      (setq TeX-engine 'xetex))
> 
> If you know nothing of Lisp this may not help you but I'll paste my
> settings anyway. It could be modified to match your needs.
> 
> 
>     (add-hook 'LaTeX-mode-hook #'tl-latex-mode-hook)
> 
>     (defun tl-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\\>.*}")))
>                   (save-match-data
>                     (if (re-search-forward re 3000 t)
>                         "XeLaTeX"
>                       "LaTeX"))))))
>       (auto-fill-mode 1)
>       (outline-minor-mode 1)
>       (abbrev-mode 1)
>       (setq fill-column 72))

If I understand, this presumes that initially latex is the default 
TeX-engine, but it adds the xelatex engine to the available commands 
if the expression is matched. This expression is way beyond my ken. 

Would it be possible instead to put a comment line just before the 
preamble of a document that contains either the word "latex" or 
"xelatex" (assuming those words do not appear elsewhere in the 
document) and base the forward search on it? Also, for my purposes it 
would probably be more convenient to make xelatex the default 
TeX-engine and if the word "latex" is found it would instead be used 
as the TeX-engine. I assume this would also avoid having to enlarge 
the TeX-command-list because I suppose latex would already be in it.

Haines 



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Having .emacs distinguish betweeen LaTeX and XeLaTeX
  2012-05-27 11:16 ` Teemu Likonen
  2012-05-27 13:31   ` Haines Brown
@ 2012-05-27 17:06   ` Haines Brown
  1 sibling, 0 replies; 6+ messages in thread
From: Haines Brown @ 2012-05-27 17:06 UTC (permalink / raw)
  To: Teemu Likonen; +Cc: help-gnu-emacs

On Sun, May 27, 2012 at 02:16:46PM +0300, Teemu Likonen wrote:
> * Haines Brown [2012-05-27 07:00:44 -0400] wrote:
 
> If you know nothing of Lisp this may not help you but I'll paste my
> settings anyway. It could be modified to match your needs.

Thank you for the lisp suggestion. Subsequently I stumbled on a very 
simple answer to my question of running either the latex or xelatex 
commands without reconfiguring and restarting emacs: simply add 
xelated to the AUCTeX configuration for TeX-engine. I added xelatex 
and it can now be called for xelatex files and the latex command is 
still accessible for latex files. At least this seems to work so far.

Haines 



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Having .emacs distinguish betweeen LaTeX and XeLaTeX
  2012-05-27 11:00 Having .emacs distinguish betweeen LaTeX and XeLaTeX Haines Brown
  2012-05-27 11:16 ` Teemu Likonen
  2012-05-27 12:51 ` XeCycle
@ 2012-05-27 19:08 ` Ralf Angeli
  2 siblings, 0 replies; 6+ messages in thread
From: Ralf Angeli @ 2012-05-27 19:08 UTC (permalink / raw)
  To: help-gnu-emacs

* Haines Brown (2012-05-27) writes:

> I would like to specify the TeX engine with the emacs command line, such
> as with C-c C-c latex and C-c C-c xelatex, rather than having it only
> call whichever TeX-engine is specified in AUCTeX configuration or in
> .emacs init file. At present I can only switch between processing LaTeX
> and XeLaTeX files by inserting or commenting a line in .emacs (setq
> TeX-engine 'xetex) and reload emacs.
> 
> Simplest would be to have AUCTeX not specify any TeX-engine and instead
> use the engine specified at the command prompt. There does not seem to
> be any way to do this, and so an alternative might be for .emacs to
> specify the TeX engine by distinguishing between LaTeX and XeLaTeX
> files.

You can set the engine as a file variable in the files which require
XeTeX.

For example like this:

%%% Local Variables: 
%%% mode: latex
%%% TeX-engine: xetex
%%% TeX-PDF-mode: t
%%% TeX-master: t
%%% End: 

> Someone using the Jed editor does this. He sets the default TeX-engine to
> xetex if the document uses packages peculiar to XeTeX:
>
>    if (re_fsearch("\\usepackage.*unicode-math") or
>        re_fsearch("\\usepackage.*fontspec") or
>        re_fsearch("\\usepackage.*polyglossia")
>       )
>       define_blocal_var("latex_output", "xetex");
>
> Is it possible to something comparable to this if construction in .emacs
> init? I know nothing of lisp, but guess it would be something like:
>
>    ( if 
>         (search-forward "\usepackage*fontspec") or
>         (search-forward "\usepackage*polyglossia")
>      (setq TeX-engine 'xetex))

AUCTeX uses style files for things like this.  For example for
fontspec.sty you'd write a file called fontspec.el which is placed in
AUCTeX's style directory and which switches the TeX engine to XeTeX.
See (info "(auctex)Style Files") for details.

-- 
Ralf


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-05-27 19:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-27 11:00 Having .emacs distinguish betweeen LaTeX and XeLaTeX Haines Brown
2012-05-27 11:16 ` Teemu Likonen
2012-05-27 13:31   ` Haines Brown
2012-05-27 17:06   ` Haines Brown
2012-05-27 12:51 ` XeCycle
2012-05-27 19:08 ` Ralf Angeli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).