1

How can I modify the runin template of the exercise/solution environment of xsim package to ignore an empty line at the beginning of the environment in the source code?

Thanks

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{lipsum}

\usepackage{xsim}

% template taken from xsim manual
% https://ctan.math.illinois.edu/macros/latex/contrib/xsim/xsim-manual.pdf
\usepackage{needspace}
\DeclareExerciseEnvironmentTemplate{runin}
{%
\par\vspace{\baselineskip}
\Needspace*{2\baselineskip}
\noindent
\textbf{\XSIMmixedcase{\GetExerciseName}~\GetExerciseProperty{counter}}%
\GetExercisePropertyT{subtitle}{ \textit{#1}} % <<< notice the space
\IfInsideSolutionF{%
\GetExercisePropertyT{points}{%
\marginpar{%
\printgoal{\PropertyValue}%
\GetExercisePropertyT{bonus-points}{+\printgoal{\PropertyValue}}%
\,\IfExerciseGoalSingularTF{points}
{\XSIMtranslate{point}}
{\XSIMtranslate{points}}%
}%
}%
}%
}
{}

\xsimsetup{%
    exercise/template = runin,
    solution/print = true
}

\begin{document}

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

\begin{exercise}

    \lipsum[1]
\end{exercise}

\vspace{2cm}

I would like the text of exercise 2 to start on the same line as ``Exercise 2'' (looking like Exercise 1) despite the presence of an empty line at the beginning of the environment.

\end{document}

1 Answer 1

1

You could define it using \paragraph*:

\documentclass{article}
\usepackage{xsim}

\DeclareExerciseEnvironmentTemplate{runin}{%
  \paragraph*{%
    \XSIMmixedcase{\GetExerciseName}~\GetExerciseProperty{counter}%
    \normalfont
    \GetExercisePropertyT{subtitle}{ \textit{\PropertyValue}}%
  }%
  \IfInsideSolutionF{%
    \GetExercisePropertyT{points}{%
      \marginpar{%
        \printgoal{\PropertyValue}%
        \GetExercisePropertyT{bonus-points}{+\printgoal{\PropertyValue}}%
        \,\IfExerciseGoalSingularTF{points}
          {\XSIMtranslate{point}}
          {\XSIMtranslate{points}}%
      }%
    }%
  }%
}{\par\addvspace{\baselineskip}}

\xsimsetup{
  exercise/template = runin,
  solution/print = true
}

\usepackage{lipsum}

\begin{document}

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

\begin{exercise}

  \lipsum[1]
\end{exercise}

I would like the text of exercise 2 to start on the same line as
``Exercise~2'' (looking like Exercise~1) despite the presence of an empty line
at the beginning of the environment.

\end{document}

It might be easier to just change the heading command of the default template, though:

\documentclass{article}
\usepackage{xsim}

\xsimsetup{
  exercise/heading = \paragraph* ,
  exercise/post-hook = \addvspace{\baselineskip} ,
  solution/print = true
}

\usepackage{lipsum}

\begin{document}

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

\begin{exercise}

  \lipsum[1]
\end{exercise}

I would like the text of exercise 2 to start on the same line as
``Exercise~2'' (looking like Exercise~1) despite the presence of an empty line
at the beginning of the environment.

\end{document}

Both examples give:

enter image description here

1
  • Thanks! I appreciate it.
    – Marca85
    Mar 9, 2022 at 9:11

You must log in to answer this question.

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