From 59b141e2b7d8d6483c518930d425cd2bb8a62374 Mon Sep 17 00:00:00 2001 From: Andras Simonyi Date: Tue, 11 Jun 2024 16:05:26 +0200 Subject: [PATCH] Escape # in URIs in LaTeX output --- citeproc-formatters.el | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/citeproc-formatters.el b/citeproc-formatters.el index e82d1bb..e2708f9 100644 --- a/citeproc-formatters.el +++ b/citeproc-formatters.el @@ -262,11 +262,16 @@ CSL tests." "Return the LaTeX-escaped version of string S." (replace-regexp-in-string citeproc-fmt--latex-esc-regex "\\\\\\&" s)) +(defconst citeproc-fmt--latex-uri-esc-regex + (regexp-opt '("#" "%")) + "Regular expression matching characters to be escaped in URIs for LaTeX output.") + (defun citeproc-fmt--latex-href (text uri) - (let ((escaped-uri (replace-regexp-in-string "%" "\\\\%" uri))) - (if (string-prefix-p "http" text) - (concat "\\url{" escaped-uri "}") - (concat "\\href{" escaped-uri "}{" text "}")))) + (let ((escaped-uri (replace-regexp-in-string + citeproc-fmt--latex-uri-esc-regex "\\\\\\&" uri))) + (if (string-prefix-p "http" text) + (concat "\\url{" escaped-uri "}") + (concat "\\href{" escaped-uri "}{" text "}")))) (defconst citeproc-fmt--latex-alist `((unformatted . ,#'citeproc-fmt--latex-escape)