TransWikia.com

Exercise package and hyperlink exercise/solution : hide the empty solutions?

TeX - LaTeX Asked by jowe_19 on January 10, 2021

I’m using the exercise package in order to manage exercises together with answers. In the following MWE, an hyperlink pointing to the associated answer is created at the beginning of each of them. If there is no solution, would it be possible to delete the previous hyperlink ? (see below exercise 2 for an example).

documentclass[11pt]{article}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{lmodern}
usepackage{hyperref}
hypersetup{breaklinks = true,
            unicode    = true,
            colorlinks = true,
            urlcolor   = red,
            linkcolor  = red}
usepackage[lastexercise]{exercise}
%
renewcommand{ExerciseName}{Exercice}
renewcommand{ExerciseHeader}{%
    noindent
    textbf{
       ExerciseNamequadExerciseHeaderNBtextit{ExerciseHeaderTitle}quad}%
    }
%Environnement exercice
newenvironment{exo}[1][unskip]{%
begin{Exercise}[title={#1},label={thevalue{Exercise}}]
hfill texttt{refAnswer{ExerciseLabel}}


}{end{Exercise}}

newenvironment{sol}
{begin{Answer}[ref=ExerciseLabel]
}
{end{Answer}
}
%%%%%%%%%%%%
begin{document}

begin{exo}
A
end{exo}

begin{sol}
ABCDE
end{sol}

begin{exo}
A
end{exo}

shipoutAnswer
end{document}

enter image description here

One Answer

Your environment exo includes a hyperlink. If you don't mind using a new environment, just define a new environment without the hyperlink

newenvironment{nhexo}[1][unskip]{%
    begin{Exercise}[title={#1},label={thevalue{Exercise}}]


    }{end{Exercise}}

Edited MWE:

documentclass[11pt]{article}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{lmodern}
usepackage{hyperref}
hypersetup{breaklinks = true,
            unicode    = true,
            colorlinks = true,
            urlcolor   = red,
            linkcolor  = red}
usepackage[lastexercise]{exercise}
%
renewcommand{ExerciseName}{Exercice}
renewcommand{ExerciseHeader}{%
    noindent
    textbf{
       ExerciseNamequadExerciseHeaderNBtextit{ExerciseHeaderTitle}quad}%
    }
%Environment exercise
newenvironment{exo}[1][unskip]{%
begin{Exercise}[title={#1},label={thevalue{Exercise}}]
hfill texttt{refAnswer{ExerciseLabel}}


}{end{Exercise}}

newenvironment{nhexo}[1][unskip]{%
    begin{Exercise}[title={#1},label={thevalue{Exercise}}]


    }{end{Exercise}}

newenvironment{sol}
{begin{Answer}[ref=ExerciseLabel]
}
{end{Answer}
}
%%%%%%%%%%%%
begin{document}

begin{exo}
A
end{exo}

begin{sol}
ABCDE
end{sol}

begin{nhexo}
A
end{nhexo}

shipoutAnswer
end{document}

enter image description here

Answered by user193767 on January 10, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP