unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#68744: [PATCH] 30.0.50; calc vector parsing: spaces should not be separators except with [...]
@ 2024-01-26 21:38 Paul Nelson
  0 siblings, 0 replies; only message in thread
From: Paul Nelson @ 2024-01-26 21:38 UTC (permalink / raw)
  To: 68744

[-- Attachment #1: Type: text/plain, Size: 4651 bytes --]

There are two ways to input vectors (or matrices) in calc.

(A) Using brackets (e.g., [x,y,z]), in any language mode.

(B) Using language-specific constructions (e.g., \begin{pmatrix} x & y
& z \end{pmatrix} in latex mode).

I would like to report a bug with (B) and to propose a fix.

Steps to reproduce (all with emacs -Q): use "C-x * * d L" to start
calc and set the language mode to latex, then evaluate the lisp forms
below, e.g., in the *scratch* buffer.

Example 1: parsing gives the wrong answer.

(math-read-expr "\\begin{pmatrix} x y & z \\end{pmatrix}")
Result: (vec (var x var-x) (var y var-y) (var z var-z))
Expected result: (vec (* (var x var-x) (var y var-y)) (var z var-z))

Example 2: parsing gives an error on valid latex.

(math-read-expr "\\begin{pmatrix} x \\\\ y + 1 \\end{pmatrix}")
Result: (error 24 "Expected a number")
Expected result: (vec (vec (var x var-x)) (vec (+ (var y var-y) 1)))

These examples are not contrived.  They make it infeasible to use calc
as a latex parser for matrices.  Fortunately, they are easy to fix.

Both issues arise because calc allows spaces as separators with both
methods (A) and (B).  I believe that spaces should be allowed as
separators with method (A) (e.g., [x y z] as an alternative to
[x,y,z]), but never with method (B).

With the attached patch, calc allows spaces as separators in a vector
only when the vector was specified using "[".




In GNU Emacs 30.0.50 (build 1, aarch64-apple-darwin22.5.0, NS
 appkit-2299.60 Version 13.4.1 (Build 22F82)) of 2023-08-17 built on
 d51735
Repository revision: 5856ea5e4e897f4cb5cd1c3c28d14b335fe5cf54
Repository branch: master
Windowing system distributor 'Apple', version 10.3.2487
System Description:  macOS 14.2.1

Configured using:
 'configure --with-ns --with-native-compilation --with-tree-sitter
 --with-gif --with-png --with-jpeg --with-rsvg --with-tiff
 --with-imagemagick --with-x-toolkit=gtk3 --with-xwidgets'

Configured features:
ACL DBUS GLIB GNUTLS IMAGEMAGICK JSON LCMS2 LIBXML2 MODULES NATIVE_COMP
NOTIFY KQUEUE NS PDUMPER PNG RSVG SQLITE3 THREADS TOOLKIT_SCROLL_BARS
TREE_SITTER WEBP XIM XWIDGETS ZLIB

Important settings:
  value of $LC_CTYPE: UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-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
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny dired
dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068
epg-config gnus-util time-date mm-decode mm-bodies mm-encode mail-parse
rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mail-utils calc-vec calc-aent calc-math
calc-lang compile text-property-search comint ansi-osc ansi-color ring
comp comp-cstr warnings icons subr-x rx cl-seq cl-macs gv cl-extra
help-mode bytecomp byte-compile calc-ext calc-misc cl-loaddefs cl-lib
calc-menu calc calc-loaddefs rect calc-macs rmc iso-transl tooltip cconv
eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type
elisp-mode mwheel term/ns-win ns-win ucs-normalize mule-util
term/common-win touch-screen tool-bar dnd fontset image regexp-opt
fringe tabulated-list replace newcomment text-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 nadvice seq simple cl-generic indonesian philippine
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 emoji-zwj charscript
charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure
cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp
files window text-properties overlay sha1 md5 base64 format env
code-pages mule custom widget keymap hashtable-print-readable backquote
threads xwidget-internal dbusbind kqueue cocoa ns lcms2 multi-tty
make-network-process native-compile emacs)

Memory information:
((conses 16 129014 14615) (symbols 48 11069 0) (strings 32 29343 1471)
 (string-bytes 1 823136) (vectors 16 20069)
 (vector-slots 8 395724 11724) (floats 8 43 191) (intervals 56 259 0)
 (buffers 992 13))

[-- Attachment #2: 0001-fix-space-separator-bug-in-calc-parsing.patch --]
[-- Type: application/octet-stream, Size: 1180 bytes --]

From c66a012dacfba4700a1d39acdf7f2fd8304067d0 Mon Sep 17 00:00:00 2001
From: Paul Nelson <ultrono@gmail.com>
Date: Fri, 26 Jan 2024 22:12:00 +0100
Subject: [PATCH] fix space separator bug in calc parsing

---
 lisp/calc/calc-aent.el | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/lisp/calc/calc-aent.el b/lisp/calc/calc-aent.el
index 08e8d9fcd6f..de59eb974ad 100644
--- a/lisp/calc/calc-aent.el
+++ b/lisp/calc/calc-aent.el
@@ -1270,7 +1270,14 @@ math-read-factor
 	   (math-read-string))
 	  ((equal math-expr-data "[")
 	   (require 'calc-ext)
-	   (math-read-brackets t "]"))
+	   (let ((space-sep
+                  ;; Allow spaces as separators when the vector is
+                  ;; specified using "[", but not when it is specified
+                  ;; using language-specific constructions such as
+                  ;; "\\begin{pmatrix}".
+                  (equal "[" (substring math-exp-str math-exp-old-pos
+                                        math-exp-pos))))
+             (math-read-brackets space-sep "]")))
 	  ((equal math-expr-data "{")
 	   (require 'calc-ext)
 	   (math-read-brackets nil "}"))
-- 
2.39.3 (Apple Git-145)


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-26 21:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-26 21:38 bug#68744: [PATCH] 30.0.50; calc vector parsing: spaces should not be separators except with [...] Paul Nelson

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).