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>

Full log


Message #14 received at 78586 <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: "Paul D. Nelson" <ultrono <at> gmail.com>
Cc: 78586 <at> debbugs.gnu.org
Subject: Re: bug#78586: TeX-make-inline
Date: Thu, 29 May 2025 09:26:42 +0200
Hi Paul,

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

> Hi Arash, thanks for your feedback.

You're welcome.

> I put the updated draft at the end of this message (to be converted
> into a patch once one of us thinks of a good place to put it), and
> attach some tests.

You said that you also have some other commands, right?  So I suggest we
put them at the end of latex.el, under ;; Utilities:.  WDYT?

Reg. manual: I suggest to document this command under

@subheading Dollar Signs

Maybe something like this:

--8<---------------cut here---------------start------------->8---
diff --git a/doc/auctex.texi b/doc/auctex.texi
index 0b486c8c..9602c062 100644
--- a/doc/auctex.texi
+++ b/doc/auctex.texi
@@ -484,6 +484,16 @@ to prevent unmatched dollar.
 Note that Texinfo mode does nothing special for @kbd{$}.  It inserts
 dollar sign(s) just in the same way as the other normal keys do.

+@AUCTeX{} provides the command @code{LaTeX-make-inline} which converts the
+display math environment at point to inline math.
+
+@deffn Command LaTeX-make-inline
+Convert @LaTeX{} display math environment at point to inline math.  This
+command replaces the enclosing math environment such as @samp{\[...\]} or
+@samp{\begin@{equation@}...\end@{equation@}} with the value of
+@code{TeX-electric-math} or @samp{$...$} by default.
+@end deffn
+
 @subheading Braces

 To avoid unbalanced braces, it is useful to insert them pairwise.  You
--8<---------------cut here---------------end--------------->8---


> (defun LaTeX-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 surrounded by `TeX-electric-math' if non-nil, or \"$..$\",
> fitting the result onto one line.  Leaves any trailing punctuation
> outside the math delimiters."

Please use active voice, maybe something like this:

  "Convert LaTeX display math environment at point to inline math.
Remove the enclosing math environment (such as \\[...\\] or
\\begin{equation}...\\end{equation}) and replace it with inline math
surrounded by `TeX-electric-math' if non-nil, or \"$...$\",
fitting the result onto one line.  Finally, leave 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 (or TeX-electric-math '("$" . "$"))))

Why `let*'?

>         (cond
>          ((member env '("\\(" "$")))
>          ((member env '("\\[" "$$"))
>           (goto-char pos)
>           (when (looking-back "\n[[:space:]]*")
>             (forward-char 2)
>             (save-excursion (join-line))
>             (forward-char -2))
>           (delete-char 2)
>           (let ((start (point))
>                 (end-delim (if (equal env "\\[") "\\]" "$$")))
>             (search-forward end-delim)
>             (delete-char -2)
>             (if (looking-back "\n[[:space:]]*")
>                 (goto-char (match-beginning 0)))
>             (LaTeX--make-inline-finalize-region start (point) delims)))
>          (t
>           (goto-char pos)
>           (kill-whole-line)
>           (let ((start (point)))
>             (search-forward (concat "\\end{" env "}"))
>             (beginning-of-line)
>             (kill-whole-line)
>             (backward-char)
>             (LaTeX--make-inline-finalize-region start (point) delims))))))))
>
> (defun LaTeX--make-inline-finalize-region (start end delims)
>   "Finalize the inline conversion from START to END using DELIMS."
>   (save-restriction
>     (narrow-to-region start end)
>
>     (goto-char (point-min))
>     (let ((re
>            (concat "\\(?:"
>                    (mapconcat #'identity
>                               (if (boundp 'reftex-label-regexps)
>                                   reftex-label-regexps
>                                 '("\\\\label{[^}]*"))
>                               "\\|")
>                    "\\)")))

This looks somewhat easier to me:

(let ((re (concat "\\(?:"
                  (if (bound-and-true-p reftex-label-regexps)
                      (mapconcat #'identity reftex-label-regexps "\\|")
                    "\\\\label{[^}]*}")
                  "\\)")))

And note the missing '}' in "\\\\label{[^}]*".

Otherwise LGTM.

Best, Arash




This bug report was last modified 3 days ago.

Previous Next


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