Subject: Re: bug#73302: TeX-find-closing-brace and verbatim macros

From: Paul Nelson <[email-masked]>
Date: Sat, 21 Sep 2024 10:47:18 +0200

> @Paul: How does you change work in a file like this:
>
> --8<---------------cut here---------------start------------->8---
> \documentclass{article}
>
> \usepackage{fvextra}
>
> \begin{document}
>
> Vanilla \verb|LaTeX|
>
> With \Verb|fvextra|, or \Verb[fontsize=\scriptsize]|fvextra|.
>
> With \Verb{fvextra}, or \Verb[fontsize=\scriptsize]{fvextra}.
>
> \end{document}
>
> %%% Local Variables:
> %%% mode: latex
> %%% TeX-master: t
> %%% End:
> --8<---------------cut here---------------end--------------->8---

One issue that shows up when attempting to fold these examples via a
string display spec is that (TeX-find-macro-end), called with point at
the beginning of \Verb|LaTeX|, returns the end of \Verb rather than
the complete macro.  As a result, using tex-fold with a string display
spec never folds the complete macro, but instead just the part
appearing before the first "|".  Perhaps this should be changed?  In
any event, it's an issue orthogonal to my patch.

Modulo this issue, I think everything in the example you provided
works as intended.  For example, with the spec ("[1]:{1}!||{1}@||[1]#"
("Verb"), the tex code

\Verb[fontsize=\scriptsize]{fvextra}
\Verb{fvextra}
\Verb[fontsize=\scriptsize]|fvextra|

folds to something that looks like

fontsize=\scriptsize:fvextra!
fvextra@
fontsize=\scriptsize#|fvextra|

which I think is the expected behavior, modulo the oddity that in the
third example, "|fvextra|" appears at the end, due to the behavior of
(TeX-find-macro-end) noted above.

Note that the string display specs in tex-fold don't support "|...|"
arguments.  I do provide folding support for "\verb|...|" in
https://github.com/ultronozm/czm-tex-fold.el, but it's done there
using a function display spec, ultimately using the regexp
"\\\\verb|\\([^|]*\\)|" rather than anything built-in.  I guess I
could extend it to work also with \Verb.

Alternatively, one could view the contents of "|...|" as a "required
argument" and extend the string display spec folding to work with
"|...|" in addition to "{...}", but I don't see the immediate payoff
from doing so.