自动将方程式的详细信息放入附录中

自动将方程式的详细信息放入附录中

我如何才能自动将有关某个方程的详细信息放入附录中?

我尝试过回答取得了一些成功。但是,我希望这些数字可以作为可点击的交叉引用,就像我\ref{something}在包中使用内部文本时一样hyperref

例如:

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

附录中:

    details of equation (clickable)1.1:
         2x(3+3)
        =2x3+2x3
        =6+6
        =12

答案1

这和在不同的地方写问题和答案非常相似;我非常喜欢answers包,这是我在下面的解决方案中所使用的。

步进计数器有点笨拙(也许有人会有改进的建议),但我认为它能满足你的要求。

\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}

有关此类事情的另一个例子,请查看添加另一个与问题本身超链接的答案以及其中的链接。

答案2

受到上述答案的启发。我调整了步进计数器等一些东西,并添加了一个条件,因此附录中的解决方案按章节分开。它并不完美,但可以按预期工作。谢谢@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}

相关内容