From 7b19cae701283a0c7c6cb760c3b28ba912abdaea Mon Sep 17 00:00:00 2001
From: Norbert Preining <norbert@preining.info>
Date: Sun, 16 Feb 2020 03:18:07 +0000
Subject: CTAN sync 202002160318

---
 macros/latex/contrib/sdaps/sdapsclassic.dtx | 122 +++++++++++++++++++++-------
 1 file changed, 91 insertions(+), 31 deletions(-)

(limited to 'macros/latex/contrib/sdaps/sdapsclassic.dtx')

diff --git a/macros/latex/contrib/sdaps/sdapsclassic.dtx b/macros/latex/contrib/sdaps/sdapsclassic.dtx
index d2f4002800..7694aa12ee 100644
--- a/macros/latex/contrib/sdaps/sdapsclassic.dtx
+++ b/macros/latex/contrib/sdaps/sdapsclassic.dtx
@@ -1,14 +1,12 @@
 % \iffalse meta-comment
 %
-% Copyright (C) 2015 by Benjamin Berg <benjamin@sipsolutions.net>
+% Copyright (C) 2019 by Benjamin Berg <benjamin@sipsolutions.net>
 %
 % This work may be distributed and/or modified under the
-% conditions of the LaTeX Project Public License, either version 1.3
+% conditions of the LaTeX Project Public License, either version 1.3c
 % of this license or (at your option) any later version.
 % The latest version of this license is in
 %   http://www.latex-project.org/lppl.txt
-% and version 1.3 or later is part of all distributions of LaTeX
-% version 2005/12/01 or later.
 %
 % This work has the LPPL maintenance status `maintained'.
 % 
@@ -290,7 +288,7 @@
 %\setlength{\parskip}{0pt}
 \setlength\columnsep{10\p@}
 \setlength\columnseprule{0\p@}
-% Redefine the spacings for \subsection ie. \questions.
+% Redefine the spacings for \subsection ie. \_sdaps_classic_question.
 \renewcommand\section{\@startsection {section}{1}{\z@}%
       {-\parskip}%
       {\parskip}%
@@ -341,7 +339,7 @@
 
 \newcommand\qid{\tl_use:N \g__sdaps_questionnaire_id_tl}
 
-\def\question#1{%
+\def\_sdaps_classic_question#1{%
   \tl_if_empty:nTF{#1}{
     \refstepcounter{subsection}%
     \par%
@@ -471,7 +469,7 @@
   \keys_set:nn { sdapsclassic / textbox } { #1 }
 
   \sdaps_classic_ensure_section:
-  \question{#3}
+  \_sdaps_classic_question{#3}
 
   \tl_if_empty:NTF \l_sdaps_classic_textbox_text_tl {
     \sdaps_qobject_begin:nnn { textbox } { Text } { #3 }
@@ -571,7 +569,7 @@
     \int_set:Nn \l_sdaps_singlemark_count_int { \themarkcheckboxcount }
   }
 
-  \question{#2}%
+  \_sdaps_classic_question{#2}%
 
   \sdaps_qobject_begin:nnn { singlemark } { range } { #2 }
 
@@ -606,7 +604,7 @@
     \int_set:Nn \l_sdaps_singlemark_count_int { \themarkcheckboxcount }
   }
 
-  \question{#2}%
+  \_sdaps_classic_question{#2}%
 
   \sdaps_qobject_begin:nnn { singlemark } { range } { #2 }
 
@@ -634,6 +632,7 @@
 \dim_new:N \l__sdaps_classic_choiceitem_pad_dim
 \int_new:N \l__sdaps_classic_choiceitem_cols_int
 \int_new:N \l__sdaps_classic_choiceitem_col_int
+\dim_new:N \l__sdaps_classic_choicequestion_prevdepth_dim
 \coffin_new:N \l__sdaps_classic_choicequestion_coffin
 
 \msg_new:nnn { sdapsclassic } { choicequestion_wrong_mode } { Mode~should~always~be~vertical~inside~a~choicequestion.\\ This~likely~means~that~the~choicequestion~contains~content~other~than~one~of~the~permissable~macros. }
@@ -692,7 +691,7 @@ you~can~get~similar~results~by~temporarily~changing~the~checkbox~style. }
 
   \keys_set:nn { sdaps / choicequestion } { #1 }
 
-  \question{#2}%
+  \_sdaps_classic_question{#2}%
 
   % Setup the context
   \tl_if_eq:VnTF \l_sdaps_choicquestion_type_tl { multichoice } {
@@ -716,6 +715,7 @@ you~can~get~similar~results~by~temporarily~changing~the~checkbox~style. }
 
   \int_set:NV \l__sdaps_classic_choiceitem_cols_int \l_sdaps_choicequestion_cols_int
   \int_set:Nn \l__sdaps_classic_choiceitem_col_int { 0 }
+  \dim_set:Nn \l__sdaps_classic_choicequestion_prevdepth_dim { 1000pt }
   \coffin_clear:N \l__sdaps_classic_choicequestion_coffin
 
   % We have to be in vertical mode at this point.
@@ -744,6 +744,7 @@ you~can~get~similar~results~by~temporarily~changing~the~checkbox~style. }
 
   \choicequestion_widowpenalty
   \vbox:n { \skip_horizontal:N \@totalleftmargin \box_use:N \l__sdaps_classic_choicequestion_coffin }
+  \prevdepth=\l__sdaps_classic_choicequestion_prevdepth_dim
   \coffin_clear:N \l__sdaps_classic_choicequestion_coffin
   \sdaps_qobject_end:n { choicequestion }
 
@@ -757,7 +758,7 @@ you~can~get~similar~results~by~temporarily~changing~the~checkbox~style. }
   \endchoicequestion
 }
 
-\cs_new_protected_nopar:Nn \_sdaps_classic_line_shipout_add:Nn
+\cs_new_protected_nopar:Nn \_sdaps_classic_line_shipout_add:NNn
 {
   % We have to be in vertical mode at this point.
   \if_mode_vertical:
@@ -767,11 +768,13 @@ you~can~get~similar~results~by~temporarily~changing~the~checkbox~style. }
   \fi:
 
   % Is linewidth the right thing here?
-  \int_compare:nT { \l__sdaps_classic_choiceitem_col_int + #2 > \l__sdaps_classic_choiceitem_cols_int } {
+  \int_compare:nT { \l__sdaps_classic_choiceitem_col_int + #3 > \l__sdaps_classic_choiceitem_cols_int } {
     % We can only typeset a coffin in vertical mode if we use the box function
     \vbox:n { \skip_horizontal:N \@totalleftmargin \box_use:N \l__sdaps_classic_choicequestion_coffin }
+    \prevdepth=\l__sdaps_classic_choicequestion_prevdepth_dim
     \skip_vertical:N \l_sdaps_choicequestion_rowsep_dim
     \coffin_clear:N \l__sdaps_classic_choicequestion_coffin
+    \dim_set:Nn \l__sdaps_classic_choicequestion_prevdepth_dim { 1000pt }
     \choicequestion_clubpenalty
     \int_set:Nn \l__sdaps_classic_choiceitem_col_int { 0 }
   }
@@ -779,8 +782,14 @@ you~can~get~similar~results~by~temporarily~changing~the~checkbox~style. }
   \dim_set:Nn \l_tmpa_dim { \linewidth / \l__sdaps_classic_choiceitem_cols_int + \l__sdaps_classic_choiceitem_pad_dim / \l__sdaps_classic_choiceitem_cols_int }
   \dim_set:Nn \l_tmpa_dim { \l__sdaps_classic_choiceitem_col_int \l_tmpa_dim }
 
+  \dim_compare:nNnTF { \coffin_dp:N \l__sdaps_classic_choicequestion_coffin } > { \coffin_dp:N #1 } {
+    \dim_set:Nn \l__sdaps_classic_choicequestion_prevdepth_dim {\dim_min:nn { \l__sdaps_classic_choicequestion_prevdepth_dim } { #2 + \coffin_dp:N \l__sdaps_classic_choicequestion_coffin - \coffin_dp:N #1 } }
+  } {
+    \dim_set:Nn \l__sdaps_classic_choicequestion_prevdepth_dim {\dim_min:nn { \l__sdaps_classic_choicequestion_prevdepth_dim + \coffin_dp:N #1 - \coffin_dp:N \l__sdaps_classic_choicequestion_coffin } { #2 } }
+  }
+
   \coffin_join:NnnNnnnn \l__sdaps_classic_choicequestion_coffin { l } { H } #1 { l } { H } { \l_tmpa_dim } { 0pt }
-  \int_add:Nn \l__sdaps_classic_choiceitem_col_int { #2 }
+  \int_add:Nn \l__sdaps_classic_choiceitem_col_int { #3 }
 }
 
 \providecommand*{\choiceitem}[2][]{%
@@ -802,13 +811,16 @@ you~can~get~similar~results~by~temporarily~changing~the~checkbox~style. }
     \hbox_set:Nn \l_tmpa_box { \strut \sdaps_checkbox:VV \l_sdaps_choicequestion_choice_var_tl \l_sdaps_choicequestion_choice_val_tl {}\  }
     \dim_set:Nn \l_tmpb_dim { \box_wd:N \l_tmpa_box }
     \hskip \l_sdaps_choicequestion_colsep_dim
-    \hbox_unpack_clear:N \l_tmpa_box
+    \hbox_unpack:N \l_tmpa_box
     \begin{minipage}[t]{\dim_eval:n { \l_tmpa_dim - \l_tmpb_dim - 2\l_sdaps_choicequestion_colsep_dim}}
-      \noindent \usekomafont{choiceitemfont} \tl_trim_spaces:n { #2 }
+      \noindent \usekomafont{choiceitemfont} \tl_trim_spaces:n { #2 }\strut
+      \par
+      \dim_gset:Nn \g_tmpa_dim { \dim_max:nn { \box_dp:N \l_tmpa_box } { \prevdepth } }
+      \unskip
     \end{minipage}
   }
 
-  \_sdaps_classic_line_shipout_add:Nn \l_tmpa_coffin { 1 }
+  \_sdaps_classic_line_shipout_add:NNn \l_tmpa_coffin \g_tmpa_dim { 1 }
   \ignorespaces
 }
 
@@ -831,13 +843,16 @@ you~can~get~similar~results~by~temporarily~changing~the~checkbox~style. }
     \hbox_set:Nn \l_tmpa_box { \strut \sdaps_checkbox:VV \l_sdaps_choicequestion_choice_var_tl \l_sdaps_choicequestion_choice_val_tl {}\  }
     \dim_set:Nn \l_tmpb_dim { \box_wd:N \l_tmpa_box }
     \hskip \l_sdaps_choicequestion_colsep_dim
-    \hbox_unpack_clear:N \l_tmpa_box
+    \hbox_unpack:N \l_tmpa_box
     \begin{minipage}[t]{\dim_eval:n { \l_tmpa_dim - \l_tmpb_dim - 2\l_sdaps_choicequestion_colsep_dim}}
-      \noindent \usekomafont{choiceitemfont} \tl_trim_spaces:n { #3 }
+      \noindent \usekomafont{choiceitemfont} \tl_trim_spaces:n { #3 }\strut
+      \par
+      \dim_gset:Nn \g_tmpa_dim { \dim_max:nn { \box_dp:N \l_tmpa_box } { \prevdepth } }
+      \unskip
     \end{minipage}
   }
 
-  \_sdaps_classic_line_shipout_add:Nn \l_tmpa_coffin { #2 }
+  \_sdaps_classic_line_shipout_add:NNn \l_tmpa_coffin \g_tmpa_dim { #2 }
   \ignorespaces
 }
 
@@ -872,10 +887,13 @@ you~can~get~similar~results~by~temporarily~changing~the~checkbox~style. }
       \dim_set:Nn \l_tmpb_dim { 0.5 \l_tmpb_dim + 0.8ex }
       \strut\ignorespaces \tl_trim_spaces:n { #4 } ~
       \sdaps_textbox_hstretch:VVVnn \l_sdaps_choicequestion_choice_var_tl \l_tmpa_dim \l_tmpb_dim { 0pt } { 1 }
+      \par
+      \dim_gset:Nn \g_tmpa_dim { \prevdepth }
+      \unskip
     \end{minipage}
   }
 
-  \_sdaps_classic_line_shipout_add:Nn \l_tmpa_coffin { #3 }
+  \_sdaps_classic_line_shipout_add:NNn \l_tmpa_coffin \g_tmpa_dim { #3 }
   \ignorespaces
 }
 
@@ -1050,12 +1068,30 @@ you~can~get~similar~results~by~temporarily~changing~the~checkbox~style. }
 %    \begin{macrocode}
 %
 
+\tl_new:N \l__sdaps_classic_group_var_tl
+\tl_new:N \l__sdaps_classic_group_text_tl
+\tl_new:N \l__sdaps_classic_group_extra_tl
+\keys_define:nn { sdapsclassic / group }
+{
+  var        .tl_set:N   = \l__sdaps_classic_group_var_tl,
+  text       .tl_set:N   = \l__sdaps_classic_group_text_tl,
+}
 
 \newenvironment { choicegroup } [ 2 ] []
 {
   \group_begin:
+    \keys_set_known:nnN { sdapsclassic / group } { #1 } \l__sdaps_classic_group_extra_tl
+
+    \_sdaps_classic_question{#2}
+    \tl_if_empty:NTF \l__sdaps_classic_group_text_tl {
+      \sdaps_qobject_begin:nnn { choicegroup } { Head } { #2 }
+    } {
+      \sdaps_qobject_begin:nnV { choicegroup } { Head } \l__sdaps_classic_group_text_tl
+    }
 
-    \question{#2}
+    \tl_if_empty:NF \l__sdaps_classic_group_var_tl {
+      \sdaps_qobject_append_var:V \l__sdaps_classic_group_var_tl
+    }
 
     % Undefine the question (and choice) commands in local scope so that they
     % can be redefined by choicearray without any issues.
@@ -1063,7 +1099,7 @@ you~can~get~similar~results~by~temporarily~changing~the~checkbox~style. }
     \cs_set_eq:NN\question\tex_undefined:D
     \cs_set_eq:NN\choice\tex_undefined:D
 
-    \begin{choicearray}[#1]{#2}
+    \expandafter\choicearray\expandafter[\l__sdaps_classic_group_extra_tl]
       % XXX: This is a bit of a hack, set in global scope because the choicearray
       %      environment does evil things with scopes.
       \cs_gset_eq:NN\groupaddchoice\choice
@@ -1073,15 +1109,27 @@ you~can~get~similar~results~by~temporarily~changing~the~checkbox~style. }
       \cs_gset_eq:NN\groupaddchoice\undefined
       \cs_gset_eq:NN\choiceline\undefined
 
-    \end{choicearray}
+    \endchoicearray
+
+    \sdaps_qobject_end:n { choicegroup }
   \group_end:
 }
 
 \newenvironment { optiongroup } [ 2 ] []
 {
   \group_begin:
+    \keys_set_known:nnN { sdapsclassic / group } { #1 } \l__sdaps_classic_group_extra_tl
 
-    \question{#2}
+    \_sdaps_classic_question{#2}
+    \tl_if_empty:NTF \l__sdaps_classic_group_text_tl {
+      \sdaps_qobject_begin:nnn { optiongroup } { Head } { #2 }
+    } {
+      \sdaps_qobject_begin:nnV { optiongroup } { Head } \l__sdaps_classic_group_text_tl
+    }
+
+    \tl_if_empty:NF \l__sdaps_classic_group_var_tl {
+      \sdaps_qobject_append_var:V \l__sdaps_classic_group_var_tl
+    }
 
     % Undefine the question (and choice) commands in local scope so that they
     % can be redefined by optionarray without any issues.
@@ -1089,7 +1137,7 @@ you~can~get~similar~results~by~temporarily~changing~the~checkbox~style. }
     \cs_set_eq:NN\question\tex_undefined:D
     \cs_set_eq:NN\choice\tex_undefined:D
 
-    \begin{optionarray}[#1]{#2}
+    \expandafter\optionarray\expandafter[\l__sdaps_classic_group_extra_tl]
       % XXX: This is a bit of a hack, set in global scope because the optionarray
       %      environment does evil things with scopes.
       \cs_gset_eq:NN\groupaddchoice\choice
@@ -1099,22 +1147,33 @@ you~can~get~similar~results~by~temporarily~changing~the~checkbox~style. }
       \cs_gset_eq:NN\groupaddoption\undefined
       \cs_gset_eq:NN\optionline\undefined
 
-    \end{optionarray}
+    \endoptionarray
+    \sdaps_qobject_end:n { optiongroup }
   \group_end:
 }
 
 \newenvironment { markgroup } [ 2 ] []
 {
   \group_begin:
+    \keys_set_known:nnN { sdapsclassic / group } { #1 } \l__sdaps_classic_group_extra_tl
 
-    \question{#2}
+    \_sdaps_classic_question{#2}
+    \tl_if_empty:NTF \l__sdaps_classic_group_text_tl {
+      \sdaps_qobject_begin:nnn { markgroup } { Head } { #2 }
+    } {
+      \sdaps_qobject_begin:nnV { markgroup } { Head } \l__sdaps_classic_group_text_tl
+    }
 
-    % Undefine the question (and choice) commands in local scope so that they
-    % can be redefined by choicearray without any issues.
+    \tl_if_empty:NF \l__sdaps_classic_group_var_tl {
+      \sdaps_qobject_append_var:V \l__sdaps_classic_group_var_tl
+    }
+
+    % Undefine the range command in local scope so that it can be redefined
+    % by rangearray without any issues.
     % Note that \cs_undefine:N works in global scope, so we cannot use it here.
     \cs_set_eq:NN\range\tex_undefined:D
 
-    \begin{rangearray}[#1]{#2}
+    \expandafter\rangearray\expandafter[\l__sdaps_classic_group_extra_tl]
       % XXX: This is a bit of a hack, set in global scope because the choicearray
       %      environment does evil things with scopes.
       \cs_gset_eq:NN\markline\range
@@ -1122,7 +1181,8 @@ you~can~get~similar~results~by~temporarily~changing~the~checkbox~style. }
 {
       \cs_gset_eq:NN\markline\undefined
 
-    \end{rangearray}
+    \endrangearray
+    \sdaps_qobject_end:n { markgroup }
   \group_end:
 }
 
-- 
cgit v1.2.3

