0

I want to write a macro that is something like this:

\get-url{10.1090/tran/8044} ------> result: https://www.ams.org/journals/tran/2021-374-01/S0002-9947-2020-08044-1/

i.e. input=doi and output= url of paper in publisher webpage

This is what I want. But it would be very nice if one can extract and return accepted and published dates and authors information. But this is just a dream, so ...!

12
  • 2
    You can join DOI number with https://doi.org/, such as https://doi.org/10.1090/tran/8044, you will get the right url. As for how LaTeX handles network-related content, I don't know about it. Maybe you can try an external program or use Lua?
    – Clara
    Commented Aug 29, 2022 at 9:31
  • For the full bibliographic information in BibTeX format you could execute a system call to doi2bib.org from your document (in this case that would be doi2bib.org/bib/10.1090/tran/8044) or some other doi resolving service.
    – Marijn
    Commented Aug 29, 2022 at 9:34
  • The question is why you would want to do that though. In the Bibliography section a doi is as good as the full publisher url (or better because it takes less space). For authors, dates etc. it is better to add/check these manually as automatically generated entries are often inaccurate. Or do you want to use this in some other way unrelated to the Bibliography section? If so, then maybe you can explain a bit more in your question what you actually want to achieve.
    – Marijn
    Commented Aug 29, 2022 at 9:36
  • Dear @Marijn: I don't want it for bibliographic usage. I want it for some purpose to make easy some time-consuming copy-paste.
    – C.F.G
    Commented Aug 29, 2022 at 9:39
  • 1
    @C.F.G I don't think you need to write a program in LaTeX. You can write it in a more familiar language and call it with LaTeX, such as minted package.
    – Clara
    Commented Aug 29, 2022 at 9:52

1 Answer 1

3

The doi resolver doi.org can return json output using the Accept: application/json header. You can parse this output for example with Python and extract the relevant fields. Then you can write this content to a file which you can include as part of your LaTeX document.

Part of the json output looks as follows for the paper in the question:

"resource": {
  "primary": {
    "URL": "https://www.ams.org/tran/2021-374-01/S0002-9947-2020-08044-1/"
  }
},
"subtitle": [],
"short-title": [],
"issued": {
  "date-parts": [
    [
      2020,
      11,
      3
    ]
  ]
},
"references-count": 62,
"journal-issue": {
  "issue": "1",
  "published-print": {
    "date-parts": [
      [
        2021,
        1
      ]
    ]
  }
},
"alternative-id": [
  "S0002-9947-2020-08044-1"
],
"URL": "http://dx.doi.org/10.1090/tran/8044",
"relation": {},
"ISSN": [
  "0002-9947",
  "1088-6850"
],
"subject": [
  "Applied Mathematics",
  "General Mathematics"
],
"container-title-short": "Trans. Amer. Math. Soc.",
"published": {
  "date-parts": [
    [
      2020,
      11,
      3
    ]
  ]
}

This already contains most of the information that was mentioned in the question and the comments.

Small Python script using pycurl to retrieve the data:

import pycurl
from io import BytesIO
import json
import calendar

doi = '10.1090/tran/8044'

# download json using pycurl
mybuffer = BytesIO()
c = pycurl.Curl()
c.setopt(c.URL, 'http://dx.doi.org/'+doi)
c.setopt(c.FOLLOWLOCATION, True)
c.setopt(c.HTTPHEADER, ["Accept: application/json"])
c.setopt(c.WRITEDATA, mybuffer)
c.perform()
c.close()

# parse with json library
contents = mybuffer.getvalue()
bib_dict = json.loads(contents)
# open file to be included by LaTeX
texout = open("paperinfo.tex", "w")
# start a verbatim environment to prevent problems with special characters
print("\\begin{verbatim}", file=texout)
# retrieve relevant fields from json output
print("doi:", doi, file=texout)
print("URL:", bib_dict['resource']['primary']['URL'], file=texout)
print("URL:", bib_dict['resource']['primary']['URL'], file=texout)
print("authors:", file=texout)
for person in bib_dict["author"]:
   print(person['given'], person['family'], file=texout)
print("Published date:", calendar.month_name[bib_dict['published']['date-parts'][0][1]], str(bib_dict['published']['date-parts'][0][2])+",", bib_dict['published']['date-parts'][0][0], file=texout)
# end the verbatim environment and close the file
print("\\end{verbatim}", file=texout)
texout.close()

Resulting paperinfo.tex:

\begin{verbatim}
doi: 10.1090/tran/8044
URL: https://www.ams.org/tran/2021-374-01/S0002-9947-2020-08044-1/
URL: https://www.ams.org/tran/2021-374-01/S0002-9947-2020-08044-1/
authors:
Anand Dessai
David González-Álvaro
Published date: November 3, 2020
\end{verbatim}

Show this file in a complete LaTeX document:

\documentclass{article}
\begin{document}
\input{paperinfo}
\end{document}

Resulting pdf:

enter image description here

Note: the workflow is a two-step process: first you manually run the Python script, this will create the file paperinfo.tex, and then you run LaTeX manually on the file that needs to have the information included.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .