GNU bug report logs - #78586
TeX-make-inline

Previous Next

Package: auctex;

Reported by: "Paul D. Nelson" <ultrono <at> gmail.com>

Date: Sun, 25 May 2025 14:03:02 UTC

Severity: normal

Done: "Paul D. Nelson" <ultrono <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: "Paul D. Nelson" <ultrono <at> gmail.com>
Subject: bug#78586: closed (Re: bug#78586: TeX-make-inline)
Date: Mon, 09 Jun 2025 19:03:02 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#78586: TeX-make-inline

which was filed against the auctex package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 78586 <at> debbugs.gnu.org.

-- 
78586: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=78586
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: "Paul D. Nelson" <ultrono <at> gmail.com>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: arash <at> gnu.org, 78586-done <at> debbugs.gnu.org
Subject: Re: bug#78586: TeX-make-inline
Date: Mon, 09 Jun 2025 21:01:59 +0200
Thanks Ikumi, I pushed the change and hope this message closes it!

Paul

[Message part 3 (message/rfc822, inline)]
From: "Paul D. Nelson" <ultrono <at> gmail.com>
To: bug-auctex <at> gnu.org
Subject: TeX-make-inline
Date: Sun, 25 May 2025 16:01:50 +0200
Hi Arash and all,

We had discussed in an earlier thread (bug#78006) the possibility of
adding some of my editing commands to AUCTeX (as standalone commands,
without default binds).  We could start with this one, discussed a bit
in that thread:

--8<---------------cut here---------------start------------->8---
(defcustom TeX-make-inline-delims '("$" . "$")
  "Delimiters for `TeX-make-inline' to surround inline LaTeX math."
  :type '(radio (const :tag "Dollar ($...$)" ("$" . "$"))
                (const :tag "Paren (\\(...\\))" ("\\(" . "\\)"))
                (cons :tag "Custom delimiters"
                      (string :tag "Left") (string :tag "Right"))))

(defun TeX-make-inline ()
  "Convert LaTeX display math environment at point to inline math.
Removes the enclosing math environment (such as \\[...\\] or
\\begin{equation}...\\end{equation}).  Replaces it with inline math
surrounded by `TeX-make-inline-delims', fitting the result onto one
line.  Leaves any trailing punctuation outside the math delimiters."
  (interactive)
  (when (texmathp)
    (when (fboundp 'preview-clearout-at-point)
      (preview-clearout-at-point))
    (save-excursion
      (let* ((env (car texmathp-why))
             (pos (cdr texmathp-why))
             (delims TeX-make-inline-delims))
        (cond
         ((member env '("\\(" "$")))
         ((member env '("\\[" "$$"))
          (goto-char pos)
          (delete-char 2)
          (let ((start (point))
                (end-delim (if (equal env "\\[") "\\]" "$$")))
            (search-forward end-delim)
            (delete-char -2)
            (TeX-make-inline--finalize-region start (point) delims)))
         (t
          (goto-char pos)
          (kill-line)
          (let ((start (point)))
            (search-forward (concat "\\end{" env "}"))
            (beginning-of-line)
            (kill-line)
            (TeX-make-inline--finalize-region start (point) delims))))))))

(defun TeX-make-inline--finalize-region (start end delims)
  "Finalize the inline conversion from START to END using DELIMS."
  (save-restriction
    (narrow-to-region start end)
    (whitespace-cleanup)

    (goto-char (point-min))
    (let ((re
           (concat "\\(?:"
                   (mapconcat #'identity
                              (if (boundp 'reftex-label-regexps)
                                  reftex-label-regexps
                                '("\\\\label{[^}]*"))
                              "\\|")
                   "\\)")))
      (while (re-search-forward re nil t)
        (replace-match "")))

    (goto-char (point-min))
    (while (looking-at "\\s-*$")
      (delete-line))
    (beginning-of-line-text)
    (delete-region (point-min) (point))

    (goto-char (point-max))
    (while (and (> (point) (point-min))
                (progn (forward-line -1)
                       (looking-at "\\s-*$")))
      (delete-line))
    (end-of-line)
    (skip-chars-backward " \t")
    (delete-region (point) (point-max))

    (goto-char (point-min))
    (insert (car delims))
    (goto-char (point-max))
    (insert "\n")
    (backward-char)

    (while (looking-back "[.,;:!?]" 5)
      (backward-char))
    (insert (cdr delims))

    (while (> (count-lines (point-min) (point-max)) 1)
      (join-line))))
--8<---------------cut here---------------end--------------->8---

I haven't prepared this as a patch because I'm not sure where to put it
or where to document it.  I looked around, and couldn't find a natural
place.  If no better idea comes to mind, then perhaps some new
"miscellaneous commands" section of latex.el, with a corresponding
section in the manual?  For what it's worth, there are a couple of other
editing-related commands I'd be inclined to propose.

Any feedback welcome.

Thanks, best,

Paul



This bug report was last modified 40 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.