[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[AUCTeX-devel] font-latex.el: Better support for verbatim macros
From: |
Arash Esbati |
Subject: |
[AUCTeX-devel] font-latex.el: Better support for verbatim macros |
Date: |
Thu, 23 Mar 2017 12:12:56 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.2 |
Hi all,
the following file:
--8<---------------cut here---------------start------------->8---
\documentclass{article}
\usepackage{listings}
\usepackage[newfloat]{minted}
\begin{document}
\begin{minted}{lisp}
;; Eval the first 3 forms and note the difference
(add-to-list 'LaTeX-verbatim-macros-with-delims-local "mint")
(add-to-list 'LaTeX-verbatim-macros-with-delims-local "mintinline")
(font-latex-update-font-lock t)
;; Eval the rest
(font-latex-add-keywords '(("mint" "[{")) 'textual)
(font-latex-add-keywords '(("mintinline" "[{")) 'textual)
;; Eval these and note how it breaks fontification:
(add-to-list 'LaTeX-verbatim-macros-with-braces-local "mint")
(add-to-list 'LaTeX-verbatim-macros-with-braces-local "mintinline")
(font-latex-update-font-lock t)
\end{minted}
Standard LaTeX: \verb|$x=~/foo/|
Works:
\mint[linenos]{perl}|$x=~/foo/|
\mintinline[showspaces]{perl}|$x=~/foo/|
Does not work:
\mint[linenos]{perl}{$x=~/foo/}
\mintinline[showspaces]{perl}{$x=~/foo/}
\begin{lstlisting}[language=Lisp]
;; (font-latex-add-keywords '(("lstinline" "")) 'textual)
(font-latex-add-keywords '(("lstinline" "[")) 'textual)
\end{lstlisting}
\lstinline[style=test]!var i:integer;!
\lstinline{var i:integer;}
\lstinline[language=Perl]!x=~/foo/! % A comment
Some Text
\end{document}
--8<---------------cut here---------------end--------------->8---
looks like this for me:
x1.png
Description: PNG image
font-latex.el can not handle verbatim macros with optional and/or
mandatory arguments before the actual verbatim part. With this patch:
--8<---------------cut here---------------start------------->8---
diff --git a/font-latex.el b/font-latex.el
index a56d3ce1..14c93eff 100644
--- a/font-latex.el
+++ b/font-latex.el
@@ -1005,6 +1005,15 @@ have changed."
(unless (= (length verb-macros-with-delims) 0)
(add-to-list 'font-latex-syntactic-keywords
`(,(concat "\\\\\\(?:" verb-macros-with-delims "\\)"
+ ;; The macros \lstinline from
+ ;; listings.sty and \mint and \mintinline
+ ;; from minted.sty take an optional
+ ;; argument after macro name.
+ "\\(?:\\[[^][]*\\(?:\\[[^][]*\\][^][]*\\)*\\]\\)?"
+ ;; \mint and \mintinline from minted.sty
+ ;; take even a mandatory argument before
+ ;; starting with verbatim.
+ "\\(?:{[^}]*}\\)?"
;; An opening curly brace as delimiter
;; is valid, but allowing it might screw
;; up fontification of stuff like
@@ -1019,6 +1028,16 @@ have changed."
(unless (= (length verb-macros-with-braces) 0)
(add-to-list 'font-latex-syntactic-keywords
`(,(concat "\\\\\\(?:" verb-macros-with-braces "\\)"
+ ;; The macro \lstinline from
+ ;; listings.sty takes an optional
+ ;; argument after macro name.
+ "\\(?:\\[[^][]*\\(?:\\[[^][]*\\][^][]*\\)*\\]\\)?"
+ ;; FIXME: \mint and \mintinline from
+ ;; minted.sty take a mandatory argument
+ ;; here before verbatim text, but adding
+ ;; "\\(?:{[^}]*}\\)?" here breaks
+ ;; fontification for
+ ;; verb-macros-with-delims above!
"\\({\\).*?[^\\]\\(?:\\\\\\\\\\)*\\(}\\)")
(1 "|") (2 "|")))))
(when font-latex-syntactic-keywords-extra
--8<---------------cut here---------------end--------------->8---
the same file look like this (after eval'ing the forms):
x2.png
Description: PNG image
One issue which I could not solve was the FIXME mentioned above: For
verb-macros-with-braces, I couldn't find a way to support constructs
like `\mintinline[showspaces]{perl}{$x=~/foo/}' without breaking
\mintinline[showspaces]{perl}|$x=~/foo/|. Does anybody has a solution
for this? Or should I apply the patch above?
Any comments welcome.
Best, Arash
- [AUCTeX-devel] font-latex.el: Better support for verbatim macros,
Arash Esbati <=