emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [Patch] Adding support for arxiv type link
@ 2023-12-18  5:19 Hammer Hu
  2023-12-18 12:53 ` Ihor Radchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Hammer Hu @ 2023-12-18  5:19 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 207 bytes --]

Hi there,

I made several commit adding support for link as arxiv:2208.11710. These codes
basically come from lisp/ol-doi.el. I copy and modify them side by side. Let me
know what do you think!

Best,
Hammer

[-- Attachment #2: 0001-New-file.patch --]
[-- Type: text/x-patch, Size: 3074 bytes --]

From 97ea5d017a2c9a889604fb5216ded59a1952e723 Mon Sep 17 00:00:00 2001
From: hammerfunctor <topo20@protonmail.com>
Date: Mon, 18 Dec 2023 00:01:39 -0500
Subject: [PATCH 1/3] New file

---
 lisp/ol-arxiv.el | 76 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)
 create mode 100644 lisp/ol-arxiv.el

diff --git a/lisp/ol-arxiv.el b/lisp/ol-arxiv.el
new file mode 100644
index 000000000..280b909f2
--- /dev/null
+++ b/lisp/ol-arxiv.el
@@ -0,0 +1,76 @@
+;;; ol-arxiv.el --- ARXIV links support in Org           -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2023-2023 Free Software Foundation, Inc.
+
+;; Author: Zhengfei Hu <hammer@posteo.net>
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This library introduces the "arxiv" link type in Org, and provides
+;; code for opening and exporting such links.
+
+;;; Code:
+
+(require 'org-macs)
+(org-assert-version)
+
+(require 'ol)
+
+(defcustom org-link-arxiv-server-url "https://arxiv.org/abs/"
+  "The URL of the ARXIV server."
+  :group 'org-link-follow
+  :version "24.3"
+  :type 'string
+  :safe #'stringp)
+
+(defun org-link-arxiv-open (path arg)
+  "Open a \"arxiv\" type link.
+PATH is a the path to search for, as a string.
+ARG is passed to `browse-url'."
+  (browse-url (url-encode-url (concat org-link-arxiv-server-url path)) arg))
+
+(defun org-link-arxiv-export (path desc backend info)
+  "Export a \"arxiv\" type link.
+PATH is the ARXIV name.  DESC is the description of the link, or
+nil.  BACKEND is a symbol representing the backend used for
+export.  INFO is a plist containing the export parameters."
+  (let ((uri (concat org-link-arxiv-server-url path)))
+    (pcase backend
+      (`html
+       (format "<a href=\"%s\">%s</a>" uri (or desc uri)))
+      (`latex
+       (if desc (format "\\href{%s}{%s}" uri desc)
+	 (format "\\url{%s}" uri)))
+      (`ascii
+       (if (not desc) (format "<%s>" uri)
+         (concat (format "[%s]" desc)
+		 (and (not (plist-get info :ascii-links-to-notes))
+		      (format " (<%s>)" uri)))))
+      (`texinfo
+       (if (not desc) (format "@uref{%s}" uri)
+         (format "@uref{%s, %s}" uri desc)))
+      (_ uri))))
+
+(org-link-set-parameters "arxiv"
+                         :follow #'org-link-arxiv-open
+                         :export #'org-link-arxiv-export)
+
+
+(provide 'org-link-arxiv)
+(provide 'ol-arxiv)
+;;; ol-arxiv.el ends here
-- 
2.43.0


[-- Attachment #3: 0002-lisp-ox-latex.el-org-latex-link-keep-arxiv-type-link.patch --]
[-- Type: text/x-patch, Size: 815 bytes --]

From 013dffb022ca84a9aa40e2b4d9e8764b9cd94169 Mon Sep 17 00:00:00 2001
From: hammerfunctor <topo20@protonmail.com>
Date: Mon, 18 Dec 2023 00:04:21 -0500
Subject: [PATCH 2/3] lisp/ox-latex.el (org-latex-link): keep arxiv type link

---
 lisp/ox-latex.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 41c2d3994..11140eddf 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2917,7 +2917,7 @@ INFO is a plist holding contextual information.  See
 		  link (plist-get info :latex-inline-image-rules)))
 	 (path (org-latex--protect-text
 		(pcase type
-		  ((or "http" "https" "ftp" "mailto" "doi")
+		  ((or "http" "https" "ftp" "mailto" "doi" "arxiv")
 		   (concat type ":" raw-path))
 		  ("file"
 		   (org-export-file-uri raw-path))
-- 
2.43.0


[-- Attachment #4: 0003-lisp-org.el-org-modules-autoload-new-library.patch --]
[-- Type: text/x-patch, Size: 1550 bytes --]

From 20dee5f0f3c7a784f490feaa14b98ba127fe7574 Mon Sep 17 00:00:00 2001
From: hammerfunctor <topo20@protonmail.com>
Date: Mon, 18 Dec 2023 00:04:55 -0500
Subject: [PATCH 3/3] lisp/org.el (org-modules): autoload new library

---
 lisp/org.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/org.el b/lisp/org.el
index 8868388bf..366626b52 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -746,7 +746,7 @@ defined in org-duration.el.")
     (require 'org-element)
     (org-element-cache-reset 'all)))
 
-(defcustom org-modules '(ol-doi ol-w3m ol-bbdb ol-bibtex ol-docview ol-gnus ol-info ol-irc ol-mhe ol-rmail ol-eww)
+(defcustom org-modules '(ol-doi ol-arxiv ol-w3m ol-bbdb ol-bibtex ol-docview ol-gnus ol-info ol-irc ol-mhe ol-rmail ol-eww)
   "Modules that should always be loaded together with org.el.
 
 If a description starts with <C>, the file is not part of Emacs and Org mode,
@@ -773,6 +773,7 @@ For export specific modules, see also `org-export-backends'."
 	(const :tag "   ctags:             Access to Emacs tags with links" org-ctags)
 	(const :tag "   docview:           Links to Docview buffers" ol-docview)
         (const :tag "   doi:               Links to DOI references" ol-doi)
+        (const :tag "   arxiv:             Links to ARXIV references" ol-arxiv)
 	(const :tag "   eww:               Store link to URL of Eww" ol-eww)
 	(const :tag "   gnus:              Links to GNUS folders/messages" ol-gnus)
 	(const :tag "   habit:             Track your consistency with habits" org-habit)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-12-18 12:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-18  5:19 [Patch] Adding support for arxiv type link Hammer Hu
2023-12-18 12:53 ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).