summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/orcidlink/orcidlink.dtx
blob: fcc5a73176338d4f9aa417a80e1cc43367d3a021 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
% \iffalse meta-comment
%
% Copyright (C) 2019-2024 by Leo C. Stein <leo.stein@gmail.com>
% ---------------------------------------------------------------------------
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Leo C. Stein.
%
% This work consists of the files orcidlink.dtx and orcidlink.ins
% and the derived filebase orcidlink.sty.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{orcidlink.dtx}
%</driver>
%
%<*driver>
\documentclass{ltxdoc}
\usepackage[dvipsnames]{xcolor}
\usepackage{orcidlink}[2024/06/25]
\hypersetup{colorlinks,urlcolor=NavyBlue,citecolor=NavyBlue,linkcolor=NavyBlue}
\hypersetup{pdftitle={The orcidlink package},pdfauthor={Leo C. Stein},
  pdfsubject={-}}
\usepackage{graphicx}
\usepackage{microtype}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{orcidlink.dtx}
  \PrintChanges
\end{document}
%</driver>
% \fi
%
% \CheckSum{59}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%
% \changes{v1.0.0}{2020/11/19}{Converted to DTX file}
% \changes{v1.0.1}{2020/11/21}{Bugfix due to misunderstanding of docstrip}
% \changes{v1.0.2}{2020/11/21}{Fix fragility of command when inside of
% author, and combined with hyperref's option pdfusetitle}
% \changes{v1.0.3}{2021/03/15}{Improve fragility by calculating
% scaling ourselves, and using DeclareRobustCommand}
% \changes{v1.0.4}{2021/06/11}{Use XeTeXLinkBox to get hyperlink
% working correctly with XeTeX.  Thanks to Tim Henke for the bug report.}
% \changes{v1.0.5}{2023/12/30}{Turn off TikZ externalization of logos.
% Thanks to github user aquileia for the bug report.}
% \changes{v1.1.0}{2024/06/25}{Support ORCID's three different ID
% formats. Thanks to Hugo Heagren for suggestions.}
%
% \DoNotIndex{\newcommand,\newenvironment}
%
% \GetFileInfo{orcidlink.sty}
% \title{The \textsf{orcidlink} package}
% \author{Leo C.\ Stein\,\orcidlink{0000-0001-7559-9597} \\ \href{mailto:leo.stein@gmail.com}{leo.stein@gmail.com}}
% \date{\fileversion~from \filedate}
%
% \maketitle
%
% \noindent Source repo:
% \url{https://github.com/duetosymmetry/orcidlink-LaTeX-command}.
%
% \section{Introduction}
%
% This is a LaTeX style file providing a macro for inserting a
% hyperlinked ORCiD logo.  The package also provides three commands
% for ORCiD's three recommended ID printing formats, and a command for
% just the ORCiD logo, not linked to anything.
%
% \section{Usage}
%
% To use this package, in the preamble include
% \begin{verbatim}
%    \usepackage{orcidlink}
% \end{verbatim}
%
% \DescribeMacro{\orcidlink\marg{orcid}}
% Insert the ORCiD logo (\orcidlink{}), which is hyperlinked to the URL
% of the researcher whose iD was specified.
% Replace the mandatory argument \meta{orcid} with your
% ORCiD --- just the digits, not your whole URL.
% For example, the command
% |\orcidlink{0000-0001-7559-9597}| will hyperlink to the URL
% \url{https://orcid.org/0000-0001-7559-9597}.
% This is most common in
% the author list.  For example, in the preamble of a RevTeX article,
% if you write
% \begin{verbatim}
%    \author{Emmy Noether\,\orcidlink{0000-0000-0000-0000}}
% \end{verbatim}
% then the article byline will look something like this:
%
% \includegraphics[width=0.5\textwidth]{preview}\newline{}
% The macro is used in the author line of this documentation as well.
%
% \DescribeMacro{\orcidlogo}
% If you simply want the ORCiD logo without a hyperlink anywhere, use
% |\orcidlogo|.
%
% ORCiD's \href{https://info.orcid.org/brand-guidelines/}{guidelines}
% recommend three formats: full, compact, and inline.  The three
% formats are available:
% \begin{enumerate}
% \item \DescribeMacro{\orcidlinkf\marg{orcid}} Full format.  Example:
% |\orcidlinkf{0000-0001-7559-9597}| will insert
% \orcidlinkf{0000-0001-7559-9597}
% \item \DescribeMacro{\orcidlinkc\marg{orcid}} Compact format.
% Example: |\orcidlinkc{0000-0001-7559-9597}| will insert
% \orcidlinkc{0000-0001-7559-9597}
% \item \DescribeMacro{\orcidlinki\marg{Name}\marg{orcid}} Inline
% format.  Example: |\orcidlinki{Leo C. Stein}{0000-0001-7559-9597}|
% will insert \orcidlinki{Leo C. Stein}{0000-0001-7559-9597}
% \end{enumerate}
%
% \DescribeMacro{\orcidlinkX\marg{before}\marg{orcid}\marg{after}}
%
% The command |\orcidlinkX{before}{orcid}{after}| is a helper macro
% that's used to implement all of the others.  Though it is just an
% internal helper, I saw no reason to keep it internal.
% |\orcidlinkX{before}{orcid}{after}| results in
% \orcidlinkX{before}{orcid}{after}.  The entire output is hyperlinked
% to the ORCiD page.  There is a thin space |\,| between ``before,''
% the logo, and ``after.''  However if ``before'' is empty, the space
% will be omitted; similarly for ``after.''
%
% \section{Package Compatibility}
%
% This package relies on \texttt{hyperref} and \texttt{tikz}.  If you
% want to pass options to either of these packages, load them
% \emph{before} you load \texttt{orcidlink}.  Similarly, if you want
% to specify options to e.g. \texttt{xcolor}, load \texttt{xcolor}
% before loading \texttt{tikz} or \texttt{orcidlink}.
%
% \StopEventually{}
%
% \section{Implementation}
%
% \iffalse
%<*package>
% \fi
%
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{orcidlink}
    [2024/06/26 v1.1.0 Support ORCID's three different ID formats.]

%% This started out as Milo's code on TeX.SE,
%% see https://tex.stackexchange.com/a/445583/34063.
%% It has since been expanded with more commands.
\RequirePackage{hyperref}
\RequirePackage{tikz}

\ProcessOptions\relax

\usetikzlibrary{svg.path}

\definecolor{orcidlogocol}{HTML}{A6CE39}
\tikzset{
  orcidlogo/.pic={
    \fill[orcidlogocol] svg{M256,128c0,70.7-57.3,128-128,128C57.3,256,0,198.7,0,128C0,57.3,57.3,0,128,0C198.7,0,256,57.3,256,128z};
    \fill[white] svg{M86.3,186.2H70.9V79.1h15.4v48.4V186.2z}
                 svg{M108.9,79.1h41.6c39.6,0,57,28.3,57,53.6c0,27.5-21.5,53.6-56.8,53.6h-41.8V79.1z M124.3,172.4h24.5c34.9,0,42.9-26.5,42.9-39.7c0-21.5-13.7-39.7-43.7-39.7h-23.7V172.4z}
                 svg{M88.7,56.8c0,5.5-4.5,10.1-10.1,10.1c-5.6,0-10.1-4.6-10.1-10.1c0-5.6,4.5-10.1,10.1-10.1C84.2,46.7,88.7,51.3,88.7,56.8z};
  }
}

%% Reciprocal of the height of the svg whose source is above.  The
%% original generates a 256pt high graphic; this macro holds 1/256.
\newcommand{\@OrigHeightRecip}{0.00390625}

%% We will compute the current X height to make the logo the right height
\newlength{\@curXheight}

%% Prevent externalization of the ORCiD logo.
\newcommand{\@preventExternalization}{%
\ifcsname tikz@library@external@loaded\endcsname%
\tikzset{external/export next=false}\else\fi%
}

%    \end{macrocode}
%
% \begin{macro}{\orcidlogo}
%    \begin{macrocode}
\newcommand{\orcidlogo}{%
\texorpdfstring{%
\setlength{\@curXheight}{\fontcharht\font`X}%
\XeTeXLinkBox{%
\@preventExternalization%
\begin{tikzpicture}[yscale=-\@OrigHeightRecip*\@curXheight,
xscale=\@OrigHeightRecip*\@curXheight,transform shape]
\pic{orcidlogo};
\end{tikzpicture}%
}}{}}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\orcidlinkX}
%    \begin{macrocode}
\DeclareRobustCommand\orcidlinkX[3]{\href{https://orcid.org/#2}{%
\ifstrempty{#1}{}{#1\,}\orcidlogo\ifstrempty{#3}{}{\,#3}}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\orcidlinkf}
%    \begin{macrocode}
\newcommand{\orcidlinkf}[1]{\orcidlinkX{}{#1}{https://orcid.org/#1}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\orcidlinkc}
%    \begin{macrocode}
\newcommand{\orcidlinkc}[1]{\orcidlinkX{}{#1}{#1}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\orcidlinki}
%    \begin{macrocode}
\newcommand{\orcidlinki}[2]{\orcidlinkX{#1}{#2}{}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\orcidlink}
%    \begin{macrocode}
\newcommand{\orcidlink}[1]{\orcidlinkX{}{#1}{}}

\endinput
%    \end{macrocode}
% \end{macro}
%

%
% \iffalse
%</package>
% \fi
%
% \Finale
\endinput