Received: (at submit) by debbugs.gnu.org; 25 Nov 2025 20:21:21 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Nov 25 15:21:21 2025
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>
To: "auctex-bugs" <bug-auctex@HIDDEN>
Subject: Fontification of asterisk between arguments
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-Debbugs-Envelope-To: submit
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
Arash Esbati <arash@HIDDEN>:bug-auctex@HIDDEN.
Full text available.bug-auctex@HIDDEN:bug#79878; Package auctex.
Full text available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.