Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reformat Strings for DOI-Links

970 views
Skip to first unread message

Lars Karsten

unread,
Dec 15, 2003, 3:58:16 AM12/15/03
to
Hi

I'm a newbie, sorry if I don't use the right conventions. I need a
macro and don't have any idea, how to make it.

I create my bibliography with BibTeX. I want every entry to be cited
with its Online-URL resp. its DOI-Number (that is a permanent URL).
The DOI-Number could be converted into an URL by simply adding
"http://dx.doi.org/". So I have a little macro called \doi{#1} which
exactly simply adds that tag and create a URL.

Unfortunatly the DOI-Numbers could contain charakters like "#" which
doesn't work in the web browser. Some characters in the DOI have to be
replaced by the Hex-Charakter like "%23" to work in the web browser.

What I need is a macro, that scans a string, replaces each "#" by
"%23" (and maybe some othe replacements) and prints the new string
out. See example below.

Another problem are the ">" and "<"-characters in the doi. The should
be replaced by the "\textless" and "\textgreater" command in the
description of the url. The "#" should be "\#" in the description.

Macro: \doi{#1}

Input #1 is a DOI-number like:
10.1002/1521-3951(200103)224:1<271::AID-PSSB271>3.0.CO;2-#

Output of the Macro should be a \href-command, where in the url the
"#" is replaced by the Hex-representive:

\href{http://dx.doi.org/10.1002/1521-3951(200103)224:1<271::AID-PSSB271>3.0.CO;2-%23}{doi:10.1002/1521-3951(200103)224:1\textless271::AID-PSSB271\textgreater3.0.CO;2-\#}

Thanks in advance,
regards,
Lars

Heiko Oberdiek

unread,
Dec 15, 2003, 12:40:22 PM12/15/03
to
lkar...@gmx.de (Lars Karsten) wrote:

> I create my bibliography with BibTeX. I want every entry to be cited
> with its Online-URL resp. its DOI-Number (that is a permanent URL).
> The DOI-Number could be converted into an URL by simply adding
> "http://dx.doi.org/". So I have a little macro called \doi{#1} which
> exactly simply adds that tag and create a URL.
>
> Unfortunatly the DOI-Numbers could contain charakters like "#" which
> doesn't work in the web browser. Some characters in the DOI have to be
> replaced by the Hex-Charakter like "%23" to work in the web browser.
>
> What I need is a macro, that scans a string, replaces each "#" by
> "%23" (and maybe some othe replacements) and prints the new string
> out. See example below.
>
> Another problem are the ">" and "<"-characters in the doi. The should
> be replaced by the "\textless" and "\textgreater" command in the
> description of the url. The "#" should be "\#" in the description.
>
> Macro: \doi{#1}
>
> Input #1 is a DOI-number like:
> 10.1002/1521-3951(200103)224:1<271::AID-PSSB271>3.0.CO;2-#
>
> Output of the Macro should be a \href-command, where in the url the
> "#" is replaced by the Hex-representive:
>
> \href{http://dx.doi.org/10.1002/1521-3951(200103)224:1<271::AID-PSSB271>3.0.CO;2-%23}{doi:10.1002/1521-3951(200103)224:1\textless271::AID-PSSB271\textgreater3.0.CO;2-\#}

If \doi is not used inside macros, then the following can be used:

\documentclass{article}
\usepackage{hyperref}

\makeatletter
\newcommand*{\doi}{%
\begingroup
\lccode`\~=`\#\relax
\lowercase{%
\def~{\#}%
}%
\lccode`\~=`\<\relax
\lowercase{%
\def~{\textless}%
}%
\lccode`\~=`\>\relax
\lowercase{%
\def~{\textgreater}%
}%
\lccode`\~=0\relax
\catcode`\#=\active
\catcode`\<=\active
\catcode`\>=\active
\@doi
}%
\def\@doi#1{%
\let\#\relax
\let\textless\relax
\let\textgreater\relax
\edef\x{%
\toks0={{doi:#1}}%
}%
\x
\edef\#{\@percentchar23}%
\edef\textless{\string<}%
\edef\textgreater{\string>}%
\edef\x{%
\toks1={\noexpand\href{http://dx.doi.org/#1}}%
}%
\x
\edef\x{%
\endgroup
\the\toks1 \the\toks0 %
}%
\x
}
\makeatother

\begin{document}
\doi{123:456<789>-#foo}
\end{document}

Yours sincerely
Heiko <ober...@uni-freiburg.de>

Lars Karsten

unread,
Dec 18, 2003, 10:45:33 AM12/18/03
to
Hi Heiko,

I don't understand anything, but it works!

Great! Thank you _very_ much.

Lars


> Yours sincerely
> Heiko <ober...@uni-freiburg.de>

0 new messages