summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/xsim/doc/examples/xsim.floating.tex
blob: 08448df35a686479a831485f9c1b0003fcc22719 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
% floating exercises:
\documentclass{article}
\usepackage{xsim,newfloat,caption,lipsum}

\DeclareFloatingEnvironment[
  fileext=loe,
  listname={List of Exercises},
  name=Exercise,
  placement=htp,
]{ex}

\DeclareExerciseEnvironmentTemplate{float}
  {%
    \ex
    \captionsetup{labelformat=empty,singlelinecheck=false,listformat=empty}
    \IfExercisePropertySetTF{subtitle}{%
      \XSIMexpandcode{%
        \noexpand\caption{%
          \noexpand\textbf{%
            \XSIMmixedcase{\GetExerciseName}\nobreakspace
            \GetExerciseProperty{counter}%
          }: \GetExerciseProperty{subtitle}%
        }%
      }%
    }{%
      \caption{%
        \textbf{%
          \XSIMmixedcase{\GetExerciseName}\nobreakspace
          \GetExerciseProperty{counter}%
        }%
      }%
    }%
  }
  {\endex}

\xsimsetup{exercise/template = float}

\begin{document}

\listofexs

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

\begin{exercise}[subtitle=Let's have a look]
  \lipsum[4]
\end{exercise}

\end{document}