Subject: 14.0.8; TeX-engine=xetex causes "No matching viewer found" with TeX-command-run-all

From: Zhuohua Li <[email-masked]>
Date: Thu, 27 Feb 2025 17:48:50 +0800

Hello AUCTeX maintainers,

I've encountered an issue when using `TeX-engine = xetex` in AUCTeX.
Specifically, invoking `TeX-command-run-all` fails to launch a PDF
viewer with the error:

#+begin_example
error in process sentinel: TeX-view-command-raw: No matching viewer found
#+end_example

After some investigation, I noticed that this problem seems to have
been introduced by commit `4a345e2`. In that commit, `latexmk` is
invoked with the option `-pdfxe` when TeX-engine is xetex:

#+begin_src elisp
(cond ((eq TeX-engine 'xetex)
       " -pdfxe")
 ...
#+end_src

When `latexmk` runs with `-pdfxe`, it creates an `.xdv` file before
producing the PDF, and it appears AUCTeX ends up attempting to open
the `.xdv` file rather than the final PDF. This leads to the
viewer-launch failure and the "No matching viewer found" error
message.

** Steps to Reproduce

1. Create a tex file with the following minimal example.
   #+begin_src latex
   \documentclass{article}
   \begin{document}
   test
   \end{document}

   %%% Local Variables:
   %%% coding: utf-8
   %%% mode: latex
   %%% TeX-master: t
   %%% TeX-engine: xetex
   %%% End:
   #+end_src
2. Make a small edit to the file to ensure that `latexmk` will trigger
a rebuild. Then run `TeX-command-run-all`.
3. Observe that AUCTeX fails to launch a PDF viewer.

** Proposed Fix

Instead of passing `-pdfxe` to `latexmk`, I replaced it with:

#+begin_src elisp
(cond ((eq TeX-engine 'xetex)
       " -pdf -pdflatex=xelatex")
 ...
#+end_src

This change instructs `latexmk` to produce a PDF directly using
`xelatex`, and in my tests, it resolves the viewer launch issue.

I do not know whether my fix is appropriate, but I hope it helps.

Emacs  : GNU Emacs 29.4 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.42, cairo version 1.18.2)
 of 2025-02-26
Package: 14.0.8

current state:
==============
(setq
 window-system 'pgtk
 LaTeX-version "2e"
 TeX-style-path '("/home/li/.config/emacs/.local/cache/auctex/"

"/home/li/.config/emacs/.local/straight/build-29.4/auctex/style"
                  "/home/li/.config/emacs/.local/cache/auctex/.auctex-auto"

"/home/li/.config/emacs/.local/cache/auctex/.auctex-style"
".auctex-auto" ".auctex-style")
 TeX-auto-save t
 TeX-parse-self t
 TeX-master t
 TeX-command-list '(("TeX" "%(PDF)%(tex) %(file-line-error)
%`%(extraopts) %S%(PDFout)%(mode)%' %(output-dir) %t"
                     TeX-run-TeX nil (plain-TeX-mode AmSTeX-mode
Texinfo-mode) :help "Run plain TeX")
                    ("LaTeX" "%`%l%(mode)%' %T" TeX-run-TeX nil
(LaTeX-mode docTeX-mode) :help "Run LaTeX")
                    ("Makeinfo" "makeinfo %(extraopts) %(o-dir) %t"
TeX-run-compile nil (Texinfo-mode) :help
                     "Run Makeinfo with Info output")
                    ("Makeinfo HTML" "makeinfo %(extraopts) %(o-dir)
--html %t" TeX-run-compile nil
                     (Texinfo-mode) :help "Run Makeinfo with HTML output")
                    ("AmSTeX" "amstex %(PDFout) %`%(extraopts)
%S%(mode)%' %(output-dir) %t" TeX-run-TeX nil
                     (AmSTeX-mode) :help "Run AMSTeX")
                    ("ConTeXt" "%(cntxcom) --once %(extraopts)
%(execopts)%t" TeX-run-TeX nil (ConTeXt-mode)
                     :help "Run ConTeXt once")
                    ("ConTeXt Full" "%(cntxcom) %(extraopts)
%(execopts)%t" TeX-run-TeX nil (ConTeXt-mode) :help
                     "Run ConTeXt until completion")
                    ("BibTeX" "bibtex %(O?aux)" TeX-run-BibTeX nil
                     (plain-TeX-mode LaTeX-mode docTeX-mode
AmSTeX-mode Texinfo-mode ConTeXt-mode) :help
                     "Run BibTeX")
                    ("Biber" "biber %(output-dir) %s" TeX-run-Biber nil
                     (plain-TeX-mode LaTeX-mode docTeX-mode
AmSTeX-mode Texinfo-mode) :help "Run Biber")
                    ("Texindex" "texindex %s.??" TeX-run-command nil
(Texinfo-mode) :help "Run Texindex")
                    ("Texi2dvi" "%(PDF)texi2dvi %t" TeX-run-command
nil (Texinfo-mode) :help
                     "Run Texi2dvi or Texi2pdf")
                    ("View" "%V" TeX-run-discard-or-function t t :help
"Run Viewer")
                    ("Print" "%p" TeX-run-command t t :help "Print the file")
                    ("Queue" "%q" TeX-run-background nil t :help "View
the printer queue" :visible
                     TeX-queue-command)
                    ("File" "%(o?)dvips %d -o %f " TeX-run-dvips t
                     (plain-TeX-mode LaTeX-mode docTeX-mode
AmSTeX-mode Texinfo-mode) :help
                     "Generate PostScript file")
                    ("Dvips" "%(o?)dvips %d -o %f " TeX-run-dvips nil
                     (plain-TeX-mode LaTeX-mode docTeX-mode
AmSTeX-mode Texinfo-mode) :help
                     "Convert DVI file to PostScript")
                    ("Dvipdfmx" "dvipdfmx -o %(O?pdf) %d" TeX-run-dvipdfmx nil
                     (plain-TeX-mode LaTeX-mode docTeX-mode
AmSTeX-mode Texinfo-mode) :help
                     "Convert DVI file to PDF with dvipdfmx")
                    ("Ps2pdf" "ps2pdf %f %(O?pdf)" TeX-run-ps2pdf nil
                     (plain-TeX-mode LaTeX-mode docTeX-mode
AmSTeX-mode Texinfo-mode) :help
                     "Convert PostScript file to PDF")
                    ("LaTeXMk"
                     "latexmk %(latexmk-out) %(file-line-error)
%(output-dir) %`%(extraopts) %S%(mode)%' %t"
                     TeX-run-format nil (LaTeX-mode docTeX-mode) :help
"Run LaTeXMk")
                    ("Glossaries" "makeglossaries %(d-dir) %s"
TeX-run-command nil
                     (plain-TeX-mode LaTeX-mode docTeX-mode
AmSTeX-mode Texinfo-mode) :help
                     "Run makeglossaries to create glossary file")
                    ("Index" "makeindex %(O?idx)" TeX-run-index nil
                     (plain-TeX-mode LaTeX-mode docTeX-mode
AmSTeX-mode Texinfo-mode) :help
                     "Run makeindex to create index file")
                    ("upMendex" "upmendex %(O?idx)" TeX-run-index t
                     (plain-TeX-mode LaTeX-mode docTeX-mode
AmSTeX-mode Texinfo-mode) :help
                     "Run upmendex to create index file")
                    ("Xindy" "texindy %s" TeX-run-command nil
                     (plain-TeX-mode LaTeX-mode docTeX-mode
AmSTeX-mode Texinfo-mode) :help
                     "Run xindy to create index file")
                    ("Check" "chktex -v6 -H %s" TeX-run-compile nil
(LaTeX-mode) :help
                     "Check LaTeX file for correctness")
                    ("ChkTeX" "chktex -v6 %s" TeX-run-compile nil
(LaTeX-mode) :help
                     "Check LaTeX file for common mistakes")
                    ("Spell" "(TeX-ispell-document \"\")"
TeX-run-function nil t :help "Spell-check the document")
                    ("Clean" "TeX-clean" TeX-run-function nil t :help
"Delete generated intermediate files")
                    ("Clean All" "(TeX-clean t)" TeX-run-function nil t :help
                     "Delete generated intermediate and output files")
                    ("Other" "" TeX-run-command t t :help "Run an
arbitrary command"))
 )