org-lint: Add new linter for ambiguous literal $

* lisp/org-lint.el (org-lint-LaTeX-$-ambiguous): New linter that
matches "$.12" and similar that match right LaTeX fragment boundary,
but are likely indented for literal use.

Reported-by: Paul Rubin <paulr@hackyon.net>
Link: https://orgmode.org/list/49c5dcf6-26fa-5fe1-1778-c932d056eadb@hackyon.net
This commit is contained in:
Ihor Radchenko 2023-07-01 13:01:40 +03:00
parent cf2349d14b
commit dc70878fc0
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 20 additions and 0 deletions

View File

@ -1350,6 +1350,22 @@ AST is the buffer parse tree."
(and (string-match-p "^[$][^$]" (org-element-property :value fragment))
(list (org-element-property :begin fragment)
"Potentially confusing LaTeX fragment format. Prefer using more reliable \\(...\\)")))))
(defun org-lint-LaTeX-$-ambiguous (_)
"Report LaTeX fragment-like text.
AST is the buffer parse tree."
(org-with-wide-buffer
(let ((ambiguous-latex-re (rx "$." digit))
report context)
(while (re-search-forward ambiguous-latex-re nil t)
(setq context (org-element-context))
(when (or (eq 'latex-fragment (org-element-type context))
(memq 'latex-fragment (org-element-restriction context)))
(push
(list
(point)
"$ symbol potentially matching LaTeX fragment boundary. Consider using \\dollar entity.")
report)))
report)))
(defun org-lint-timestamp-syntax (ast)
"Report malformed timestamps.
AST is the buffer parse tree."
@ -1614,6 +1630,10 @@ AST is the buffer parse tree."
"Report potentially confusing $...$ LaTeX markup."
#'org-lint-LaTeX-$
:categories '(markup))
(org-lint-add-checker 'LaTeX-$
"Report $ that might be treated as LaTeX fragment boundary."
#'org-lint-LaTeX-$-ambiguous
:categories '(markup) :trust 'low)
(org-lint-add-checker 'timestamp-syntax
"Report malformed timestamps."
#'org-lint-timestamp-syntax