GithubHelp home page GithubHelp logo

Comments (1)

muzimuzhi avatar muzimuzhi commented on June 12, 2024

With the default setting exercise/template=default, exercise title is typeset by \subsection*{<title>}, which takes care of vertical spacing between following list (like enumerate) automatically, through \@afterheading.

With exercise/template=centered, the same exercise title is now typeset manually, by \hfil\textbf{<title>}...\hfil\par\noindent. This time the vertical space \topsep inserted by a list environment (between it and the previous text) is not ignored automatically any more.

Implementations of exercise templates default and centered

xsim/code/xsim.sty

Lines 5509 to 5533 in 06e3dba

\DeclareExerciseEnvironmentTemplate {default}
{
\GetExerciseHeadingF { \subsection* }
{
\XSIMmixedcase { \GetExerciseName } \nobreakspace
\GetExerciseProperty {counter}
\IfInsideSolutionF
{
\IfExercisePropertySetT {subtitle}
{ ~ { \normalfont \itshape \GetExerciseProperty {subtitle} } }
}
}
\GetExercisePropertyT {points}
{
\marginpar
{
\IfInsideSolutionF { \rule {1.2cm} {1pt} \slash }
\printgoal {\PropertyValue}
\GetExercisePropertyT {bonus-points}
{ \nobreakspace ( + \printgoal {\PropertyValue} ) }
\nobreakspace\XSIMtranslate {point-abbr}
}
}
}
{ \par }

\DeclareExerciseEnvironmentTemplate{centered}
{%
\par\vspace{\baselineskip}
\Needspace*{2\baselineskip}
\noindent
\hfil\textbf{\XSIMmixedcase{\GetExerciseName}~\GetExerciseProperty{counter}}%
\GetExercisePropertyT{subtitle}{ \textit{#1}}\hfil
\par\noindent
\IfInsideSolutionF{%
\GetExercisePropertyT{points}{%
\marginpar{%
\printgoal{\PropertyValue}%
\GetExercisePropertyT{bonus-points}{+\printgoal{\PropertyValue}}%
\,\IfExerciseGoalSingularTF{points}
{\XSIMtranslate{point}}
{\XSIMtranslate{points}}%
}%
}%
}%
}
{}

Adding back \@afterheading (manually or by patching the centered template) solves the problem, partially. Note with exercise/template=centered, if exercise property points is given for an exercise starting with a list environment, the value of points will be typeset in its own paragraph, as a marginal note. You may need to manually adjust the vertical spacing.

\documentclass{article}
\usepackage{lipsum}

% to show distances between baseline heights
\usepackage{lineno}
\renewcommand{\thelinenumber}{\arabic{linenumber}\rlap{\rule{.4pt}{11pt}}}
\linenumbers

%\usepackage{cmbright}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage[clear-aux]{xsim}
\xsimsetup{
	load-style=layouts,
	exercise/template=centered,
}

\makeatletter
% cheat `xsim` as if `centered` template is undefined
\ExpandArgs{cc}\relax {cs_undefine:N} {l__xsim_template_begin_centered_setup_tl}
\ExpandArgs{cc}\relax {cs_undefine:N} {l__xsim_template_end_centered_setup_tl}

\DeclareExerciseEnvironmentTemplate{centered}
  {%
    \par\vspace{\baselineskip}
    \Needspace*{2\baselineskip}
    \noindent
    \hfil\textbf{\XSIMmixedcase{\GetExerciseName}~\GetExerciseProperty{counter}}%
    \GetExercisePropertyT{subtitle}{ \textit{#1}}\hfil
    \par\noindent\@afterheading % <<< changed
    \IfInsideSolutionF{%
      \GetExercisePropertyT{points}{%
          \marginpar{%
            \printgoal{\PropertyValue}%
            \GetExercisePropertyT{bonus-points}{+\printgoal{\PropertyValue}}%
            \,\IfExerciseGoalSingularTF{points}
                {\XSIMtranslate{point}}
                {\XSIMtranslate{points}}%
          }%
      }%
    }%
  }
  {}
\makeatother

\begin{document}
\begin{exercise}[subtitle={no points + plain text}]
  Normal distance between header and text!
\end{exercise}

\begin{exercise}[subtitle={no points + list}]
  \begin{enumerate}
  	\item Greater distance between header and text!
  \end{enumerate}
\end{exercise}

\begin{exercise}[points=2, subtitle={points + plain text}]
  Normal distance between header and text!
\end{exercise}

\begin{exercise}[points=3, subtitle={points + list}]
  \begin{enumerate}
  	\item Greater distance between header and text!
  \end{enumerate}
\end{exercise}

\begin{exercise}[points=4, subtitle={points + list + manual adjustment}]
  \vspace{-\baselineskip}
  \begin{enumerate}
  	\item Greater distance between header and text!
  \end{enumerate}
\end{exercise}

\section*{Emulation}
\subsection*{EnvironmentTemplate=default}
\lipsum[2][1]

\subsection*{EnvironmentTemplate=default}
\begin{enumerate}
  \item \lipsum[2][1]
\end{enumerate}

\hfil\textbf{EnvironmentTemplate=centered}\hfil \par
\lipsum[2][1]

\hfil\textbf{EnvironmentTemplate=centered}\hfil \par
\begin{enumerate}
  \item \lipsum[2][1]
\end{enumerate}

\hfil\textbf{EnvironmentTemplate=centered, patched}\hfil \par
\UseName{@afterheading}%
\begin{enumerate}
  \item \lipsum[2][1]
\end{enumerate}
\end{document}

image
image

from xsim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.