Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can I automatically position the details about a certain equation into an appendix?

I've attempted this answer with some success. However, I would like the numbers to work as clickable cross-references like when I use \ref{something} inside text with the hyperref package.

For instance:

        2x(3+3)=12             (1.1)
    details: see page (clickable)123

and in the appendix:

    details of equation (clickable)1.1:
         2x(3+3)
        =2x3+2x3
        =6+6
        =12
share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

This is quite similar to a writing questions and answers in separate places; I'm a huge fan of the answers package, which is what I've used in the solution below.

Stepping the counter is a little clumsy (perhaps someone will have suggestions for improvements), but I think it does what you want.

\documentclass{article}

\usepackage{lipsum}     % for sample text
\usepackage{amsmath}    % for mathematical environments
\usepackage{answers}    % for file writing
\usepackage{etoolbox}   % for \AtBeginEnvironment (and a lot more)
\usepackage{hyperref}   % for hyperlinks- load it last

% hyperlinks
\hypersetup{colorlinks=true,
linkcolor=blue}

% very useful during de-bugging!
%\usepackage[left]{showlabels}
%\showlabels{hypertarget}
%\showlabels{hyperlink}

% appendix file
\Opensolutionfile{appendixmaterial}
\Newassociation{appmat}{appMAT}{appendixmaterial}

% setup hypertargets for equations
\AtBeginEnvironment{equation}{%
\stepcounter{equation}%
\hypertarget{q:myref\theequation}{}%
\Writetofile{appendixmaterial}{\protect\hypertarget{a:myref\theequation}{}}%
\Writetofile{appendixmaterial}{\protect\label{a:myref\theequation}{}}%
\addtocounter{equation}{-1}%
}

% command to link to the appendix
\newcommand{\linktoappmat}{%
details of equation \hyperlink{a:myref\theequation}{\theequation} (see page \pageref{a:myref\theequation})}

\begin{document}

\lipsum[1]
\begin{equation}
    2\cdot (3+3)=12   
    \begin{appmat}
     \begin{align*}
     2\cdot (3+3)   & =2\cdot 3+2\cdot 3   \\
                    &=6+6       \\
                    & =12       \\
     \end{align*}
    \end{appmat}
\end{equation}
\linktoappmat
\begin{equation}
    2\cdot (5+5)=12   
    \begin{appmat}
     \begin{align*}
     2\cdot (5+5)   & =2\cdot 5+2\cdot 5   \\
                    &=10+10       \\
                    & =20       \\
     \end{align*}
    \end{appmat}
\end{equation}
\linktoappmat


% close solution file
\Closesolutionfile{appendixmaterial}

% renew the solution environment so that it hyperlinks back to 
% the question
\renewenvironment{appMAT}[1]{%
         % add some glue
         \vskip .5cm plus 2cm minus 0.1cm%
         {details of equation \bfseries \hyperlink{q:myref#1}{#1.}}%
}%
{%
}%

\clearpage
\section{Appendix}
% input the file if it exists
\IfFileExists{appendixmaterial.tex}{\input{appendixmaterial.tex}}{}
\end{document}

For another example of this kind of thing, have a look at Adding another answer hyperlinked to the question itself and the link within.

share|improve this answer
    
Thank you, it helped a a lot! Just one minor thing: is there a way to get the destination page of the hyperlink? In a document to be printed it should be: "Details: see page x(link)" –  Pedro May 24 '12 at 5:05
1  
@Pedro yes, for sure! I've updated the code –  cmhughes May 24 '12 at 15:42
add comment

Inspired on the above answer. I tweaked somethings like the stepping counter and added a conditional so in the appendix solutions are separated by chappter. It is not perfect but works as intended. Thank you @cmhughes.

    \documentclass{book}
    \usepackage{lipsum}     % for sample text
    \usepackage{amsmath}    % for mathematical environments
    \usepackage{answers}    % for file writing
    \usepackage{etoolbox}   % for \AtBeginEnvironment (and a lot more)
    \usepackage{hyperref}   % for hyperlinks- load it last
    \usepackage{ifthen} %for comparison

   % appendix file
   \Opensolutionfile{equation_details}
   \Writetofile{equation_details}{\protect\chapter{Equation details}}
   \Newassociation{eqdet}{eqDET}{equation_details}

   \newcommand{\details}{
   \raggedright{
        \scriptsize{
            \textbf{Details:} see \autopageref{details_:\theequation}\\
            \vskip .3cm
            }
        }
    }

    %raised target
    \makeatletter
     \newcommand{\nop}[1]{\Hy@raisedlink{\hypertarget{#1}{}}}
    \makeatother

    \newcounter{tempchap}
    \setcounter{tempchap}{0}

    % setup hypertargets for equations
    \AtBeginEnvironment{eqdet}{%
     \nop{equation_:\theequation}{}%
     \ifthenelse{\equal{\value{tempchap}}{\value{chapter}}}
     {}
     {\Writetofile{equation_details}{\protect\section*{\thechapter}}
     \setcounter{tempchap}{\value{chapter}}
     }
}


    % renew the solution environment so that it hyperlinks back to 
    % the question
    \renewenvironment{eqDET}[1]{%
                {\bfseries Equation \hyperlink{equation_:#1}{#1.}}
        \label{details_:#1}
        }
    {%
    }%

    \begin{document}

    \chapter{First Chapter}

    \lipsum[1]
    \begin{equation}
        2\cdot (3+3)=12
        \begin{eqdet}
            \begin{align*}
                2\cdot (3+3)   & =2\cdot 3+2\cdot 3\\
                    &=6+6\\
                    & =12\\
            \end{align*}
        \end{eqdet}   
    \end{equation}
    \details

    \lipsum[1]
    \begin{equation}
        3\cdot (4+4)=24
        \begin{eqdet}
            \begin{align*}
                3\cdot (4+4)   & =3\cdot 4+3\cdot4\\
                    &=12+12\\
                    & =24\\
            \end{align*}
        \end{eqdet}   
    \end{equation}
    \details


    \chapter{Second Chapter}

    \lipsum[1]
    \begin{equation}
        2\cdot (3+3)=12
        \begin{eqdet}
            \begin{align*}
                2\cdot (3+3)   & =2\cdot 3+2\cdot 3\\
                    &=6+6\\
                    & =12\\
            \end{align*}
        \end{eqdet}   
    \end{equation}
    \details

    \lipsum[1]
    \begin{equation}
        3\cdot (4+4)=24
        \begin{eqdet}
            \begin{align*}
                3\cdot (4+4)   & =3\cdot 4+3\cdot4\\
                    &=12+12\\
                    & =24\\
            \end{align*}
        \end{eqdet}   
    \end{equation}
    \details

    \Closesolutionfile{equation_details}

    \appendix

    % input the file if it exists
    \IfFileExists{equation_details.tex}{\input{equation_details.tex}}{}
    \end{document}
share|improve this answer
    
You're welcome :) if my answer did the job, please click on the green check mark so that this question is marked as, 'answered' –  cmhughes May 25 '12 at 2:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.