Skip to content

Commit

Permalink
Escape # in URIs in LaTeX output
Browse files Browse the repository at this point in the history
  • Loading branch information
andras-simonyi committed Jun 11, 2024
1 parent fed2853 commit 59b141e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions citeproc-formatters.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 59b141e

Please sign in to comment.