# [pdftex] Strange error: hyperref meets multline

Ross Moore ross at ics.mq.edu.au
Sun Mar 9 08:04:44 CET 2008

Hi Victor,

On 09/03/2008, at 12:54 PM, Victor Ivrii wrote:

> On Sat, Mar 8, 2008 at 8:40 PM, Ross Moore <ross at ics.mq.edu.au> wrote:

>>> \begin{multline}
>>> 2+1=2
>>> \label{B}\tag*{$(\ref*{A})^*$}
>>
>>  Why are you putting a \ref  inside the  \tag{...} ?
>
> I am putting \ref* not \ref. Which
>
>>
>>  So when you call  \ref{B}  part of the processing will be
>>  to evaluate  \ref*{A} .
>>  This results in the macro holding the target anchor for \ref{B}
>>  being replaced by that for \ref{A} .
>
> No, because \ref* does not create an anchor (see hyperref
> documentation).

OK, you are right.  \ref*  is already doing what I thought
was needed. The real explanation is a little more complicated,
and specific to only some of the AMSmath alignment environments.

But first, do you not get the following message in the .log file?

pdfTeX warning (dest): name {AMS.1} has been referenced but does not
exist,
replaced by a fixed one.

This means that no destination was put into the .pdf output, to be
the target of the hyperlink --- at least not at the correct place.
Instead, pdfTeX puts the destination as 'page 1'.
You can check this by putting an extra page into your test document,
*before* any of the mathematics.

>
> The purpose of this is to have equation tag for a second equation the
> same as for the first one but with * and to do it automatically
>
>> I suspect that you want the visual result of the \ref*{A} to be
>> put onto the page, but without the extra processing of hyperlinks
>
> No, if I wanted this I would put \ref*{B}. I want hyperlink to follow
> to page where {B} is.

This is what I meant; by not processing the hyperlink
that would result from \ref{A}. That from \ref{B} should
be included, and is done. Unfortunately the target for
this link has not been created the way you want.

> And this construction perfectly works with
> equation and align

\begin{multline} ... \end{multline}  works differently
to many other AMS alignment environments.

It uses a 2-step process:
a.  first typeset the contents, to measure the resulting
size; then
b.  re-processes the contents with appropriate
alignments, knowing how much space is needed.

In step (a), the \tag  macro's argument is processed to get
its size, and the argument is saved for use in step (b).
Only the first part of this is patched by  hyperref to create
a pdf destination.  Unfortunately, this destination does *not*
end up in the PDF output.

For step (b) the expansions of \tag and \label are changed
to simply gobble and ignore their arguments. For the visible
tag, the value stored in step (a) is used. But the macros
that handle it have not been patched by hyperref to create
a named destination.
This is why pdfTeX cannot find  AMS.1  as a valid destination.

It is not at all clear which is the best internal macro
to patch, to make hyperlinks work correctly in this setting.

Already hyperref patches  \make at df@tag@@  to include a macro:

\Hmake at df@tag@@ #1
->\gdef\df at tag{\maketag@@@{#1}\def\@currentlabel{#1}}

before building a hyperlink anchor. This works fine in other
AMS environments, but not with  {multline} (and perhaps some
others as well).

What is needed, in this case, is a patch also to  \maketag@@@ .

A difficulty will be to do this properly, so that it works
correctly with *all* the AMS alignment environments.

>
> Victor

Hope this helps,

Ross

------------------------------------------------------------------------
Ross Moore                                         ross at maths.mq.edu.au
Mathematics Department                             office: E7A-419
Macquarie University                               tel: +61 +2 9850 8955
Sydney, Australia  2109                            fax: +61 +2 9850 8114
------------------------------------------------------------------------