4

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
Pedro
  • 267

2 Answers2

4

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.

David Carlisle
  • 757,742
cmhughes
  • 100,947
  • 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 05:05
  • 1
    @Pedro yes, for sure! I've updated the code – cmhughes May 24 '12 at 15:42
0

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}
David Carlisle
  • 757,742
Pedro
  • 267
  • 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 02:41