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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Now, if anyone could change the title into something better that would be great =)

I am writing a rather long document, which contains plenty of integrals. I have a big list of integrals sorted in a three column style, as pictured below

enter image description here

The image is a tad old. Now, I want to link both the soutions and the answers to each question using hyperref. (Where the answer means just the antiderivate, and the solution means all the small steps to compute the integral) My problem is that I do not know what the best way to do this is. Right now, I have turned every integral into a hyperlink, as the MWE shows.


\newcommand{\dx}{\mathop{}\! \text{d} x}
\newcommand{\R}{ \mathbb{R} }


    colorlinks=true,        %  false: boxed links; true: colored links
    linkcolor=black,        %  color of internal links
    citecolor=cyan,         %  color of links to bibliography
    filecolor=magenta,      %  color of file links
    urlcolor=cyan           %  color of external links
\newcommand{\IntExerc}[2]{\item \hyperref[#1]{\mbox{ \( \displaystyle #2 \) }}}


\subsection{Huge ass list of problems}

\IntExerc{R1.1}{\int \frac{x^2+3x}{x^2} \dx }
\IntExerc{R1.2}{\int_0^1 \frac{x}{x^2+1} \dx}
\IntExerc{R1.3}{\int \frac{x}{x+1} \dx}
\IntExerc{R1.4}{\int_{-3}^{3} \frac{1}{1-x} \dx}
\IntExerc{R1.5}{\int \sqrt{4-x} \dx}
\IntExerc{R1.6}{\int_{0}^{1/2} \left( 2x - 1\right)^{50} \dx}
\IntExerc{R1.7}{\int \sqrt[n]{x} \dx}
\IntExerc{R1.8}{\int \frac{1}{x \ln x} \dx}
\IntExerc{R1.7}{\int \sin x \cos x \dx}
\IntExerc{R1.8}{\int_{1}^{\sqrt{e-1}} \ln\left( 1 + x^2 \right)x\dx}
\IntExerc{R1.9}{\int \frac{x}{e^x} \dx}
\IntExerc{R1.10}{\int \sin x \cos x \dx}
\IntExerc{R1.11}{\int_1^{e^n} \ln x \dx \ n \in \R}
\IntExerc{R1.12}{\int x \cdot a^x \dx}
\IntExerc{R1.13}{\int \log_{10} (x) \dx}
\IntExerc{R1.14}{\int_{\pi/6}^{\pi/3} \sin(x)^2 \dx}
\IntExerc{R1.15}{\int_1^e \int \frac{\pi}{-x^2} \dx \dx}
\IntExerc{R1.16}{\int_{0}^{\ln 2} x\ln(x+1) \dx}
\IntExerc{R1.17}{\int \frac{x e^x}{(x+1)^2} \dx}
\IntExerc{R1.18}{\int \frac{1}{1+\sqrt{x}}\dx}
\IntExerc{R1.19}{\int \frac{\ln x}{\sqrt{x}} \dx}
\IntExerc{R1.20}{\int_{\pi}^{\pi} \frac{\sin(1/x)e^{x^2}}{\sqrt{x!}} \dx}
\IntExerc{R1.21}{\int \frac{x-1}{\sqrt{x^2 + 2x + 7}} \dx}
\IntExerc{R1.22}{\int \frac{1 + e^x}{\sqrt{e^x + x}} \dx}
\IntExerc{R1.23}{\int \frac{e^x + 1}{e^x - 1} \dx}
\IntExerc{R1.24}{\int_{a}^{a+2\pi} \sin x+1 \dx}
\IntExerc{R1.25}{\int \frac{x^2 + 2x + 2}{x-1} \dx}
\IntExerc{R1.26}{\int_{0}^1 e^{-y^2}  \dx}
\IntExerc{R1.30}{\int_{-3/4}^{4} \frac{x+1}{(x+2)^4}\dx}
\IntExerc{R1.27}{\int x^3\sqrt{1-x^2} \dx}
\IntExerc{R1.40}{\int \ln\left(\frac{1}{\sqrt{x}}\right) \dx}
\IntExerc{R1.28}{\int \sin(2x)e^{\sin(x)^2} \dx}
\IntExerc{R1.29}{\int x \ln \left( \frac{1}{x}\right) \dx}
\IntExerc{R1.30}{\int 2^x e^x \dx}
\IntExerc{R1.30}{\int \binom{x+1}{x} \dx}
\IntExerc{R1.31}{\int \frac{1}{\sqrt{x}\left( 1 + \sqrt{x}\right)} \dx}
\IntExerc{R1.32}{\int_{1}^{\log_e(a)^2} e^{\sqrt{x}}\dx}
\IntExerc{R1.33}{\int \frac{x^2}{x^2 - 1} \dx}
\IntExerc{R1.34}{\int \frac{x}{1 - x^2 + \sqrt{1 - x^2}} \dx}
\IntExerc{R1.34}{\int_{1}^{\sqrt{e-1}} \ln\left( 1 + x^2 \right)x\dx}
\IntExerc{R1.36}{\int \frac{x^2}{x^2 + 4x + 8}\dx}
\IntExerc{R1.37}{\int \frac{1}{x \ln(x)^n} \dx}
\IntExerc{R1.38}{\int_{0}^{\infty} x^3 e^{-x}  \dx}
\IntExerc{R1.39}{\int e^{x + e^x} \dx}
\IntExerc{R1.40}{\int \ln(x)^3 \dx}
\IntExerc{R1.41}{\int \frac{x e^x}{\left( x + 1\right)^2}\dx}
\IntExerc{R1.42}{\int_n^m (m-x)(x-n)\dx}
\IntExerc{R1.41}{\int \frac{\pi}{\sqrt{e^2-16}}\dx}
\IntExerc{R1.40}{\int \frac{\sin(2x)}{\sin x} \dx}
\IntExerc{R1.40}{\int_0^{\pi/3n} \tan(nx) \dx}
\IntExerc{R1.40}{\int \frac{4a}{x^2-a^2} \dx}
\IntExerc{R1.40}{\int e^{\sin(x)^2}e^{\cos(x)^2}  \dx}
\IntExerc{R1.40}{\int \frac{e^{\ln\left(x^2 + 1 \right)}}{x+1} \dx}
\IntExerc{R1.40}{\int_{\pi/6}^{\pi/2} \frac{1}{\tan x} \dx}
\IntExerc{R1.40}{\int \frac{x^2+1}{x(x^2+3)} \dx}
\IntExerc{R1.40}{\int \frac{1}{\sqrt[3]{x} + x} \dx}
\IntExerc{R1.40}{\int \frac{1}{x \ln x - x} \dx}
\IntExerc{R1.40}{\int_{0}^{\pi} \frac{x^2 \sin(x)}{\pi - 2} \dx}
\IntExerc{R1.40}{\int \sqrt{\sqrt{x} + \sqrt{x}\,} \dx}
\IntExerc{R1.40}{\int 2^{\ln x} \dx}
\IntExerc{R1.40}{\int_{2}^{5} \frac{2 - 4}{x^4 - x^2} \dx}
\IntExerc{R1.40}{\int \cos( \sin(x) ) \cos x \dx}
\IntExerc{R1.40}{\int \left(x + x^2\right)e^{3(x+\ln 3)} \dx}
\IntExerc{R1.40}{\int \cos(x)\sin(2x) \dx}
\IntExerc{R1.40}{\int \frac{1}{2x \sqrt{\ln x}} \dx}
\IntExerc{R1.40}{\int \frac{\log_5(x)}{\log_{25}(x)} \dx}

\subsubsection{Word problems}

$$ \int_{1/2}^{\sqrt{3}/2} \frac{x^3}{\left( \frac{5}{8} - x^4\right)\sqrt{\frac{5}{8} - x^4}}\quad $$



\int \frac{x^2+3x}{x^2} \dx & = \int \frac{x^2}{x^2} + \frac{3x}{x^2} \dx = \int 1 \dx + 3\int \frac{dx}{x} = x + 3 \ln|x| + \CC  \label{R1.1}\\
\int\sin(x)\,\mathrm{d}x & = -\cos(x) + C \label{R1.22} \\
\int\sin(x)\,\mathrm{d}x & = -\cos(x) + C \label{R1.40}

First straight integration problems, then word problems


Question(s): What is the best way to separate the plain answer, from the solution? (Are any of the ideas below good?)

  • Can one perhaps add a spoiler tag (Opens on click)?
  • Make the numbers into separate links?
  • Add seperate links next to each integral? (I think this would make it very cluttered)

Oh, and is there any way to make the hyperref go both ways? That I could click on the answer, and get back to the questions?

Cheers, thanks in advance for any suggestions, answers or comments =)

share|improve this question
up vote 7 down vote accepted

All of this can be achieved using the answers and hyperref package.

In the MWE below, I've linked the question number to the solution, and the solution number back to the question by using the hypertarget and hyperlink mechanism from the hyperref package.

The example I have shown is very simple, but you can get pretty sophisticated with it as I've shown in my answer to

Contest: Show Off Your Skillz in TeX & Friends [TeX.sx birthday]

The main thing to note is that I have renewenvironment for the solution file immediately before I have inputted it- you have to wait until this point to avoid messing up the process of writing to a file.






% very useful during de-bugging!

% solutions file

% new environment that sets up hypertargets both in the question
% section, and in the answer section
    %  hyperlink to solution



% close solution file

% renew the solution environment so that it hyperlinks back to 
% the question
         % add some glue
         \vskip .5cm plus 2cm minus 0.1cm%
         {\bfseries \hyperlink{question:#1}{#1.}}%

% input the file if it exists
share|improve this answer
I kind of like the idea of using the answer package, but I am feeling I need something a bit more specialized. But you are giving me some good ideas. Would the answer package be compatible with the multicolumn package? – N3buchadnezzar Feb 22 '12 at 17:58
@N3buchadnezzar yes, absolutely! the answer package works environment by environment- you can put the question environment into multicols easily – cmhughes Feb 22 '12 at 18:33
@N3buchadnezzar see my edit – cmhughes Feb 22 '12 at 18:53
cmhughes - I will do some work and get back to this ok? =) It is near what I am looking for, all I need is to put the code into a own command. (I seem to always have problems with enviroments inside commands) and see if I can figure out how to add two answers to each question =) – N3buchadnezzar Feb 22 '12 at 19:13
@N3buchadnezzar You can add two answers to each question using a newassociation. I've tried using a command approach before, but things work out much more easily using an environment – cmhughes Feb 22 '12 at 19:39

You can define a new environment to write the answer verbatim into a seperate file, and then you can \input the answer file when necessary.

Here is a private package for my own book:

\ProvidesPackage{latexexercise}[2011/08/03 by Leo]






    {\PackageInfo{latexexercise}{answer file `\ltxex@ansfilename' inputed.}}%
      {answer file `\ltxex@ansfilename' does not exsist.}}}


\def\ltxex@pre{\item[]\hskip-\labelsep {\large\bfseries \exercisename}}

  \def\makelabel##1{\ltxex@anslabelstyle ##1}

  \let\do\@makeother \dospecials



Test code:




\item $1+1=?$

\item $2\times 2 = ?$
That's 4.


\item Foo


share|improve this answer
Well, for updated question, this solution is not suitable. I leave it for reference. It is not difficult to add hyperlink, but I've no much time. – Leo Liu Feb 22 '12 at 16:49

Your Answer


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.