From ac2cf3ee05ab2a5494afa92dbbdc6d56e7518bae Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 2 Dec 2013 22:18:13 +0000 Subject: exsheets (2dec13) git-svn-id: svn://tug.org/texlive/trunk@32302 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/latex/exsheets/exsheets.sty | 311 ++++++++++++++++------ 1 file changed, 227 insertions(+), 84 deletions(-) (limited to 'Master/texmf-dist/tex/latex/exsheets') diff --git a/Master/texmf-dist/tex/latex/exsheets/exsheets.sty b/Master/texmf-dist/tex/latex/exsheets/exsheets.sty index ed95236e601..7a67093fe33 100644 --- a/Master/texmf-dist/tex/latex/exsheets/exsheets.sty +++ b/Master/texmf-dist/tex/latex/exsheets/exsheets.sty @@ -25,8 +25,8 @@ % If you have any ideas, questions, suggestions or bugs to report, please % feel free to contact me. % ---------------------------------------------------------------------------- -\def\exsheets@date{2013/11/20} -\def\exsheets@version{0.11} +\def\exsheets@date{2013/12/02} +\def\exsheets@version{0.12} \RequirePackage { expl3 , xparse } \ProvidesExplPackage @@ -51,12 +51,13 @@ % ---------------------------------------------------------------------------- % variants of kernel functions: -\cs_generate_variant:Nn \prop_get:NnN { Nx } -\cs_generate_variant:Nn \prop_get:NnN { cf } -\cs_generate_variant:Nn \prop_get:NnNTF { Nx } -\cs_generate_variant:Nn \prop_gput:Nnn { Nf , Nff , Nfx } -\cs_generate_variant:Nn \prop_gput:Nnn { Nx , Nxx } -\cs_generate_variant:Nn \prop_gput:Nnn { cf , cff } +\cs_generate_variant:Nn \prop_get:NnN { Nx } +\cs_generate_variant:Nn \prop_get:NnN { cf } +\cs_generate_variant:Nn \prop_get:NnNTF { Nx } +\cs_generate_variant:Nn \prop_gput:Nnn { Nf , Nff , Nfx } +\cs_generate_variant:Nn \prop_gput:Nnn { Nx , Nxx } +\cs_generate_variant:Nn \prop_gput:Nnn { cf , cff } +\cs_generate_variant:Nn \tl_if_blank:nTF { x } % ---------------------------------------------------------------------------- % temporary variables @@ -79,13 +80,13 @@ % messages \msg_new:nnn { exsheets} { totalpoints } { - You~need~to~activate~"points/parse"~if~you~want~to~use~ + You~need~to~activate~`points/parse'~if~you~want~to~use~ \token_to_str:N \totalpoints .~I~will~do~nothing~instead. } \msg_new:nnn { exsheets} { parse-points } { - You~need~to~activate~"points/parse"~if~you~want~to~use~ + You~need~to~activate~`points/parse'~if~you~want~to~use~ \token_to_str:N #1 .~I~will~do~nothing~instead. } @@ -111,7 +112,7 @@ \msg_new:nnn { exsheets } { only-inside-question } { - The~command~\token_to_str:N #1 \c_space_tl can~only~be~used~inside~ + The~command~`~\token_to_str:N #1 \c_space_tl'~can~only~be~used~inside~ the~question~environment. } @@ -120,10 +121,13 @@ \msg_new:nnn { exsheets } { deprecated-command } { - The~command~"~\token_to_str:N #1 \c_space_tl"~is~deprecated.~ - Use~"~\token_to_str:N #2 \c_space_tl"~instead. + The~command~`~\token_to_str:N #1 \c_space_tl'~is~deprecated.~ + Use~`~\token_to_str:N #2 \c_space_tl'~instead. } +\msg_new:nnn { exsheets } { dropped-option } + { The~option~`#1'~has~been~dropped. } + \msg_new:nnn { exsheets } { grade-missing } { The~grade~`#1'~has~never~been~declared. } @@ -151,6 +155,9 @@ { \msg_warning:nnnn { exsheets } { deprecated-command } { #1 } { #2 } #2 } } +\cs_new_protected:Npn \exsheets_option_dropped:n #1 + { \msg_warning:nnn { exsheets } { dropped-option } { #1 } } + % ---------------------------------------------------------------------------- \RequirePackage { xtemplate , l3sort , l3keys2e , xcolor , etoolbox , environ , pgfcore } @@ -159,8 +166,24 @@ % color: \xdefinecolor { exsheetsblue } { rgb } { 0.02 , 0.04 , 0.48 } \xdefinecolor { exsheetsred } { rgb } { 0.65 , 0.04 , 0.07 } -\tl_new:N \g__exsheets_color_tl -\tl_gset:Nn \g__exsheets_color_tl { exsheetsblue } +% \tl_new:N \g__exsheets_color_tl +\tl_const:Nn \c__exsheets_color_tl { exsheetsblue } + +% ---------------------------------------------------------------------------- +% write to aux file: +\cs_new_protected:Npn \exsheets_write_to_aux_x:n #1 + { \if@filesw \iow_now:Nx \@auxout { #1 } \fi } + +% prevent compilatin errors when exsheets is removed from a document: +\AtBeginDocument{ + \exsheets_write_to_aux_x:n + { + \exp_not:N \providecommand \exp_not:N \exsheets@question@property[3]{} ^^J + \exp_not:N \providecommand \exp_not:N \exsheets@save@number[2]{} ^^J + \exp_not:N \providecommand \exp_not:N \exsheets@sum@of@points[1]{} ^^J + \exp_not:N \providecommand \exp_not:N \exsheets@sum@of@bonus[1]{} + } +} % ---------------------------------------------------------------------------- % how are questions/solutions/... counted? @@ -217,7 +240,8 @@ \keys_define:nn { exsheets } { - color .tl_gset:N = \g__exsheets_color_tl , + color .code:n = + \exsheets_option_dropped:n { color } , counter-format .code:n = \SaveCounterPattern [ exsheets ] \l__exsheets_qu_counter_pattern_tl @@ -937,6 +961,8 @@ \tl_new:N \l__exsheets_exercise_name_tl \tl_set:Nn \l__exsheets_exercise_name_tl { Exercise } +\tl_new:N \CurrentQuestionID + \bool_new:N \l__exsheets_questions_print_bool \bool_set_true:N \l__exsheets_questions_print_bool \bool_new:N \l__exsheets_inside_question_bool @@ -989,12 +1015,36 @@ \tl_new:N \l__exsheets_questions_label_tl \tl_new:N \l__exsheets_questions_points_tl -\bool_new:N \l__exsheets_points_not_given_bool +\prg_new_conditional:Npnn \exsheets_if_question_subtitle: { p,T,F,TF } + { + \tl_if_blank:VTF \l__exsheets_questions_subtitle_tl + { \prg_return_false: } + { \prg_return_true: } + } + +\cs_new:Npn \IfQuestionSubtitleTF { \exsheets_if_question_subtitle:TF } +\cs_new:Npn \IfQuestionSubtitleT { \exsheets_if_question_subtitle:T } +\cs_new:Npn \IfQuestionSubtitleF { \exsheets_if_question_subtitle:F } + +\bool_new:N \l__exsheets_only_print_points_bool \fp_new:N \g__exsheets_this_question_points_fp \fp_new:N \g__exsheets_this_question_bonus_fp -\cs_new_protected:Npn \__exsheets_read_points:w #1+#2+#3 \q_stop +\cs_new:Npn \__exsheets_read_points:w #1 ! #2 ! #3 \q_stop + { + \tl_if_blank:nTF { #1 } + { + \bool_set_true:N \l__exsheets_only_print_points_bool + \tl_set:Nn \l__exsheets_questions_points_tl { #2 } + } + { + \bool_set_false:N \l__exsheets_only_print_points_bool + \__exsheets_read_points_aux:w #1++ \q_stop + } + } + +\cs_new_protected:Npn \__exsheets_read_points_aux:w #1+#2+#3 \q_stop { \tl_if_blank:nTF { #1 } { \fp_zero:N \l__exsheets_question_points_fp } @@ -1010,10 +1060,60 @@ \cs_new_protected:Npn \__exsheets_read_points:n #1 { \bool_if:NTF \l__exsheets_parse_points_bool - { \__exsheets_read_points:w #1++ \q_stop } + { \__exsheets_read_points:w #1!! \q_stop } { \tl_set:Nn \l__exsheets_questions_points_tl { #1 } } } +\cs_new:Npn \exsheets_label_format:n #1 { qu:#1 } +\cs_new:Npn \__exsheets_label:n { \label } +\cs_new:Npn \exsheets_label:n { } +\cs_generate_variant:Nn \exsheets_label:n { V } +\cs_new:Npn \__exsheets_ref:n { \ref } +\cs_new:Npn \exsheets_ref:n { } +\cs_new:Npn \__exsheets_pageref:n { \pageref } +\cs_new:Npn \exsheets_pageref:n { } + +\cs_new_protected:Npn \exsheets_update_referencing_command:NN #1#2 + { + \cs_set:Npx #1 ##1 + { \exp_not:o { #2 } { \exsheets_label_format:n { ##1 } } } + } + +\cs_new_protected:Npn \exsheets_update_referencing_commands: + { + \exsheets_update_referencing_command:NN \exsheets_label:n \__exsheets_label:n + \exsheets_update_referencing_command:NN \exsheets_ref:n \__exsheets_ref:n + \exsheets_update_referencing_command:NN \exsheets_pageref:n \__exsheets_pageref:n + } + +\cs_new_protected:Npn \exsheets_set_ref_properties:n #1 + { + \exsheets_set_question_properties:x + { + ref = \exp_not:o { \exsheets_ref:n { #1 } } , + pageref = \exp_not:o { \exsheets_pageref:n { #1 } } + } + } +\cs_generate_variant:Nn \exsheets_set_ref_properties:n { V } + +\keys_define:nn { exsheets } + { + label-format .code:n = + \cs_set:Npn \exsheets_label_format:n ##1 { #1 } + \exsheets_update_referencing_commands: , + label-cmd .code:n = + \cs_set:Npn \__exsheets_label:n { #1 } + \exsheets_update_referencing_commands: , + ref-cmd .code:n = + \cs_set:Npn \__exsheets_ref:n { #1 } + \exsheets_update_referencing_commands: , + page-ref-cmd .code:n = + \cs_set:Npn \__exsheets_pageref:n { #1 } + \exsheets_update_referencing_commands: + } + +\exsheets_update_referencing_commands: + \newenvironment { __exsheets_question: } [2] { \bool_set_true:N \l__exsheets_inside_question_bool @@ -1038,35 +1138,16 @@ { \tl_gset:Nx \g__exsheets_questions_current_id_tl { \tl_use:N \l__exsheets_questions_id_tl } - } - % label: - \tl_if_blank:VTF \l__exsheets_questions_label_tl - { - \bool_if:NT \l__exsheets_auto_label_bool - { - \exp_args:Nx \label { qu : \g__exsheets_questions_current_id_tl } - \exsheets_set_question_properties:x - { - ref = \exp_not:N \ref { qu : \g__exsheets_questions_current_id_tl } , - pageref = \exp_not:N \pageref { qu : \g__exsheets_questions_current_id_tl } - } - } - } - { - \exp_args:Nx \label { \l__exsheets_questions_label_tl } - \exsheets_set_question_properties:x - { - ref = \exp_not:N \ref { \l__exsheets_questions_label_tl } , - pageref = \exp_not:N \pageref { \l__exsheets_questions_label_tl } - } - } - % FIXME: rather useless since it isn't used at all, see also - % exsheets_headings.def + } \tl_if_blank:VF \l__exsheets_questions_subtitle_tl { - \prop_gput:NVV \g__exsheets_questions_subtitle_prop - \g__exsheets_questions_current_id_tl - \l__exsheets_questions_subtitle_tl + \exsheets_set_question_properties:x + { subtitle = { \exp_not:V \l__exsheets_questions_subtitle_tl } } + % FIXME: rather useless since it isn't used at all, see also + % exsheets_headings.def + % \prop_gput:NVV \g__exsheets_questions_subtitle_prop + % \g__exsheets_questions_current_id_tl + % \l__exsheets_questions_subtitle_tl } } \bool_if:nT @@ -1097,8 +1178,9 @@ \fp_set_eq:NN \l__exsheets_question_points_fp \l__exsheets_points_default_fp - \exsheets_set_question_properties:x - { points = \fp_to_tl:N \l__exsheets_points_default_fp } + % check if moving this to a later point has negative effects... + % \exsheets_set_question_properties:x + % { points = \fp_to_tl:N \l__exsheets_points_default_fp } } } { @@ -1106,7 +1188,8 @@ \g__exsheets_this_question_points_fp \l__exsheets_question_points_fp \__exsheets_read_points:n { #2 } - \exsheets_set_question_properties:n { points = #2 } + % check if moving this to a later point has negative effects... + % \exsheets_set_question_properties:n { points = #2 } } \tl_if_blank:VT \l__exsheets_question_heading_instance_tl { @@ -1146,6 +1229,19 @@ % erhöhe jetzt, wenn kein Nein dabei war: \tl_if_in:NnF \l__exsheets_step_counter_tl { n } { \refstepcounter{question} } + % label: + \tl_if_blank:VTF \l__exsheets_questions_label_tl + { + \bool_if:NT \l__exsheets_auto_label_bool + { + \exsheets_label:V \g__exsheets_questions_current_id_tl + \exsheets_set_ref_properties:V \g__exsheets_questions_current_id_tl + } + } + { + \exsheets_label:V \l__exsheets_questions_label_tl + \exsheets_set_ref_properties:V \l__exsheets_questions_label_tl + } \__exsheets_get_sectioning_numbers: \bool_if:nT { @@ -1185,7 +1281,9 @@ \l__exsheets_tmpa_tl \l__exsheets_questions_id_tl } - \bool_if:NTF \l__exsheets_parse_points_bool + \tl_set_eq:NN \CurrentQuestionID \l__exsheets_tmpa_tl + \bool_if:nTF + { \l__exsheets_parse_points_bool && !\l__exsheets_only_print_points_bool } { \__exsheets_use_heading:VVVnnV \l__exsheets_question_heading_instance_tl @@ -1196,13 +1294,26 @@ \l__exsheets_tmpa_tl } { - \__exsheets_use_heading:VVVnnV - \l__exsheets_question_heading_instance_tl - \l__exsheets_questions_title_tl - \l__exsheets_qu_counter_interpretation_tl - { \l__exsheets_questions_points_tl } - { 0 } - \l__exsheets_tmpa_tl + % might be dangerous to expand here... + \tl_if_blank:xTF { \l__exsheets_questions_points_tl } + { + \__exsheets_use_heading:VVVnnV + \l__exsheets_question_heading_instance_tl + \l__exsheets_questions_title_tl + \l__exsheets_qu_counter_interpretation_tl + { 0 } + { 0 } + \l__exsheets_tmpa_tl + } + { + \__exsheets_use_heading:VVVnnV + \l__exsheets_question_heading_instance_tl + \l__exsheets_questions_title_tl + \l__exsheets_qu_counter_interpretation_tl + { \l__exsheets_questions_points_tl } + { 0 } + \l__exsheets_tmpa_tl + } } } } @@ -1229,9 +1340,7 @@ \cs_new_protected:Npn \__exsheets_save_number_in_aux_x:Nnn #1#2#3 { \prop_gput:Nfx #1 { #2 } { #3 } - \if@filesw - \iow_now:Nx \@auxout { \exsheets@save@number { #2 } { #3 } } - \fi + \exsheets_write_to_aux_x:n { \exsheets@save@number { #2 } { #3 } } } \cs_new_protected:Npn \__exsheets_save_number_in:N #1 @@ -1348,7 +1457,7 @@ \tl_set:Nn \l__exsheets_exercise_name_tl { #1 } \tl_set:Nn \l__exsheets_questions_name_tl { #1 } , headings .tl_set:N = \l__exsheets_question_heading_instance_tl , - subtitle .tl_set:N = \l__exsheets_questions_subtitle_tl , + subtitle .tl_set:N = \l__exsheets_questions_subtitle_tl , print .bool_set:N = \l__exsheets_questions_print_bool , print .default:n = true , ID .tl_set:N = \l__exsheets_questions_id_tl , @@ -1393,20 +1502,42 @@ \NewDocumentCommand \SetQuestionProperties { m } { \exsheets_set_question_properties:n { #1 } } +% #1: ID +% #2: property +% #3: value +\cs_new:Npn \exsheets@question@property #1#2#3 + { + \prop_gput:cnn { g__exsheets_question_property_#2_prop } + { #1 } { #3 } + } + +% #1: property +% #2: value \cs_new_protected:Npn \__exsheets_question_set_property:nn #1#2 { \prop_gput:cVn { g__exsheets_question_property_#1_prop } \g__exsheets_questions_current_id_tl { #2 } + % watch if this has negativ effects: + \exsheets_write_to_aux_x:n + { + \exp_not:N \exsheets@question@property + { \g__exsheets_questions_current_id_tl } + { \exp_not:n {#1} } + { \exp_not:n {#2} } + } } -\NewDocumentCommand \GetQuestionProperty { mm } - { \exsheets_get_question_property:nn { #1 } { #2 } } +% #1: property +% #2: ID +\DeclareExpandableDocumentCommand \GetQuestionProperty { mm } + { \exsheets_get_question_property:no { #1 } { #2 } } \cs_new:Npn \exsheets_get_question_property:nn #1#2 { \prop_if_in:cnT { g__exsheets_question_property_#1_prop } { #2 } { \prop_get:cn { g__exsheets_question_property_#1_prop } { #2 } } } +\cs_generate_variant:Nn \exsheets_get_question_property:nn { no } \int_new:N \g__exsheets_tmpa_int \cs_new_protected:Npn \ForEachQuestion #1 @@ -1480,8 +1611,6 @@ \NewDocumentCommand \DebugExSheets { G{true} } { \use:c { bool_set_#1:N } \l__exsheets_questions_debug_bool } -\cs_new:Npn \CurrentQuestionID { \g__exsheets_questions_current_id_tl } - % ---------------------------------------------------------------------------- % include random/selected questions from a file: \bool_new:N \l__exsheets_select_questions_bool @@ -1937,22 +2066,20 @@ \cs_new_protected:Npn \__exsheets_exlabel:n #1 { \@bsphack - \if@filesw - \iow_now:Nx \@auxout + \exsheets_write_to_aux_x:n { \token_to_str:N \newlabel { exse:#1 } { { \arabic { section } } { \thepage } } } \cs_if_exist:NT \thechapter { - \iow_now:Nx \@auxout + \exsheets_write_to_aux_x:n { \token_to_str:N \newlabel { exch:#1 } { { \arabic { chapter } } { \thepage } } } } - \@esphack - \fi + \@esphack } % user command: @@ -1967,10 +2094,10 @@ } % this is like \ref from latex.ltx -\cs_new:Npn \__exsheets_ref:n #1 +\cs_new:Npn \__exsheets_exref:n #1 { \cs_if_exist:cTF { r@#1 } - { \__exsheets_ref_aux:n { #1 } } + { \__exsheets_exref_aux:n { #1 } } { 1\relax \protect\G@refundefinedtrue @@ -1978,10 +2105,10 @@ } } -\cs_new:Npn \__exsheets_ref_aux:n #1 +\cs_new:Npn \__exsheets_exref_aux:n #1 { \exp_after:wN \exp_after:wN \exp_after:wN \use_i:nn \cs:w r@#1 \cs_end: } -\cs_new_eq:NN \exref \__exsheets_ref:n +\cs_new_eq:NN \exref \__exsheets_exref:n % user command: \NewDocumentCommand \printsolutions { O{all} } @@ -2536,13 +2663,14 @@ % properties: \DeclareQuestionProperty{points} +\DeclareQuestionProperty{subtitle} \bool_if:NT \l__exsheets_auto_label_bool { \DeclareQuestionProperty{ref} \DeclareQuestionProperty{pageref} } -% classs: +% classes: \DeclareQuestionClass{class}{classes} \DeclareQuestionClass{topic}{topics} @@ -2610,15 +2738,13 @@ % save total points in .aux file to make it available for \allpoints anywhere \AtEndDocument { - \if@filesw - \iow_now:Nx \@auxout - { - \exp_not:N \exsheets@sum@of@points - { \fp_eval:n { \g__exsheets_points_sum_fp } }^^J - \exp_not:N \exsheets@sum@of@bonus - { \fp_eval:n { \g__exsheets_bonus_sum_fp } } - } - \fi + \exsheets_write_to_aux_x:n + { + \exp_not:N \exsheets@sum@of@points + { \fp_eval:n { \g__exsheets_points_sum_fp } }^^J + \exp_not:N \exsheets@sum@of@bonus + { \fp_eval:n { \g__exsheets_bonus_sum_fp } } + } } % ---------------------------------------------------------------------------- @@ -2777,6 +2903,23 @@ HISTORY: has been passed to the headings 2013/11/20 v0.11 - \GetQuestionClass{} - \PrintQuestionClass(TF) +2013/12/02 v0.12 - fix issue with \CurrentQuestionID + - new options `label-format', `label-cmd', `ref-cmd' + and `pageref-cmd' for `auto-label' options that + allow specification of labelling command and thus + compatibility with packages like `cleveref' + - write question properties to aux file so they can be + retrieved before the corresponding question is + printed + - make \GetQuestionProperty expandable + - new syntax featture in points argument: a leading + bang prevents the points from being added to the sum + of points + - added possibility for + https://bitbucket.org/cgnieder/exsheets/issue/15 + - added \IfQuestionSubtitle(TF) + - added `subtitle' property + - dropped `color' option %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % TODO: -- cgit v1.2.3