# XSIM and crossrefs

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.

1. How can I fix it ?
2. Would it be possible to have just one solution environment ? i.e. to delete solprob and just use sol in the sequel.

MWE

\documentclass[oneside]{scrbook}

\usepackage{xcolor,lipsum,hyperref}
\usepackage[blank,clear-aux]{xsim}

%
\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)}~}
}%
}%
{}%
}{}

\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 ,
}
\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 ,
}
%
\xsimsetup{
}

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


• You should be able to check for an existing solution in the template with \IfExistSolutionTF – cgnieder Jun 16 '20 at 11:24
• Thanks ! I'm going to try. – jowe_19 Jun 16 '20 at 12:00
• I have edited my question taking into account the first comment, but now an exercise having no solution is printed empty. – jowe_19 Jun 16 '20 at 12:56
• Your code compiles with errors. If I exchange remove the unnecessary \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 – cgnieder Jun 18 '20 at 11:26
• I have deleted all the auxiliary files and bodies of exercises/answers. The code compiles without errors, but the first exercise is still empty (whereas the body file is not ... ). Do you think that the code (updated) in the question is now correct? – jowe_19 Jun 19 '20 at 14:26

According to the comments of cgnieder, the following code does finally the trick.

\documentclass[oneside]{scrbook}

\usepackage{xcolor,lipsum,hyperref}
\usepackage[use-files,blank,clear-aux]{xsim}
%
%
\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{\big(Énoncé:\pageref{ex:\ExerciseID}\big)}~}%
}
{%
{\color{gray}\footnotesize{\big(Solution:\pageref{sol:\ExerciseID}\big)}~}
}%
}%
{}%
}{}

\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 ,
}
\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 ,
}
%
\xsimsetup{
}

\begin{document}

\chapter{First chapter}

\begin{exo}
ABCDE
\end{exo}

\begin{exo}
\lipsum[1]
\end{exo}
\begin{sol}
\lipsum[1]
\end{sol}

%
\begin{prob}
\lipsum[1]
\end{prob}
%
\begin{solprob}
\lipsum[1]
\end{solprob}

\printsolutions*

\end{document}