From debbugs-submit-bounces@debbugs.gnu.org Tue Jun 10 02:48:15 2025 Received: (at submit) by debbugs.gnu.org; 10 Jun 2025 06:48:15 +0000 Received: from localhost ([127.0.0.1]:60213 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uOsmK-0000MT-Vc for submit@debbugs.gnu.org; Tue, 10 Jun 2025 02:48:15 -0400 Received: from lists.gnu.org ([2001:470:142::17]:53222) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uOsmG-0000KJ-Km for submit@debbugs.gnu.org; Tue, 10 Jun 2025 02:48:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uOsm5-0006Om-SL for bug-auctex@gnu.org; Tue, 10 Jun 2025 02:47:58 -0400 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uOsm1-0003W5-He for bug-auctex@gnu.org; Tue, 10 Jun 2025 02:47:57 -0400 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-5532a30ac45so4700509e87.0 for ; Mon, 09 Jun 2025 23:47:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749538071; x=1750142871; darn=gnu.org; h=mime-version:message-id:date:subject:to:from:from:to:cc:subject :date:message-id:reply-to; bh=hxVJBQRCJcXYr59ToFMcWQXd2GIiu9fneA93XXQlPMA=; b=luP0UjZecWNXlSY5qgN1HEe7Qaxiqw6fN/V0lNBNNzsEqzKvqe8k+YstmLTmR9FW4M b+Dz13utuAOdaGbbC0scIFpDzCJ4Jlh3oh0ZplIYs1wUs2Vq35828cVMHtJSxZRwN4+x rWD2RIxCRq/X60I+9hj5nyMjvQIfEAptmiR/6AcxDN/YNVlhGrCiPUIOKwNlcfRqQtAC /XF77jIRmpj+eDCkaW8P5/IisnEYkgDJQyRrsnlGL+bX2pAnMYbj3TnL/P/GfnTXjdEM HsFiUWmsozcn818lV86DyXVnb6Z32dDKGlaNnjur7mNRAysOZSl9mpn9fUCxgoE9nb2o D1DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749538071; x=1750142871; h=mime-version:message-id:date:subject:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=hxVJBQRCJcXYr59ToFMcWQXd2GIiu9fneA93XXQlPMA=; b=D/l6lP0hb1FWkr/Ag9rXcmi8/2V8OOGY8f1/kDL3hJSPqKXUdE/4rE5w9jCKzwEb4r PDCVRtr1eeIw2t7p15ZWXYURoZSYjlvoafAhdathJa6+4pUyPHOUwDgXwJzk3CZOUhM1 k6V5fc+xq9QLGpVewZePAl1H7h+9n4OBiem/UP4/ivuJ7XbTo1slaYrdVDKSFnRK5PQq /q6UkERH08UJtbA/DV4vsXToyfPCma1NdR4ZuKZPf/m3qovzyxcO+zNeRnbXP/SF0wny +KKB+6TfNldf/LwNVaZgCR3QbOebtKTN02NMIpmiG7TaVEqBWKXwzjxqqR8651zzbbLe c/hg== X-Gm-Message-State: AOJu0Yz7wVxJF5Ze6ib1cm8UPtO/Anc81UEsVDO1Sh2GcenuUM9e0gUF KV5qHE4svaCvq3R+xkwG+kp4UZjoAOjIt4z3pG+pmZcuNiv/aNpfilxRzJC1mhdF X-Gm-Gg: ASbGncuoRW0VPVxXpZxJTYushPeguWjSIwOTmId1ZnHSJwFcGogX2M1A8XiI13Iqp4S vQ+8K9ZBuWqRWKhG5V5EX+QJUPr+p2v9LiM0jO7fAPq4MyvZNUbXxZv0lV1nyXvIu2x+fmxA3A2 CU2Z2KXH8q6/ZmERYkb/Kk++yl6jikqm5QRVZ8x5VSAD161cOIXm61wFm/48Lpzjevbs5JjVJal gBrBuaWEXhMATvBQJeD3U3/3cEQRkHHnEYUgUeUJyxoGCQ7bWsI/Zmlzvh1CDCmZ0SmQ5NlpXKH nGmmiLErnHLtAWVHNegDjzqfAvoAmzC0jSdfjSHa8GVHQpy/homIy9opGtALLIzSVjg= X-Google-Smtp-Source: AGHT+IED0NZIdrrUik4KXm0ZCXz5u8wrJs4U69UeyXRPl37Afp4R2jWZJE25DSJ5sEu9ZrHqrK44Vg== X-Received: by 2002:a05:6512:108e:b0:553:2927:9864 with SMTP id 2adb3069b0e04-55393167341mr608005e87.6.1749538070876; Mon, 09 Jun 2025 23:47:50 -0700 (PDT) Received: from localhost ([185.229.155.48]) by smtp.gmail.com with UTF8SMTPSA id 2adb3069b0e04-55367731a7dsm1430084e87.230.2025.06.09.23.47.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jun 2025 23:47:49 -0700 (PDT) From: "Paul D. Nelson" To: bug-auctex@gnu.org Subject: [PATCH] LaTeX-repeat-recent-math Date: Tue, 10 Jun 2025 08:47:47 +0200 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2a00:1450:4864:20::136; envelope-from=ultrono@gmail.com; helo=mail-lf1-x136.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --=-=-= Content-Type: text/plain Hi again, I would like to propose a command that inserts a copy of the Nth most recent display math (N=1 by default, strips labels). I documented it at the end of the "Entering Mathematics" part of the manual. Any feedback or suggestions would be welcome. Paul --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-command-LaTeX-repeat-recent-math-environment.patch >From 04edbf84cb39b85803c39866384f6c94f84641ee Mon Sep 17 00:00:00 2001 From: Paul Nelson Date: Sat, 31 May 2025 20:45:57 +0200 Subject: [PATCH] Add command LaTeX-repeat-recent-math-environment * latex.el (LaTeX-repeat-recent-math): New command. * doc/auctex.texi (Mathematics): Document it. --- doc/auctex.texi | 29 +++++++++++++++++++++++++++ latex.el | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/doc/auctex.texi b/doc/auctex.texi index 5629a693..90a8cf21 100644 --- a/doc/auctex.texi +++ b/doc/auctex.texi @@ -1404,6 +1404,35 @@ e.g.@: by adding the following to your init file: @xref{Quotes,,LaTeX-make-inline}, for a built-in convenience wrapper that converts display constructs to inline math. +@subheading Repeating recent math + +@cindex LaTeX-repeat-recent-math +@cindex Math, repeating +@cindex Environments, repeating + +Sometimes you want the next equation to be a slight modification of a +previous one. The command @code{LaTeX-repeat-recent-math} looks backward +for a recent top-level display math construct and inserts a copy. + +@deffn Command LaTeX-repeat-recent-math @var{n} +Search backward for the @var{n}th most recent outer-level math construct +(@samp{\[...\]}, @samp{$$...$$}, or any math environment recognized by +@code{texmathp}, such as @code{equation}, @code{align*}, @dots{}). Copy +that construct to the current line, indent it, and strip any labels. + +With no prefix argument, @var{n} defaults to @code{1} (the most recent +construct). +@end deffn + +We can bind this command to a key, as follows: + +@lisp +(keymap-set LaTeX-mode-map "C-c r" #'LaTeX-repeat-recent-math) +@end lisp + +Then @kbd{C-c r} duplicates the last equation, @kbd{C-2 C-c r} duplicates +the second-to-last equation, and so on. + @node Completion @section Completion @cindex Completion diff --git a/latex.el b/latex.el index f4c206fa..5bff638b 100644 --- a/latex.el +++ b/latex.el @@ -9761,6 +9761,59 @@ trailing punctuation outside the math delimiters." (cons TeX-electric-math 'inline) "$"))) +(defun LaTeX-repeat-recent-math (&optional n) + "Insert a copy of the Nth most recent top-level math construct. +N should be a positive integer. The recognized constructs are +\"\\=\\[ ... \\]\", \"$$ ... $$\" and \"\\begin{ENV} ... \\end{ENV}\" +with ENV a math environment detected by `texmathp'. Any +\"\\label{...}\" macros inside the copied region are stripped." + (interactive "*p") + (setq n (or n 1)) + (unless (> n 0) (user-error "N must be positive")) + (let* ((env-re (concat (regexp-quote TeX-esc) "begin" + TeX-grop + "\\(" (regexp-opt (LaTeX--math-environment-list)) "\\)" + TeX-grcl)) + (search-re (concat env-re "\\|" + "\\(" (regexp-quote "$$") "\\|" + (regexp-quote (concat TeX-esc "[")) "\\)")) + beg end) + (save-excursion + (catch 'found + (while (re-search-backward search-re nil t) + (unless (nth 4 (syntax-ppss)) + (let ((open (match-string-no-properties 0))) + (when (save-excursion + (goto-char (match-end 0)) + (texmathp)) + (cl-decf n) + (when (zerop n) + (setq beg (point)) + (goto-char (match-end 0)) + (let ((end-re + (let ((type (if (string-match env-re open) + (match-string-no-properties 1 open) + open))) + (regexp-quote (LaTeX--closing type))))) + (re-search-forward end-re)) + (setq end (point)) + (throw 'found t)))))))) + (unless (and beg end) + (user-error "Nth most recent top-level math construct not found")) + (let ((contents (buffer-substring-no-properties beg end))) + (beginning-of-line) + (if (looking-at-p "[[:blank:]]*$") + (delete-region (point) (line-end-position)) + (end-of-line) + (delete-horizontal-space) + (insert "\n")) + (save-excursion (insert contents)) + (save-restriction + (narrow-to-region (point) (+ (point) (length contents))) + (indent-region (point-min) (point-max)) + (save-excursion (LaTeX--strip-labels)) + (forward-line))))) + (provide 'latex) ;;; latex.el ends here -- 2.39.3 (Apple Git-145) --=-=-=--