moewew / biblatex-ext

Extensions for the biblatex standard styles
LaTeX Project Public License v1.3c
24 stars 3 forks source link

create generic macro for eprint and openacess #27

Closed bastien-roucaries closed 2 years ago

bastien-roucaries commented 3 years ago

Hi,

May be some part of the bug are better in biblatex, but in order to implement eprint effeciently I use:

% generic command for printing hrefwitheprint easy to override for styling
\NewDocumentCommand{\hrefeprint}{mom}{%
  \ifhyperref%
      {\href{#1}{\color{orange}{\nolinkurl{#3}\IfNoValueF{#2}{#2}}}}%
      {\nolinkurl{\color{orange}{#3}\IfNoValueF{#2}{#2}}}%
}%

% maybe implement with place holder instead of optional arg ?
\NewDocumentCommand{\DeclareEprintGeneric}{m O{always} m O{} m O{}}{
  \DeclareFieldFormat{eprint:#1}{%
    #3\addcolon\space%
    \hrefeprint{#5##1#6}{#4##1}%
  }%
  \IfNoValueF{#2}%
    {\DeclareOpenAccessEprintUrl[#2]{#1}{#5\thefield{eprint}#6}}%
}

\makeatletter
\DeclareFieldFormat{eprint:arxiv}{%
  arXiv\addcolon\space
  \hrefeprint{https://arxiv.org/\abx@arxivpath/#1}[%
    \iffieldundef{eprintclass}%
      {}%
      {\addspace\texttt{\mkbibbrackets{\thefield{eprintclass}}}}]%
      {#1}%
}
\makeatother

\DeclareEprintGeneric{ark}{ARK}[ark:/]{https://identifiers.org/ark:/}
\DeclareEprintGeneric{archive.org}{archive.org}{https://archive.org/details/}
\DeclareEprintGeneric{BHL}{BHL}{https://www.biodiversitylibrary.org/bibliography/}
\DeclareEprintGeneric{Caltech}{Caltech}{https://resolver.caltech.edu/}
\DeclareEprintGeneric{DTIC}{DTIC}{https://apps.dtic.mil/docs/citations/}
\DeclareEprintGeneric{DurhamEThese}{Durham E-These}{http://etheses.dur.ac.uk/}
\DeclareEprintGeneric{DSpace@MIT}{DSpace{@}MIT}{https://dspace.mit.edu/handle/}
\DeclareEprintGeneric{dtu.dk}{DTU.dk}{https://orbit.dtu.dk/files/}
\DeclareEprintGeneric{EThOS}{EThOS}{https://ethos.bl.uk/OrderDetails.do?uin=}
\DeclareEprintGeneric{HAL}{HAL~Id}{https://hal.archives-ouvertes.fr/}
\DeclareEprintGeneric{hdl}{HDL}{http://hdl.handle.net/}
\DeclareEprintGeneric{iastate}{iastate}{https://lib.dr.iastate.edu/}
\DeclareEprintGeneric{LUT}{LUT}{http://lutpub.lut.fi/handle/}
\DeclareEprintGeneric{KITopen-ID}{KITopen-ID}{https://publikationen.bibliothek.kit.edu/}
\DeclareEprintGeneric{Manchester}{Manchester}{https://www.research.manchester.ac.uk/portal/files/}[/FULL_TEXT.PDF]
\DeclareEprintGeneric{ResearchGate}{ResearchGate}{https://www.researchgate.net/publication/}
\DeclareEprintGeneric{Tampere}{Tampere}{https://trepo.tuni.fi//handle/}
\DeclareEprintGeneric{TUDelft}{TUDelft}{https://repository.tudelft.nl/islandora/object/uuid\%3A}
\DeclareEprintGeneric{soton}{Soton}{https://eprints.soton.ac.uk/id/eprint/}
\DeclareEprintGeneric{WhiteRose}{WhiteRose}{https://eprints.whiterose.ac.uk/}
bastien-roucaries commented 3 years ago

If ok with the principle I can cook a better patch and made a pull request

moewew commented 3 years ago

This looks like a cool idea, but I'm wondering how useful it is in general. If people are defining lots of eprint types like you and feel that they are duplicating a lot of work, they can probably whip up a helper macro that works for them (just as you did). But for the occasional use this might be overkill and if people define very exotic eprint fields, something formulaic like this might not be enough (even though this approach looks quite customisable).

From the developer standpoint adding this also means that it has to be documented extensively and I'm just not sure if the effort of documenting all this properly is really worth the gain for power users with many eprint definitions.

bastien-roucaries commented 3 years ago

@moewew I will try to simplify the macro.

They are two part:

bastien-roucaries commented 3 years ago

simpler:

\NewDocumentCommand{\DeclareEprintGeneric}{m O{always} m O{\thefield{eprint}} m}{
  \DeclareFieldFormat{eprint:#1}{%
    #3\addcolon\space%
    \hrefeprint{#5}{#4}%
  }%
  \IfNoValueF{#2}%
    {\DeclareOpenAccessEprintUrl[#2]{#1}{#5}}%
}

\DeclareEprintGeneric{ark}{ARK}[ark:/\thefield{eprint}]{https://identifiers.org/ark:/\thefield{eprint}}
\DeclareEprintGeneric{archive.org}{archive.org}{https://archive.org/details/\thefield{eprint}}
\DeclareEprintGeneric{BHL}{BHL}{https://www.biodiversitylibrary.org/bibliography/\thefield{eprint}}
\DeclareEprintGeneric{Caltech}{Caltech}{https://resolver.caltech.edu/\thefield{eprint}}
\DeclareEprintGeneric{DTIC}{DTIC}{https://apps.dtic.mil/docs/citations/\thefield{eprint}}
\DeclareEprintGeneric{DurhamEThese}{Durham E-These}{http://etheses.dur.ac.uk/\thefield{eprint}}
\DeclareEprintGeneric{DSpace@MIT}{DSpace{@}MIT}{https://dspace.mit.edu/handle/\thefield{eprint}}
\DeclareEprintGeneric{dtu.dk}{DTU.dk}{https://orbit.dtu.dk/files/\thefield{eprint}}
\DeclareEprintGeneric{EThOS}{EThOS}{https://ethos.bl.uk/OrderDetails.do?uin=\thefield{eprint}}
\DeclareEprintGeneric{HAL}{HAL~Id}{https://hal.archives-ouvertes.fr/\thefield{eprint}}
\DeclareEprintGeneric{hdl}{HDL}{http://hdl.handle.net/\thefield{eprint}}
\DeclareEprintGeneric{iastate}{iastate}{https://lib.dr.iastate.edu/\thefield{eprint}}
\DeclareEprintGeneric{LUT}{LUT}{http://lutpub.lut.fi/handle/\thefield{eprint}}
\DeclareEprintGeneric{KITopen-ID}{KITopen-ID}{https://publikationen.bibliothek.kit.edu/\thefield{eprint}}
\DeclareEprintGeneric{Manchester}{Manchester}{https://www.research.manchester.ac.uk/portal/files/\thefield{eprint}/FULL_TEXT.PDF}
\DeclareEprintGeneric{ResearchGate}{ResearchGate}{https://www.researchgate.net/publication/\thefield{eprint}}
\DeclareEprintGeneric{Tampere}{Tampere}{https://trepo.tuni.fi//handle/\thefield{eprint}}
\DeclareEprintGeneric{TUDelft}{TUDelft}{https://repository.tudelft.nl/islandora/object/uuid\%3A\thefield{eprint}}
\DeclareEprintGeneric{soton}{Soton}{https://eprints.soton.ac.uk/id/eprint/\thefield{eprint}}
\DeclareEprintGeneric{WhiteRose}{WhiteRose}{https://eprints.whiterose.ac.uk/\thefield{eprint}}
moewew commented 3 years ago

Sorry, I don't quite understand what you say about bibmacro eprint+eprintclass. There is no such bibmacro. eprintclass formatting is currently handled within the relevant field format (and only for arXiv).

Now with the simplified macro I'd be even more tempted to say that it is fairly easy for people who want something like this to quickly define it themselves at exactly the level they need. As general macro implemented in the package here, I'm currently inclined to believe that it is almost impossible to strike a good balance between useful, generally applicable, customisable on the one hand and usability, 'documentability' on the other hand.

bastien-roucaries commented 3 years ago

@moewew in fact in 99% of case eprint is always: eprintname: eprintfiledwithurl [optional eprintclass] so a eprint:* bibmacro with 3 parameter and one optional will be better and will even simplify biblatex code

moewew commented 3 years ago

Hmmm. Making this macro less complex obviously makes it easier to document and use, but at the same time it becomes almost trivial to replicate for people who want this (and possibly with additional bells and whistles people may want on a case-by-case basis). So I'm wondering how useful this is going to be. I guess on the whole biblatex does not need to define all utility commands anyone would ever want to use. It is enough if the building blocks are there.

moewew commented 2 years ago

I'm going to close this and will not implement a macro like this in biblatex-ext. As I said above, I don't believe that I can find a satisfying balance between usefulness on the one hand and usability/documentability on the other hand. Plus, this is going to be fairly niche stuff anyway. If you think this could be useful you can always share your code via question and self-answer on TeX.SX or other TeX forums, or you can create your own biblatex utility package and send it off to CTAN.