joaomlourenco / novathesis

A LaTeX template for academic monographs (e.g., dissertations and thesis). This template serves both beginners and proficient LaTeX users.
http://joaomlourenco.github.io/novathesis/
LaTeX Project Public License v1.3c
790 stars 133 forks source link

Bad links when referencing subbottoms with \ref and \subcaptionref #39

Closed bcandeias closed 8 years ago

bcandeias commented 8 years ago

There is a conflict between the memoir class and hyperref package when a subbottom is referenced.

When more than one figure is created with several subfigures, a reference to any subottom will point ALWAYS to the first one.

E.g.,

Chapter 1 has Figure 1.1 with two subfigures (a and b):

\begin{figure}[htbp]
    \centering
    \subbottom[Subbottom 1] {%
        \label{fig:sub1}
        \includegraphics{fig1}
    }~
    \subbottom[Subbottom 2] {%
        \label{fig:sub2}
        \includegraphics{fig2}
    }
    \caption{\emph{subbottom} example}
    \label{fig:1}
\end{figure}

Chapter 2 has Figure 2.1 with two subfigures (a and b):

\begin{figure}[htbp]
    \centering
        \subbottom[Subbottom 3] {%
            \label{fig:sub3}
            \includegraphics{fig3}
        }~
        \subbottom[Subbottom 4] {%
            \label{fig:sub4}
            \includegraphics{fig4}
        }
    \caption{Yet another \emph{subbottom} example}
    \label{fig:2}
\end{figure}

The command \ref{fig:sub3} will print 2.1(a), but the link will point to Figure 1.1(a), instead of pointing to Figure 2.1(a).

Furthermore I get a compiling warning similar to these:

destination with the same identifier (name{subfigure.1}) has been already used, duplicate ignored
destination with the same identifier (name{subfigure.2}) has been already used, duplicate ignored

I saw this problem mentioned here, here, plus in a couple of places, but none of the provided solutions worked. Additionally, the memoir package manual did not shed any light on the matter.

Is anyone else having this problem? Can you reproduce it? It is important to know this because it can occur due to my setup.

Problem spotted with version 3.1.2 (2016/02/22) and older versions.

tmonteiro2344 commented 8 years ago

Bruno, yep it is reproducible. Using the latest template version, texlive 2015, memoir 3.7e, and hyperref 6.83m Em 15/03/2016 15:01, "Bruno Candeias" notifications@github.com escreveu:

There is a conflict between the memoir class and hyperref package when a subbottom is referenced.

When more than one figure is created with several subfigures, a reference to any subottom will point ALWAYS to the first one.

E.g.,

Chapter 1 has Figure 1.1 with two subfigures (a and b):

\begin{figure}[htbp] \centering \subbottom[Subbottom 1] {% \label{fig:sub1} \includegraphics{fig1} }~ \subbottom[Subbottom 2] {% \label{fig:sub2} \includegraphics{fig2} } \caption{\emph{subbottom} example} \label{fig:1}\end{figure}

Chapter 2 has Figure 2.1 with two subfigures (a and b):

\begin{figure}[htbp] \centering \subbottom[Subbottom 3] {% \label{fig:sub3} \includegraphics{fig3} }~ \subbottom[Subbottom 4] {% \label{fig:sub4} \includegraphics{fig4} } \caption{Yet another \emph{subbottom} example} \label{fig:2}\end{figure}

The command \ref{fig:sub3} will print 2.1(a), but the link will point to Figure 1.1(a), instead of pointing to Figure 2.1(a).

Furthermore I get a compiling warning similar to these:

destination with the same identifier (name{subfigure.1}) has been already used, duplicate ignored destination with the same identifier (name{subfigure.2}) has been already used, duplicate ignored

I saw this problem mentioned here http://www.tex.ac.uk/FAQ-hyperdupdest.html, here http://compgroups.net/comp.text.tex/problems-with-subbottom-hyperref-and-memoir/1930023, plus in a couple of places, but none of the provided solutions worked. Additionally, the memoir package manual did not shed any light on the matter.

Is anyone else having this problem? Can you reproduce it? It is important to know this because it can occur due to my setup.

Problem spotted with version 3.1.2 (2016/02/22) and older versions.

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/joaomlourenco/unlthesis/issues/39

bcandeias commented 8 years ago

Great! Well, not great, but at least I'm not the only one. I asked a friend to try it out and he said that it didn't happen with him. I know that he has an older version of the template, but I don't know which one. I'll try to figure out why later today, and post an update.

The threads I found online were a bit old, so it should be assumable that by now the problem was fixed either in memoir, hyperref or memhfixc. Although I think — from what I read in the hyperref's README — that the template does not require any package that conflicts with either of the above, the order by which they are loaded may matter (it usually do when one of the players is hyperref).

Thanks for trying this out, Tomas! I'll return to the matter later today.

bcandeias commented 8 years ago

Sorry for the absence, but I've been busy...

So here's the deal: I saw with my own eyes that, as my friend told me, the subbottoms were working with his setup. He was running Version 2015/07/30 [3.0.4] with TeXstudio.

I just downloaded version 3.0.4 from the releases page and tried out the example showed in the template. Specifically, right above Section 3.8, there are two references to Figure 3.4(a) and 3.4(b) that point to Figure 3.1(a) and 3.2(b), respectively. So I compiled it and guess what: I still get the wrong linking. This makes me believe that the problem is with the packages installed, and not with the versions in the template themselves. It might have to do with the combination of both, though. Anyway, I'm running Version 2016/01/07 [3.1.0] and (main) package versions are:

hyperref    2012/11/06 v6.83m
memoir.cls    2015/07/08 v3.7e
memhfixc.sty    2013/05/30 v1.17

I asked my friend's log file and his versions are:

hyperref    2012/11/06 v6.83m
memoir.cls    2015/04/23 v3.7d
memhfixc.sty    2013/05/30 v1.17

Which is not much of a difference. I'll try to get hold of that delta in the memoir class, but I'm afraid it will be inconclusive.

bcandeias commented 8 years ago

As Github so kindly informed, I included a workaround (fix) to this problem (commit 202abfb). I believe that between the configuration parameters/commands of hyperref and memoir (and the way these packages are loaded) there must be the key to solve this issue. However, an easier, less time-consuming fix is to use the subcaption package.

Ideally, we should import as few packages as possible. More packages mean more time to compile and more propensity to incompatibilities. But for now I think that is preferable to have everything working correctly.

carandraug commented 3 years ago

I'm having exactly the same issue on a paper I'm writing. Loading subcaption (which is not really necessary since memoir has the functionality needed) also fixed the problem. I will try to pursue this with upstream.

carandraug commented 3 years ago

I have reported it on https://tex.stackexchange.com/questions/578460/hyperref-links-to-first-subcaptionref-with-memoir

One way to workaround this without loading subcaption is to declare the subfigures after loading the hyperref package.