0

I'm trying to make a simple environment to enter a (personal) review of a paper and cross-reference to it, using the following commands:

\newenvironment{articlereview}[2][]{%
  \hypertarget{review:#2}{\textcolor{blue}{\texttt{#2:}}}\cite{#2} (#1)
}{
  \medskip
}
\newcommand\linktoreview[1]{\hyperlink{review:#1}{\nolinkurl{#1}}}

I then use them this way:

\begin{articlereview}[date]{nice:paper}
My review...
\end{articlereview}

See review of paper \linktoreview{nice:paper}

The issue is that for some reason, I can't get rid of the : special char expansion in \linktoreview, and I get errors of the like:

 name{review:nice\\unskip\040\\penalty\040\\@M\040\040:paper}  has been referenced but does not exist, replaced by a fixed one

What I am doing wrong ?

Edit Here is a minimal (non) working example:

\documentclass{article}

\usepackage[french]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{hyperref}


\bibliographystyle{unsrt}

\newenvironment{articlereview}[2][]{%
  \hypertarget{review:#2}{\texttt{#2:}}\cite{#2} (#1)
}{
  \medskip
}
\newcommand\linktoreview[1]{\hyperlink{review:#1}{\nolinkurl{#1}}}

\begin{document}
\begin{articlereview}[date]{nice:paper}
My review...
\end{articlereview}

See review of paper \linktoreview{nice:paper}

\bibliography{Biblio}

\end{document}

As mentioned by David Carlisle, if I comment out the babel line, then all goes fine. The problem is the following: the nice:paper is a reference (well, many) in a .bib file, I'm not going to change those. Wrapping manually each use of : is also not possible (there's hundreds of them !), and it feels like "it should be possible to make it work" (since it works with other labels.

6
  • 3
    You haven't shown relevant code but I would guess you are using a French typesetting option where : is an active character that adjusts the white space Feb 11, 2020 at 14:22
  • A basic example with this code in works for me, except that I think you want \label instead of \cite in the definition of articlereview. Thus, as @DavidCarlisle says, there is something else going on.
    – rbrignall
    Feb 11, 2020 at 14:26
  • @DavidCarlisle you are correct, I am using French typesetting. The problem is I can't just disable the : expansion everywhere, since it's useful, and not around every instance of \linktoreview{nice:paper}. I will provide a MWE later on. Feb 11, 2020 at 14:35
  • you could use \string: or just use a different letter, - or _ or anything not made active by babel. Feb 11, 2020 at 14:38
  • @DavidCarlisle I've added an example. I hope my requirements are now more clear. Thanks for your help. Feb 11, 2020 at 17:36

1 Answer 1

1

You can detokenize the label/anchor argument:

\documentclass{article}

\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{hyperref}


\bibliographystyle{unsrt}

\newenvironment{articlereview}[2][]{%
  \expandafter\hypertarget\expandafter{\detokenize{review:#2}}{\texttt{#2:}}\cite{#2} (#1)
}{
  \medskip
}
\newcommand\linktoreview[1]{\expandafter\hyperlink\expandafter{\detokenize{review:#1}}{\nolinkurl{#1}}}

\begin{document}
\begin{articlereview}[date]{nice:paper}
My review...
\end{articlereview}



See review of paper \linktoreview{nice:paper}

\bibliography{Biblio}

\end{document}
1
  • Perfect ! This is exactly what I was looking for ! Feb 12, 2020 at 6:26

You must log in to answer this question.

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