Subject: bug#49080: 28.0.50; latex-forward-sexp scan error (unbalanced parens) when parens are balanced

From: Ahmed Khaled <[email-masked]>
Date: Thu, 17 Jun 2021 22:12:14 +0200

In tex-mode, latex-forward-sexp does not correctly handle parentheses
like this \[ \]. In particular, it says the expression is not balanced
when it is.

Steps to reproduce the bug:
1. Start with emacs -Q (with -nw or without doesn't make a difference)
2. Open any .tex file (I attached test.tex which I used).
3. Navigate to any LaTeX equation delimited by \[ and \], like this:
\[ 1 + 1 = 2 \]
4. Put the cursor on the first [ in the line:
5. Call latex-forward-sexp

That's it. On test.tex, the error I get is:
       Scan error: "Unbalanced parentheses", 126, 157
Note that if the cursor is on the backslash, rather than [, then there
is no error.

In GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.24,
cairo version 1.16.0)
System Description: Ubuntu 20.04.2 LTS

Configured using:
 'configure
 CONFIG_SHELL=/gnu/store/pwcp239kjf7lnj5i4lkdzcfcxwcfyk72-bash-minimal-5.0.16/bin/bash
 SHELL=/gnu/store/pwcp239kjf7lnj5i4lkdzcfcxwcfyk72-bash-minimal-5.0.16/bin/bash
 --prefix=/gnu/store/xq1linh33h7icndhqwsxky0x6fmjqn11-emacs-pgtk-native-comp-28.0.50-194.1c0a7c3
 --enable-fast-install --with-native-compilation --with-pgtk
 --with-xwidgets --with-modules --with-cairo --disable-build-details'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LIBOTF LIBSELINUX LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY
PDUMPER PGTK PNG RSVG SECCOMP SOUND THREADS TIFF TOOLKIT_SCROLL_BARS XIM
XWIDGETS GTK3 ZLIB

Important settings:
  value of $EMACSLOADPATH:
/home/robo/.guix-profile/share/emacs/site-lisp:/home/robo/.guix-profile/share/emacs/site-lisp:/gnu/store/xq1linh33h7icndhqwsxky0x6fmjqn11-emacs-pgtk-native-comp-28.0.50-194.1c0a7c3/share/emacs/28.0.50/lisp
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: LaTeX

Minor modes in effect:
  shell-dirtrack-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
rfc822 mml mml-sec epa derived epg epg-config gnus-util rmail
rmail-loaddefs auth-source cl-seq eieio eieio-core eieio-loaddefs
password-cache json map time-date subr-x seq mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail
rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils vc-git
diff-mode easy-mmode vc-dispatcher tex-mode compile text-property-search
shell pcomplete comint ansi-color ring latexenc term/xterm xterm
byte-opt bytecomp byte-compile cconv cl-macs cl-loaddefs cl-lib pcase gv
jka-compr iso-transl tooltip eldoc electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel term/pgtk-win pgtk-win term/common-win tool-bar
dnd fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode elisp-mode lisp-mode prog-mode register page tab-bar menu-bar
rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock
font-lock syntax font-core term/tty-colors frame minibuffer cl-generic
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice button loaddefs faces cus-face macroexp files
window text-properties overlay sha1 md5 base64 format env code-pages
mule custom widget hashtable-print-readable backquote threads
xwidget-internal dbusbind inotify dynamic-setting system-font-setting
font-render-setting cairo move-toolbar gtk x-toolkit pgtk multi-tty
make-network-process native-compile emacs)

Memory information:
((conses 16 97956 9073)
 (symbols 48 8246 0)
 (strings 32 24556 2414)
 (string-bytes 1 872307)
 (vectors 16 13770)
 (vector-slots 8 274177 6530)
 (floats 8 37 69)
 (intervals 56 410 0)
 (buffers 992 12))