3

The exsheets package allowed for referencing a previous exercise through its ID tag with \exerciseNumber{<id>}. Changing to XSIM now, I could not find an equivalent. The \GetExerciseProperty{ID} provides the ID of the current exercise (manual v0.11, p. 31), but I could not find a way to access the number of a previous question in XSIM using its ID (or id; manual p. 10).

I could provide a separate \label{} in one question and refer to it with \ref{} later. But I would prefer to directly access the ID tag.

Background: I have a collection of ~300 exercises built with exsheets and heavy cross-referencing. Now I want to convert it to xsim without having to manually add labels and refs.

1 Answer 1

2

There is no such command at the moment but it is possible to define one:

\documentclass{article}
\usepackage{xsim,lipsum}

\ExplSyntaxOn
\NewDocumentCommand \exercisenumber {m}
  {
    \xsim_get_property:nxn
      {exercise}
      { \xsim_get_id_for_property:nn {ID} {#1} }
      {counter}
  }
\cs_generate_variant:Nn \xsim_get_property:nnn {nx}  
\ExplSyntaxOff

\begin{document}

\begin{exercise}
  \lipsum[1]
\end{exercise}

\begin{exercise}[ID=foo]
  \lipsum[1]
\end{exercise}

\begin{exercise}
  See exercise \exercisenumber{foo}. \lipsum[1]
\end{exercise}

\end{document}

enter image description here

1
  • Thanks, Clemens, does exactly what I needed! Great! Commented Oct 2, 2019 at 17:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .