XSIM 和 crossrefs

XSIM 和 crossrefs

我查看了模板xsim_crossref.tex(在 XSIM 文档中)以在语句和解决方案之间创建超链接。

它运行正常,但现在我想隐藏空引用(没有解决方案的练习)。正如第一条评论中所建议的,这可以通过条件测试来完成\IfExistSolutionTF,但第一个没有解决方案的练习是空的。

  1. 我该如何修复它?
  2. 是否有可能只有一个解决方案环境?IE删除solprob并仅sol在后续中使用。

平均能量损失

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

在此处输入图片描述

答案1

根据 cgnieder 的评论,下面的代码最终达到了目的。

\documentclass[oneside]{scrbook}

\usepackage{xcolor,lipsum,hyperref}
\usepackage[use-files,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{\big(Énoncé:\pageref{ex:\ExerciseID}\big)}~}%
             }
             {%
             {\color{gray}\footnotesize{\big(Solution:\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}
\lipsum[1]  
\end{prob}
%
\begin{solprob}
\lipsum[1]  
\end{solprob}


\printsolutions*

\end{document}

相关内容