Skip to content

Commit

Permalink
Merge pull request #167 from andras-simonyi/166-Escape_#_in_URIs_in_L…
Browse files Browse the repository at this point in the history
…aTeX_output

Escape # in URIs in LaTeX output
  • Loading branch information
andras-simonyi authored Jun 11, 2024
2 parents fed2853 + 59b141e commit 08f988e
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 08f988e

Please sign in to comment.