cgnieder / xsim

eXercise Sheets IMproved
69 stars 23 forks source link

Exercise name not capitalised with TeXLive 2024 #127

Closed ACCakut closed 3 months ago

ACCakut commented 4 months ago

Hello,

we use xsim to create our exercise sheets, and I played around with the settings in overleaf today. When switching TexLive from 2023 to 2024, I encountered a strange problem: The exercise name is small letters only. I tried several things using \XSIMmixedcase, but with no success.


\xsimsetup{
solution/template=boxed,
grading-table/template=default*,
exercise/name=Aufgabe, % results in aufgabe,   {AufGABE} also --> aufgabe
exercise/template=custom
}

\DeclareExerciseEnvironmentTemplate {custom}%
  {%
    \GetExerciseHeadingF { \subsection* }%
    {%
      \XSIMmixedcase { \GetExerciseName }\nobreakspace%
      \GetExerciseProperty {counter}%
      \IfInsideSolutionF%
        {%
          \IfExercisePropertySetT {subtitle}%
            { ~ { \normalfont \GetExerciseProperty {subtitle} } }%
        }%
    }%
    \GetExercisePropertyT {points}%
      {%
        %\marginpar%
         % {%
           % \IfInsideSolutionF { \rule {0.8cm} {1pt} \slash }%
            %\printgoal fonffonbfo {\PropertyValue}%
            %\GetExercisePropertyT {bonus-points}%
            %  { \nobreakspace ( + \printgoal {\PropertyValue} ) }%
            %\nobreakspace\XSIMtranslate {point-abbr}%
          %}%
      }%
  }%
  { \par }%
muzimuzhi commented 4 months ago

\XSIMmixedcase is a thin wrapper of expl3 function \text_titlecase:n, which has been deprecated since release 2023-10-23 of l3kernel.

https://github.com/cgnieder/xsim/blob/06e3dba43b96ed493968ddd54add9fc8a1d9a264/code/xsim.interface.code.tex#L330-L331

On its deprecation, the behavior is also slightly changed: now the title-casing is done on a per-word basis and the leading space is treated as an inter-word space, thus prohibits the title-casing of the word right after it.

In your example, the easiest change is to drop the space between { and \GetExerciseName:

-\XSIMmixedcase { \GetExerciseName }
+\XSIMmixedcase {\GetExerciseName}
\documentclass{article}
\usepackage{xsim}

\begin{document}

\def\mytext{text TEXT}

% results in "Text text" and "text text"
\XSIMmixedcase {\mytext} 
\XSIMmixedcase { \mytext}

\ExplSyntaxOn
% results in "Text text" and "text text"
\text_titlecase:n {\mytext} \space
\text_titlecase:n {~\mytext} \par
\ExplSyntaxOff

\end{document}
muzimuzhi commented 4 months ago

In your example, the easiest change is to drop the space between { and \GetExerciseName:

-\XSIMmixedcase { \GetExerciseName }
+\XSIMmixedcase {\GetExerciseName}

As \XSIMmixedcase never removed leading spaces from its argument, I think the no-space version is all-time preferable.

ACCakut commented 3 months ago

Thanks, that resolves my issue. I made a PR to fix this in the whole repo from where I took the code snippet some time ago.

Pull request: https://github.com/cgnieder/xsim/pull/128

muzimuzhi commented 3 months ago

I made a PR to fix this in the whole repo from where I took the code snippet some time ago.

Well those spaces in xsim source code are actually ignored.

All the xsim code are wrapped between expl3 commands \ExplSyntaxOn ... \ExplSyntaxOff, which employ a special catcode table in which space character is ignored, _ and : are characters, and ~ is the normal space. See the doc of \ExplSyntax(On|Off) in texdoc interface3, sec. 1.2 Documentation conventions.

ACCakut commented 3 months ago

I see, thanks for that insights, I was not aware of this. Nevertheless, there is this problem: If one copies code from .sty to alter the template (like I did and also did today for a grading table for collaborative exam correction), that "bug" emerges.

Is there a solution to that, except writing it in the RTFM boldly of repeating \ExplSyntaxOn ... \ExplSyntaxOff in every relevant snippet? I see that whitespace makes the code more readable, whereas in this case, I tend towards removing it for the mixed case thingies.

muzimuzhi commented 3 months ago

Is there a solution to that, except writing it in the RTFM boldly of repeating \ExplSyntaxOn ... \ExplSyntaxOff in every relevant snippet?

I'm afraid no. You always need to write something to set and restore the catcode of space.

muzimuzhi commented 3 months ago

All the xsim code are wrapped between expl3 commands \ExplSyntaxOn ... \ExplSyntaxOff, which employ a special catcode table ...

Note that package code is also auto-wrapped between \makeatletter ... \makeatother, which allows using @ in names of control sequences, like using letters (a-zA-Z). It happens that the piece of xsim code you copied didn't make use of this "feature", but theoretically ... .