I looked at the template xsim_crossref.tex
(in the XSIM documentation) to create hyperlinks between statements and solutions.
It works fine but now I would like to hide the empty references (exercises with no solution). As suggested in the first comment, this can be done with the conditional test \IfExistSolutionTF
, but the first exercise with no solution is empty.
- How can I fix it ?
- Would it be possible to have just one solution environment ? i.e. to delete
solprob
and just usesol
in the sequel.
MWE
\documentclass[oneside]{scrbook}
\usepackage{xcolor,lipsum,hyperref}
\usepackage[blank,clear-aux]{xsim}
\DeclareExerciseHeadingTemplate{custom}{\XSIMtranslate{default-heading}}
%
\DeclareExerciseEnvironmentTemplate{custom}
{%
\IfExistSolutionTF
{%
\IfInsideSolutionTF
{%
\label{sol:\ExerciseID}}
{%
\label{ex:\ExerciseID}}
}{}%
\IfInsideSolutionTF
{%
{\color{green}\bfseries\XSIMmixedcase{\GetExerciseName}~(\GetExerciseParameter{exercise-name}%
~\GetExerciseProperty{counter})}%
}
{%
{\color{orange}\bfseries\XSIMmixedcase{\GetExerciseName}~\GetExerciseProperty{counter}}~{\color{black}\bfseries\itshape\GetExercisePropertyT{subtitle}{\PropertyValue}}%
}
\IfExistSolutionTF
{%
\IfInsideSolutionTF
{%
{\color{gray}\footnotesize{(Énoncé~:~\pageref{ex:\ExerciseID})}~}%
}
{%
{\color{gray}\footnotesize{\big(\XSIMmixedcase{\GetExerciseParameter{solution-name}}~:~\pageref{sol:\ExerciseID}\big)}~}
}%
}%
{}%
}{}
% Traductions
\DeclareExerciseTranslations{problem}{
Fallback = problème ,
English = problem ,
French = problème ,
}
\DeclareExerciseTranslations{problems}{
Fallback = problèmes ,
English = problems ,
French = problèmes ,
}
\DeclareExerciseType{exercice}{
exercise-env = exo ,
solution-env = sol ,
exercise-name = \XSIMtranslate{exercise} ,
exercises-name = \XSIMtranslate{exercises} ,
solution-name = \XSIMtranslate{solution} ,
solutions-name = \XSIMtranslate{solutions} ,
exercise-template = custom ,
solution-template = custom ,
exercise-heading = custom ,
solution-heading = custom
}
\DeclareExerciseType{probleme}{
exercise-env = prob ,
solution-env = solprob ,
exercise-name = \XSIMtranslate{problem} ,
exercises-name = \XSIMtranslate{problems} ,
solution-name = \XSIMtranslate{solution} ,
solutions-name = \XSIMtranslate{solutions} ,
exercise-template = custom ,
solution-template = custom ,
exercise-heading = custom ,
solution-heading = custom
}
%
\xsimsetup{
print-solutions/headings-template = custom ,
print-solutions/headings = false ,
}
\begin{document}
\chapter{First chapter}
\begin{exo}
ABCDE
\end{exo}
\begin{exo}
\lipsum[1]
\end{exo}
\begin{sol}
\lipsum[1]
\end{sol}
%
\begin{prob}[subtitle={A problem but "solprob" instead of "sol" is mandatory}]
\lipsum[1]
\end{prob}
%
\begin{solprob}
\lipsum[1]
\end{solprob}
\printsolutions*
\end{document}
\IfExistSolutionTF
\XSIMmixedcase
from\XSIMmixedcase{Énoncé}
, i.e. only useÉnoncé
and add the missing third argument to\DeclareExerciseEnvironmentTemplate
then the code compiles without errors and the first exercise is not empty