auctex-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Improving fontification support for biblatex qualified citation lists


From: Gustavo Barros
Subject: Improving fontification support for biblatex qualified citation lists
Date: Thu, 20 Apr 2023 07:53:10 -0300

Hi All,

AUCTeX does provide fontification support for biblatex's qualified
citation lists, like `\cites' and friends, but a somewhat limited one,
in that only the first two bibkeys and their corresponding prenotes
and postnotes.  However, biblatex's citation lists can receive an
arbitrary number of "[pre][post]{key}" groups, and those exceeding the
second one are not fontified.

Some years ago, Arash said in a TeX.SX answer this is a "won't fix",
since "Fontification is done by font-latex.el shipped with AUCTeX
which in general can only fontify fixed number of arguments."
(https://tex.stackexchange.com/a/426066).

That is true not only of the `font-latex.el' syntax for specifying the
argument, but also of the underlying font-lock machinery for which a
given number or subexpression matches must be specified beforehand.

However, the situation could be improved by relaxing this limit a
little to support more than two "[pre][post]{key}" groups.
Technically, if we just add more groups with `font-latex-add-keywords'
(or in `font-latex-built-in-keyword-classes') the fontification of the
argument works.  However, if the actual command happens to be shorter
than that particular number of arguments, it is flagged as a
`syntax-error', and the command's backslash receives a warning face.
Of course, it is missing expected "mandatory" arguments.  With that,
it is easy to understand why two groups are currently supported: if
there was only one, there would be no need for the citation list, and
any number larger than two would result in possible syntactic errors
being flagged.

The problem here is that the bibkeys of biblatex's citation lists are
not really mandatory, and yet they are given in braces.  But we could
extend the syntax of `font-latex.el' to accommodate this case.  We
could use, for example, a closing brace to indicate an optional
argument in braces.  With that, in
`font-latex-match-command-with-arguments' which handles the
fontification of such commands, we could have (around were the
`alternative' is dealt with):

#+begin_src emacs-lisp
(when (eq spec ?})
  (setq opt-braces t)
  (setq spec ?{))
#+end_src

And then, when the syntax-error is handled for the mandatory argument case:

#+begin_src emacs-lisp
(unless (or alternative opt-braces)
  (setq syntax-error t)
  (when (and match-beg (= match-beg (point)))
    (setq error-indicator-pos match-beg))
  (throw 'break nil))
#+end_src

Let bind `opt-braces' and reset it as is done for `alternative' and,
as far as I can tell, that's all there'd be to it for
`font-latex-match-command-with-arguments' to support the case.

Finally, the only possibly remaining thing is that
`font-latex-keyword-matcher' places an upper bound of 12 matching
subgroups, and these citation lists can become quite long.  So,
extending this limit a little would be welcome for this purpose.

True, still a fixed number of arguments, but better.

Best regards,
Gustavo.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]