8

I started to write a clickable problem book using fortextbook. The question: after compiling to PDF, and setting the page fit to width in the Acrobat Reader if I click on e.g. question 1. it jumps to solution 2., or click to the square next to solution 1. jumps to question 2.

The code:

\documentclass{article}
\usepackage{amsmath}

\usepackage[latextoc,dvips,pdflatex]{web}  % dvipsone, dvips, pdftex, dvipdfm

\usepackage[links,pdftex,fortextbook,nomarginwrite,usecustomdesign,
ftbsolns, forcolorpaper,noseparationrule,usexkv]{eqexam}

\begin{document}

\begin{probset}
{{\thesection} Solutions}%\label{probGrpANS}

\begin{problem}[7]
Solve the equation $ x^2 - 3x + 1 = 0 $ using the \emph{method of
completing the square}. \ANS{$x=\frac{3}{2}-\frac{\sqrt5}{2}$,
            $\frac{3}{2}+\frac{\sqrt5}{2}$}
\begin{solution}[]
\begin{ssol}
$ x = \frac{3}{2}-\frac{\sqrt5}{2},                \frac{3}{2}+\frac{\sqrt5}{2}$
\end{ssol}
\begin{lsol}
We use standard methods.
\begin{align*}
    x^2 - 3x + 1 &= 0 \\
    x^2 - 3x &= -1\\
    x^2 - 3x + \frac{9}{4} &= -1 + \frac{9}{4}\\
    ( x - \frac{3}{2} )^2 &= \frac{5}{4}\\
            x - \frac{3}{2} &= \pm\frac{\sqrt5}{2}\\
            x &= \frac{3}{2} \pm\frac{\sqrt5}{2}
            \qquad\makebox[0pt][l]{\text{The solutions are $\boxed{ x = \frac{3}{2}-\frac{\sqrt5}{2},                \frac{3}{2}+\frac{\sqrt5}{2}}$}}
\end{align*}
\end{lsol}
\end{solution}
\end{problem}

\begin{problem}
Solve the equation $ x^2 - 4x + 8 = 0 $ using the \emph{quadratic formula}.
Simplify your final answer. \ANS{$x=2\pm2\imath$}
\begin{solution}[]
\begin{ssol}
$x=2\pm2\imath$
\end{ssol}
\begin{lsol}
We apply the quadratic formula:
\begin{align*}
    x &= \frac{4\pm\sqrt{16-4(1)(8)}}{2}\\
      &= \frac{4\pm\sqrt{16-32}}{2}\\
      &= \frac{4\pm\sqrt{-16}}{2}\\
      &= \frac{4\pm 4\imath}{2}\\
      &= 2\pm2\imath
\end{align*}
The solutions are $ \boxed{ x = 2-2\imath,\ 2+2\imath }$.
\end{lsol}
\end{solution}
\end{problem}

\end{probset}

\newpage

\includeexersolutions

\end{document}
Troy
  • 13,741

1 Answers1

4

The problem relies on the use of \hypertarget and \hyperlink from the hyperref package used in the background (the eqexam package, http://ftp.cstug.cz/pub/tex/CTAN/macros/latex/contrib/eqexam.zip).

The reason seems to be that its anchor is set to the baseline of the box (#2) not to the left upper corner of the box. I enclose a patch where you can in addition of regular raise by the height of the box choose left-right and up-down shifts. The redefinition of the \hypertarget command uses the \raisebox and \kern commands.

With your permission, I have also fixed that \sectioning problem inside the probset environment. I have added \noexpand and it seems it is working as it should be. I enclose an example how to use this patch and a preview of those two pages. Good luck with your project!

%! {pdf|lua}latex clickable-book.tex
\documentclass{article}
\usepackage{amsmath}
\usepackage[latextoc, pdftex]{web}% dvipsone, dvips, pdftex, dvipdfm [latextoc, dvips, pdftex]
\usepackage[links, fortextbook, %pdftex,
   nomarginwrite, usecustomdesign, ftbsolns, forcolorpaper, noseparationrule, usexkv,
  ]{eqexam}
\textbookOpts{instred,lsols}

% The patch...
\newbox\malbox
\let\malhypertarget=\hypertarget
\newdimen\malreserve \malreserve=8mm% Reserve for moving left and right...
\newdimen\malreserveup \malreserveup=0.5\baselineskip% Reserve for moving up and down...
\def\hypertarget#1#2{% 
  \setbox\malbox=\hbox{#2}% What am I dealing with?
  \advance\malreserveup by \ht\malbox% Reserve plus the height of the box...
  \raisebox{\malreserveup}[0pt][0pt]{% Moving target up....
  \kern-\malreserve\relax% Moving it left...
  \malhypertarget{#1}{% The real \hypertarget is applied.
  \raisebox{-\malreserveup}[0pt][0pt]{\kern\malreserve#2}% Moving it down and right...
  }% End of \malhypertarget...
 }% End of \raisebox...
}% End of new \hypertarget...

\begin{document}
\section{My set of problems}

\begin{probset}
{\noexpand\section{My set of solutions}\noexpand\label{probGrpANS}}

\begin{problem}[7]\strut
Solve the equation $ x^2 - 3x + 1 = 0 $ using the \emph{method of
completing the square}. 
\ANS{\strut$x=\frac{3}{2}-\frac{\sqrt5}{2}$,
            $\frac{3}{2}+\frac{\sqrt5}{2}$}
\begin{solution}[]
\begin{ssol}
$ x = \frac{3}{2}-\frac{\sqrt5}{2},\
            \frac{3}{2}+\frac{\sqrt5}{2}$
\end{ssol}
\begin{lsol}
We use standard methods.
\begin{align*}
    x^2 - 3x + 1 &= 0 \\
    x^2 - 3x &= -1\\
    x^2 - 3x + \frac{9}{4} &= -1 + \frac{9}{4}\\
    \left( x - \frac{3}{2} \right)^2 &= \frac{5}{4}\\
            x - \frac{3}{2} &= \pm\frac{\sqrt5}{2}\\
            x &= \frac{3}{2} \pm\frac{\sqrt5}{2}
            %\qquad\makebox[0pt][l]{\text{The solutions are $\boxed{ x = \frac{3}{2}-\frac{\sqrt5}{2},\ \frac{3}{2}+\frac{\sqrt5}{2}}$}}
\end{align*}
% I would prefer that part typeset over here...
The solutions are $\boxed{ x = \frac{3}{2}-\frac{\sqrt5}{2},\ \frac{3}{2}+\frac{\sqrt5}{2}}$
  \bigskip% Manual intervention between solutions...
\end{lsol}
\end{solution}
\end{problem}

\begin{problem}\strut
Solve the equation $ x^2 - 4x + 8 = 0 $ using the \emph{quadratic formula}.
Simplify your final answer. 
   \ANS{\strut$x=2\pm2\imath$}
\begin{solution}[]
\begin{ssol}
$x=2\pm2\imath$
\end{ssol}
\begin{lsol}
We apply the quadratic formula:
\begin{align*}
    x &= \frac{4\pm\sqrt{16-4(1)(8)}}{2}\\
      &= \frac{4\pm\sqrt{16-32}}{2}\\
      &= \frac{4\pm\sqrt{-16}}{2}\\
      &= \frac{4\pm 4\imath}{2}\\
      &= 2\pm2\imath
\end{align*}
The solutions are $ \boxed{ x = 2-2\imath,\ 2+2\imath }$.
\end{lsol}
\end{solution}
\end{problem}
\end{probset}

% There has been no need for this part...
%\newpage
%\includeexersolutions% or
%\input\jobname.sol
\end{document}

mwe

Malipivo
  • 13,287