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)