Dear Org Mode developers,

I am writing to report a bug in the LaTeX export pipeline in Org Mode 9.7.11 as 
packaged with the Snap version of Emacs 31.0.50. The issue appears to stem from 
a recent change in `org-latex-compile` which results in the following error 
when exporting to PDF:

Debugger entered--Lisp error: (wrong-type-argument sequencep t)
latexenc-find-file-coding-system((insert-file-contents
"/path/to/file.tex" nil nil nil nil))


This appears to result from a malformed call to 
`latexenc-find-file-coding-system`, where the return value of 
`(insert-file-contents ...)` — likely `t` or a cons cell — is passed instead of 
a string (filename) or buffer.

This issue began recently and was not present in previous versions of Org or 
Emacs. My Emacs and Org versions are:

- Emacs: 31.0.50 (installed via Snap)
- Org: 9.7.11 (release_9.7.11 @ 
/snap/emacs/current/usr/share/emacs/31.0.50/lisp/org/)

The error is triggered consistently on any call to `org-latex-export-to-pdf`.

### Temporary Workaround

I have temporarily resolved the issue by overriding `org-latex-compile` in my 
init file to avoid the faulty encoding detection step. This workaround bypasses 
the use of `latexenc-find-file-coding-system` entirely:

```emacs-lisp
(defun org-latex-compile (texfile &optional snippet)
  "Custom LaTeX compile function that avoids latexenc bug in Org 9.7.11."
  (unless (and texfile (stringp texfile))
    (error "Invalid texfile: %S" texfile))
  (let* ((texfile (expand-file-name texfile))
         (output-dir (file-name-directory texfile))
         (pdf-file (concat (file-name-sans-extension texfile) ".pdf"))
         (command (format "pdflatex -interaction nonstopmode -output-directory 
%s %s"
                          (shell-quote-argument output-dir)
                          (shell-quote-argument texfile))))
    (with-current-buffer (get-buffer-create "*Org PDF LaTeX Output*")
      (erase-buffer)
      (shell-command command (current-buffer)))
    (if (file-exists-p pdf-file)
        pdf-file
      (error "PDF file was not produced"))))

I would be grateful if this could be confirmed and fixed in an upcoming release 
of Org 9.7.x.

Please let me know if you require a minimal .org file or further details to 
reproduce the issue.

Kind regards,
Stephen Wheeler

Lancashire UK

Reply via email to