3

I am using reftex and auctex with emacs 27.1 on Ubuntu 21.10 to write a large latex document that consists of many .tex files in a single directory. Between various weekly Ubuntu updates and editing my ~/.emacs file, something broke such that reftex commands no longer work, and I could greatly use some help to get things working smoothly again.

When I edit a single simple test .tex file, reftex works fine, e.g., Esc-x reftex-parse-all, C-c ), C-c (, C-c = work fine. But when I edit the main.tex file or other .tex files of my many-file document and run a reftex command like C-c = or C-c ), I get an error message like this

 Wrong type argument: stringp, 46

and so far I have not been able to figure out why the reftex commands are failing beyond that it seems to be related to my editing multiple files. I include my .emacs file below to show how I am trying to invoke auctex and latex.

Any help would be appreciated.

Thanks,

Henry

=================================================================

my ~/.emacs file, which I am byte-compiling to ~/.emacs.el:

;speed up this file by byte-compiling it: M-x byte-compile ~/.emacs

(setq inhibit-startup-message t)
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
(display-time)
(transient-mark-mode t) ; show temporary region between mark
(show-paren-mode t)     ; show matching parentheses

;(setq case-fold-search nil)  ; search now case sensitive
;(setq case-replace t)        ; replace now case sensitive

(setq-default shell-file-name "/bin/tcsh")

;; set default font and frame size
;; M-x describe-font to see current font

(when (member "Hack" (font-family-list))
  (set-frame-font "Hack-11" t t))

(if (display-graphic-p)
(progn
  (setq initial-frame-alist
    '(
      (tool-bar-lines . 0)
      (width . 97)
      (height . 52)
      (background-color . "white")
      (left . 20)
      (top . 10)))
  (setq default-frame-alist
    '(
      (tool-bar-lines . 0)
      (width . 97)
      (height . 52)
      (background-color . "white")
      (left . 20)
      (top . 10))))
  (progn
(setq initial-frame-alist '( (tool-bar-lines . 0)))
(setq default-frame-alist '( (tool-bar-lines . 0)))))

(setq-default major-mode 'text-mode)
(add-hook 'text-mode-hook 'turn-on-auto-fill)

(setq browse-url-browser-function 'browse-url-chromium)

(global-set-key (kbd "<delete>") `delete-char) ; make DEL delete forward
(define-key global-map "\^Xc" 'compile)
(define-key global-map "\el" 'goto-line)
(global-unset-key "\e\e")     ; ESC ESC undefined

; related to tex, auctex, and reftex
; Note: install auctex via "sudo apt install auctex", not part of emacs distribution
; C-c = reftex-toc
; C-c [ for reftex-citation
; C-c ) for reftex-reference

(load "auctex.el" nil t t)
(load "preview-latex.el" nil t t)

(setq TeX-parse-self t)  ; Enable parse on load.
(setq TeX-auto-save t)   ; Enable parse on save.

(add-hook 'LaTeX-mode-hook
      (lambda ()
    (require 'reftex)
))

(add-hook 'LaTeX-mode-hook 'turn-on-reftex)  ; turn on reftex for .tex files
(add-hook 'latex-mode-hook 'turn-on-reftex)

(setq reftex-plug-into-AUCTeX t)
(setq reftex-enable-partial-scans t)
(setq reftex-save-parse-info t)
(setq reftex-use-multiple-selection-buffers t)

(setq-default TeX-master nil)  ; query for master file when using auctex
(setq-default reftex-default-bibliography "~hsg/bib")
(setq-default reftex-bibpath-environment-variables ".:~hsg/bib/:")
(setq-default reftex-texpath-environment-variables ".:~hsg/tex/inputs/:")

;; Make sure auto-mode-alist is modifiable.
(setq auto-mode-alist (copy-alist auto-mode-alist))
(setq major-mode 'text-mode)
(setq auto-mode-alist (cons '("\\.tex$" . latex-mode) auto-mode-alist))

(setq completion-ignored-extensions '(".a" ".aux" ".bbl" ".blg" ".dvi" ".elc"
                  ".lof" ".log" ".lot" ".o" ".toc" 
                  ".rel" "~"))

(add-hook 'text-mode-hook
  '(lambda ()
     (turn-on-auto-fill)
     (setq fill-column 70)
;         (gin-mode 1)          ; smart indenting and filling
     ))

(add-hook 'LaTeX-mode-hook
      '(lambda ()
     (turn-on-auto-fill)
;             (gin-mode 1)      ; smart indenting and filling
     (setq fill-column 70)
     ))

;;; html mode should do auto-fill
(add-hook 'html-mode-hook
      (function 
       (lambda ()
     (turn-on-auto-fill))))

; (autoload 'matlab-mode "matlab" "Enter Matlab mode." t)
; (setq auto-mode-alist (cons '("\\.m\\'" . matlab-mode) auto-mode-alist))
; (autoload 'matlab-shell "matlab" "Interactive Matlab mode." t)

;(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
; '(canlock-password "545471838e5b5365df39713bc54b83fe3aea845c")
; '(current-language-environment "Latin-9")
; '(default-input-method "latin-9-prefix")
; '(display-time-mode t)
; '(load-home-init-file t t))

(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(highlight ((((class color) (background light)) (:background "lightgoldenrod2"))))
 '(region ((t (:background "lightsteelblue2")))))

%%%%%

Response to running M-x reftex-parse-all on my main.tex after executing "M-x toggle-debug-on-error:

  Debugger entered--Lisp error: (wrong-type-argument stringp 46)
string-match("^!" 46)
#f(compiled-function (x) #<bytecode 0x1586db96da9d>)(46)
mapconcat(#f(compiled-function (x) #<bytecode 0x1586db96da9d>) ".:~hsg/tex/inputs/:" ":")
reftex-access-search-path("tex" nil "/home/hsg/understanding-brains/" "preface")
reftex-locate-file("preface" "tex" "/home/hsg/understanding-brains/")
reftex-parse-from-file("preface" (("ch:preface" "s" "%\\input{preface} %\\setcounter{chapter}{0} \\chapter..." "/home/hsg/understanding-brains/main.tex" nil) (toc "toc" "  * Preface" "/home/hsg/understanding-brains/main.tex" #<marker at 2341 in main.tex> 1 "*" "\\chapter*{Preface}" 2341) (bof "/home/hsg/understanding-brains/main.tex")) "/home/hsg/understanding-brains/")
reftex-parse-from-file("/home/hsg/understanding-brains/main.tex" nil "/home/hsg/understanding-brains/")
reftex-do-parse(1 nil)
reftex-access-scan-info(nil)
reftex-reference()
funcall-interactively(reftex-reference)
call-interactively(reftex-reference nil nil)
command-execute(reftex-reference)
  • 1
    Run `M-x toggle-debug-on-error` to switch `debug-on-error` on. With this, you should get a backtrace when the error occurs. Either, this backtrace already gives you a clue about the error and you can fix it or you can paste the backtrace here if you need further assistance. – Tobias May 22 '22 at 21:56
  • Thanks for the reply. I followed your suggestion and include the backgrace above at the end of my original entry. The backtrace does not make sense to me, so far I don't see where an error occurs. – hsgreenside May 23 '22 at 01:37
  • I explored my problem further by greatly simplifying my main.tex file and slowly adding lines until something broke. The problem is definitely related to using a \input or \include statement: as soon as the first \input appears in my main.tex, reftex breaks (e.g., C-c ( generates a wrong-type-argument error). The strange thing is the error occurs even if I comment out the \input line, e.g. %\input{foo} for a nearly empty file foo.tex generates an error. I remain puzzled and don't know how to fix this. – hsgreenside May 23 '22 at 03:10

1 Answers1

1

The values of reftex-bibpath-environment-variables and reftex-texpath-environment-variables should not be strings but lists of strings.

Change the settings

(setq-default reftex-bibpath-environment-variables ".:~hsg/bib/:")
(setq-default reftex-texpath-environment-variables ".:~hsg/tex/inputs/:")

to

(setq-default reftex-bibpath-environment-variables '(".:~hsg/bib/:"))
(setq-default reftex-texpath-environment-variables '(".:~hsg/tex/inputs/:"))
Tobias
  • 32,569
  • 1
  • 34
  • 75
  • Thanks so much! This fixed the problem, and I would not have been able to solve this on my own, I still don't know enough of Lisp and emacs to understand fully when strings versus lists of strings are required. My problem and your answer suggests that emacs code like reftex, auctex, etc could be improved if something like assert statements were used to test the validity of all incoming arguments and then say clearly why some input parameter is bad, say a list of strings was required. The error trace I looked at was not helpful despite my being an experienced coder (although not in Lisp). – hsgreenside May 23 '22 at 15:09
  • The right way for a non-lisper to set these vars would be via M-x customize-option. That GUI-interface ensures syntactically right input. – Tobias May 23 '22 at 22:23
  • @hsgreenside Please mark this question as answered ASAP. Otherwise, it still appears in the list of unanswered questions. – Tobias May 24 '22 at 15:01
  • Thanks for the suggestion about M-x customize-option. – hsgreenside May 25 '22 at 04:06