--- Begin Message ---
Subject: |
Verbatim environments with key-value arguments |
Date: |
Wed, 28 Apr 2021 11:11:07 +0200 |
Hi,
I am writing styles for the minted and listings libraries of tcolorbox,
which introduce the tcblisting verbatim environment. Here is a small
example showing things:
\documentclass[preview,svgnames,x11names]{standalone}
\RequirePackage[newfloat]{minted}
\RequirePackage{tcolorbox}
\tcbuselibrary{most,minted}
\begin{document}
\begin{tcblisting}{%
listing only,%
title={Example shell session},
minted language=shell-session,%
minted options={},%
}
$ echo 'Hello, World!'
Hello, World!
\end{tcblisting}
\end{document}
% Local Variables:
% mode: latex
% TeX-command-extra-options: "-shell-escape"
% TeX-master: t
% End:
As you can see, tcblisting takes key-value arguments. This breaks the
"mandatory arguments to verbatim environments" part of
`font-latex-syntactic-keywords', which is defined as:
;; After the optional argument, there may also be
;; another mandatory argument(s) (e.g. with VerbatimOut or
;; the minted envs or defined with `lstnewenvironment').
"\\(?:{[^}]*}\\)*"
Since the key-value arguments _can_ contain braces (e.g., title={Example
shell session}), the regex does not match properly and messes up the
fontification.
Feel free to add "tcblisting" to `LaTeX-verbtaim-environments' and check
out the example above: You will see that everything after title={Example
shell session} is fontified as verbatim.
I would be happy to try and improve the regex so that it handles
key-value arguments, but I first wanted to ask if this is indeed and the
best approach.
Best regards,
--
Dario Gjorgjevski <dario.gjorgjevski@gmail.com>
Key fingerprint = F7C3 734D 2381 DAEB 4C6D 9CF7 744A 4F0B 4F1C 9371
$ gpg --keyserver hkps://hkps.pool.sks-keyservers.net \
--search-keys 744A4F0B4F1C9371
--- End Message ---
--- Begin Message ---
Subject: |
Re: bug#48078: Verbatim environments with key-value arguments |
Date: |
Wed, 28 Apr 2021 20:41:16 +0200 |
User-agent: |
mu4e 1.5.12; emacs 28.0.50 |
Dario Gjorgjevski <dario.gjorgjevski@gmail.com> writes:
Hi Dario,
> \begin{tcblisting}{%
> listing only,%
> title={Example shell session},
> minted language=shell-session,%
> minted options={},%
> }
> $ echo 'Hello, World!'
> Hello, World!
> \end{tcblisting}
>
> Feel free to add "tcblisting" to `LaTeX-verbtaim-environments' and
> check out the example above: You will see that everything after
> title={Example shell session} is fontified as verbatim.
>
> I would be happy to try and improve the regex so that it handles
> key-value arguments,
To handle all situations correctly is impossible. You can't properly
match nested constructs like balanced parens/braces using regular
expressions. For that, you'd need an actual parser.
But you can at least allow a fixed number of balanced braces, and I've
just done that in order to allow one level of nested {...} in mandatory
arguments. (We already allowed for one level of nested brackets in an
optional argument.)
I'll make a new ELPA release.
Thanks for the report and Bye,
Tassilo
--- End Message ---