X-Loop: help-debbugs@HIDDEN
Subject: bug#79878: Fontification of asterisk between arguments
Resent-From: Arash Esbati <arash@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-auctex@HIDDEN
Resent-Date: Tue, 25 Nov 2025 20:22:02 +0000
Resent-Message-ID: <handler.79878.B.17641020813427 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: report 79878
X-GNU-PR-Package: auctex
X-GNU-PR-Keywords:
To: 79878 <at> debbugs.gnu.org
X-Debbugs-Original-To: "auctex-bugs" <bug-auctex@HIDDEN>
Received: via spool by submit <at> debbugs.gnu.org id=B.17641020813427
(code B ref -1); Tue, 25 Nov 2025 20:22:02 +0000
Received: (at submit) by debbugs.gnu.org; 25 Nov 2025 20:21:21 +0000
Received: from localhost ([127.0.0.1]:41790 helo=debbugs.gnu.org)
by debbugs.gnu.org with esmtp (Exim 4.84_2)
(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
id 1vNzXN-0000t6-7F
for submit <at> debbugs.gnu.org; Tue, 25 Nov 2025 15:21:21 -0500
Received: from lists.gnu.org ([2001:470:142::17]:52752)
by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
(Exim 4.84_2) (envelope-from <arash@HIDDEN>) id 1vMq2Q-0006u9-Ta
for submit <at> debbugs.gnu.org; Sat, 22 Nov 2025 11:00:39 -0500
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 <arash@HIDDEN>) id 1vMq2G-0006n9-1f
for bug-auctex@HIDDEN; Sat, 22 Nov 2025 11:00:28 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
(Exim 4.90_1) (envelope-from <arash@HIDDEN>) id 1vMq2C-0001lt-PI
for bug-auctex@HIDDEN; Sat, 22 Nov 2025 11:00:24 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to:
references; bh=/KelIrIQuHPoE1VkfmwwGpx+n7WpWYBuF2gWdnBcEwM=; b=sAGQeNVT7HCRJw
dAIVoUKByv51JKM2p14iDZ4VbyIwB8BvloQVU7F98r39I10YH/oAlbB769Q3ZgTzzZpKin6tSSxn3
6MdSwvjQAs5GMl3T2Pt0yHz3HiiUgPQvSoD7jnFikqMPvw2CHMJ3PDyaR3SoqVPrGiiIemDm99qjW
ZFBen1qOgxynzkH0Rxtyq0/D/fjTHm0KNfMAlMr1QeKlvKYKW9Q1hxIdKCwS87ZgpfCoo4171dXBX
vGg3MpXaTyJTaKPVuR1BGOJf/oH2fC/ck+iCDZVrmK3H+UZ6GTdyOzzZdw+xPHro5zArfltg0Wjs9
YbPhAGi1Hfld9YbY7YPA==;
From: Arash Esbati <arash@HIDDEN>
Date: Sat, 22 Nov 2025 17:00:13 +0100
Message-ID: <m2y0nydpma.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: -0.0 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>,
<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>,
<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)
Hi all,
AUCTeX currently doesn't support fontification of macros when you have
an asterisk between the arguments. I admit, it is rare, but still,
there are some packages which have this kind of macros, e.g.,
paracol.sty with \switchcolumn which goes like:
\switchcolumn[col]*[text]
Now, take this small .tex file:
--8<---------------cut here---------------start------------->8---
\documentclass{article}
\usepackage{graphicx}
\begin{document}
Eval these forms,
\begin{verbatim}
(font-latex-add-keywords '(("TestMacro" "*[*{"))
'reference)
(font-latex-add-keywords '(("switchcolumn" "[*["))
'reference)
\end{verbatim}
%
and hit \verb|C-x x f| for \verb|M-x font-lock-update RET|. Emacs
will say \verb|Char not supported|.
\TestMacro*[optional]*{mandatory}
\TestMacro*[optional]{mandatory}
\switchcolumn[text]*[text]
\switchcolumn[text][text]
\includegraphics*[width=3cm,keepaspectratio]{somefig}
\end{document}
%%% Local Variables:
%%% mode: LaTeX
%%% TeX-master: t
%%% End:
--8<---------------cut here---------------end--------------->8---
We can teach font-latex.el TDRT with this small change:
--8<---------------cut here---------------start------------->8---
diff --git a/font-latex.el b/font-latex.el
index 3da68ba4..7873a4a5 100644
--- a/font-latex.el
+++ b/font-latex.el
@@ -1617,8 +1617,7 @@ Returns nil if none of KEYWORDS is found."
;; Check for starred macro if first spec is an asterisk or a
;; plus sign in case of \defaultfontfeatures+ provided by
;; fontspec.sty
- (when (or (eq (car spec-list) ?*)
- (eq (car spec-list) ?+))
+ (when (memql (car spec-list) '(?* ?+))
(setq spec-list (cdr spec-list))
(skip-chars-forward "*+" (1+ (point))))
;; Add current point to match data and use keyword face for
@@ -1669,6 +1668,21 @@ Returns nil if none of KEYWORDS is found."
(when (and match-beg (= match-beg (point)))
(setq error-indicator-pos match-beg))
(throw 'break nil))))
+ ;; Asterisk or plus sign between arguments (sigh!):
+ ((and (memql spec '(?* ?+))
+ (= (char-after) spec))
+ (setq match-beg (point))
+ (if (= (char-after) spec)
+ (progn
+ (nconc match-data
+ (list (point)
+ (progn
+ (skip-chars-forward "*+")
+ (point))))
+ (nconc font-latex-matched-faces
+ (list 'font-lock-keyword-face))
+ (setq end (max end (point))))
+ (throw 'break nil)))
;; Optional arguments: [...] and others
((eq (char-after) spec)
(setq match-beg (point))
--8<---------------cut here---------------end--------------->8---
If you don't want to apply the patch, this is the complete function:
--8<---------------cut here---------------start------------->8---
(defun font-latex-match-command-with-arguments (regexp keywords face limit)
"Search for regexp command KEYWORDS[opt]{arg} before LIMIT.
Returns nil if none of KEYWORDS is found."
(setq font-latex-matched-faces nil)
(catch 'match
(while (re-search-forward regexp limit t)
(unless (font-latex-faces-present-p '(font-lock-comment-face
font-latex-verbatim-face)
(match-beginning 0))
(let* ((beg (match-beginning 0))
end ; Used for multiline text property.
(match-data (list beg))
match-beg syntax-error alternative spec
error-indicator-pos
(spec-list (string-to-list
(or (cadr (assoc (match-string 1) keywords))
font-latex-command-with-args-default-spec)))
(parse-sexp-ignore-comments t)) ; scan-sexps ignores comments
(goto-char (match-end 0))
;; Check for starred macro if first spec is an asterisk or a
;; plus sign in case of \defaultfontfeatures+ provided by
;; fontspec.sty
(when (memql (car spec-list) '(?* ?+))
(setq spec-list (cdr spec-list))
(skip-chars-forward "*+" (1+ (point))))
;; Add current point to match data and use keyword face for
;; region from start to point.
(nconc match-data (list (point)))
(add-to-list 'font-latex-matched-faces 'font-lock-keyword-face)
(setq end (point))
(catch 'break
;; Walk the list of specs.
(while spec-list
(setq spec (pop spec-list)
error-indicator-pos beg)
(while (and (not (eobp)) (font-latex-forward-comment)))
;; Alternative
(when (eq spec ?|)
(setq alternative t)
(setq spec (pop spec-list)))
(cond
;; Macros: \foo
((eq spec ?\\)
(if (eq (char-after) spec)
(progn
(nconc match-data
(list (point)
(progn
(forward-char)
(if (zerop (skip-syntax-forward "_w"))
(forward-char) ; Single-char macro.
(skip-chars-forward "*+"))
(point))))
(nconc font-latex-matched-faces (list face))
(setq end (max end (point)))
(when alternative (pop spec-list)))
(setq syntax-error t)
(throw 'break nil)))
;; Mandatory arguments: {...}
((eq spec ?{)
(if (and (eq (char-after) spec)
(setq match-beg (point))
(font-latex-find-matching-close ?{ ?}))
(progn
(nconc match-data (list (1+ match-beg) (1- (point))))
(nconc font-latex-matched-faces (list face))
(setq end (max end (1- (point))))
(when alternative (pop spec-list)))
(unless alternative
(setq syntax-error t)
(when (and match-beg (= match-beg (point)))
(setq error-indicator-pos match-beg))
(throw 'break nil))))
;; Asterisk or plus sign between arguments (sigh!):
((and (memql spec '(?* ?+))
(= (char-after) spec))
(setq match-beg (point))
(if (= (char-after) spec)
(progn
(nconc match-data
(list (point)
(progn
(skip-chars-forward "*+")
(point))))
(nconc font-latex-matched-faces
(list 'font-lock-keyword-face))
(setq end (max end (point))))
(throw 'break nil)))
;; Optional arguments: [...] and others
((eq (char-after) spec)
(setq match-beg (point))
(if (font-latex-find-matching-close
spec (cdr (assq
spec
font-latex-command-with-args-opt-arg-delims)))
(progn
(nconc match-data (list (1+ match-beg) (1- (point))))
(nconc font-latex-matched-faces
(list 'font-lock-variable-name-face))
(setq end (max end (1- (point)))))
(setq syntax-error t
error-indicator-pos match-beg)
(throw 'break nil))))
(setq alternative nil)))
(when (and syntax-error (memq major-mode
font-latex-syntax-error-modes))
;; Add the warning face at the front of the list because
;; the matcher uses 'append and the face would otherwise
;; be overridden by the keyword face.
(setq match-data (append (list error-indicator-pos
(1+ error-indicator-pos))
match-data))
(push 'font-latex-warning-face font-latex-matched-faces))
(store-match-data match-data)
(throw 'match t))))))
--8<---------------cut here---------------end--------------->8---
This is part of font-latex.el is a mystery to me, so I'd appreciate any
comments.
Best, Arash
Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) Content-Type: text/plain; charset=utf-8 X-Loop: help-debbugs@HIDDEN From: help-debbugs@HIDDEN (GNU bug Tracking System) To: Arash Esbati <arash@HIDDEN> Subject: bug#79878: Acknowledgement (Fontification of asterisk between arguments) Message-ID: <handler.79878.B.17641020813427.ack <at> debbugs.gnu.org> References: <m2y0nydpma.fsf@HIDDEN> X-Gnu-PR-Message: ack 79878 X-Gnu-PR-Package: auctex Reply-To: 79878 <at> debbugs.gnu.org Date: Tue, 25 Nov 2025 20:22:02 +0000 Thank you for filing a new bug report with debbugs.gnu.org. This is an automatically generated reply to let you know your message has been received. Your message is being forwarded to the package maintainers and other interested parties for their attention; they will reply in due course. Your message has been sent to the package maintainer(s): bug-auctex@HIDDEN If you wish to submit further information on this problem, please send it to 79878 <at> debbugs.gnu.org. Please do not send mail to help-debbugs@HIDDEN unless you wish to report a problem with the Bug-tracking system. --=20 79878: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D79878 GNU Bug Tracking System Contact help-debbugs@HIDDEN with problems
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.