diff options
author | Karl Berry <karl@freefriends.org> | 2013-01-22 23:46:45 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2013-01-22 23:46:45 +0000 |
commit | 48f8b21c2d50f6df0ccca85645ed3d6f7f0dd4a0 (patch) | |
tree | 08a17e173875933c9e18478ba2a67372821512fc /Master/texmf-dist/tex/latex/exsheets/exsheets.sty | |
parent | 9a53151298ad029ce1c0c77c1f30922ee837ee07 (diff) |
exsheets/tasks 0.7a (22jan13)
git-svn-id: svn://tug.org/texlive/trunk@28907 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/exsheets/exsheets.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/exsheets/exsheets.sty | 217 |
1 files changed, 129 insertions, 88 deletions
diff --git a/Master/texmf-dist/tex/latex/exsheets/exsheets.sty b/Master/texmf-dist/tex/latex/exsheets/exsheets.sty index 7c939d9de03..6ac2e4dddc0 100644 --- a/Master/texmf-dist/tex/latex/exsheets/exsheets.sty +++ b/Master/texmf-dist/tex/latex/exsheets/exsheets.sty @@ -31,8 +31,8 @@ % If you have any ideas, questions, suggestions or bugs to report, please % feel free to contact me. % ---------------------------------------------------------------------------- -\def\exsheets@date{2013/01/06} -\def\exsheets@version{0.6b} +\def\exsheets@date{2013/01/21} +\def\exsheets@version{0.7a} \RequirePackage { expl3 , xparse } \ProvidesExplPackage @@ -48,6 +48,8 @@ \tl_new:N \l__exsheets_tmpc_tl \int_new:N \l__exsheets_tmpa_int \int_new:N \l__exsheets_tmpb_int +\int_new:N \l__exsheets_tmpc_int +\int_new:N \l__exsheets_tmpd_int \dim_new:N \l__exsheets_tmpa_dim \seq_new:N \l__exsheets_tmpa_seq \fp_new:N \l__exsheets_tmpa_fp @@ -119,7 +121,7 @@ % ---------------------------------------------------------------------------- \RequirePackage - { xtemplate , l3sort , l3keys2e , xcolor , etoolbox , environ , lcg , silence } + { xtemplate , l3sort , l3keys2e , xcolor , etoolbox , environ , pgfcore } % ---------------------------------------------------------------------------- % color: @@ -161,6 +163,7 @@ \bool_new:N \l__exsheets_solutions_by_ref_bool \bool_new:N \l__exsheets_questions_totoc_bool \bool_new:N \l__exsheets_solutions_totoc_bool +\bool_new:N \l__exsheets_auto_label_bool \tl_new:N \l__exsheets_heading_instance_tl \tl_set:Nn \l__exsheets_heading_instance_tl { block } @@ -206,7 +209,8 @@ \tl_set:Nn \l__exsheets_questions_toclevel_tl { #1 } \tl_set:Nn \l__exsheets_solutions_toclevel_tl { #1 } , questions-toc-level .tl_set:N = \l__exsheets_questions_toclevel_tl , - solutions-toc-level .tl_set:N = \l__exsheets_solutions_toclevel_tl + solutions-toc-level .tl_set:N = \l__exsheets_solutions_toclevel_tl , + auto-label .bool_set:N = \l__exsheets_auto_label_bool } \keys_set:nn { exsheets} { counter-format = qu. } @@ -939,6 +943,7 @@ \tl_new:N \l__exsheets_questions_meta_tl \tl_new:N \g__exsheets_questions_current_id_tl \tl_new:N \l__exsheets_title_tl +\tl_new:N \l__exsheets_questions_label_tl \bool_new:N \l__exsheets_points_not_given_bool @@ -966,35 +971,63 @@ % Optionen: \IfNoValueF { #1 } { \keys_set:nn { exsheets / question } { #1 } } % ID: - \int_gincr:N \g__exsheets_questions_id_int - \tl_if_blank:VTF \l__exsheets_questions_id_tl + \bool_if:nT + { + (\l__exsheets_questions_deactivate_bool && \l__exsheets_select_questions_bool) + || + !\l__exsheets_select_questions_bool + } { - \prop_gput:NVV \g__exsheets_questions_id_prop - \g__exsheets_questions_id_int - \g__exsheets_questions_id_int - \bool_if:NT \l__exsheets_questions_use_bool + \int_gincr:N \g__exsheets_questions_id_int + \tl_if_blank:VTF \l__exsheets_questions_id_tl { - \prop_gput:NVV \g__exsheets_questions_used_prop + \prop_gput:NVV \g__exsheets_questions_id_prop \g__exsheets_questions_id_int \g__exsheets_questions_id_int - \int_gincr:N \g__exsheets_questions_used_int + \bool_if:NT \l__exsheets_questions_use_bool + { + \prop_gput:NVV \g__exsheets_questions_used_prop + \g__exsheets_questions_id_int + \g__exsheets_questions_id_int + \int_gincr:N \g__exsheets_questions_used_int + } + \tl_gset:Nx \g__exsheets_questions_current_id_tl + { \int_use:N \g__exsheets_questions_id_int } } - \tl_gset:Nx \g__exsheets_questions_current_id_tl - { \int_use:N \g__exsheets_questions_id_int } - } - { - \prop_gput:NVV \g__exsheets_questions_id_prop - \l__exsheets_questions_id_tl - \g__exsheets_questions_id_int - \bool_if:NT \l__exsheets_questions_use_bool { - \prop_gput:NVV \g__exsheets_questions_used_prop + \prop_gput:NVV \g__exsheets_questions_id_prop \l__exsheets_questions_id_tl \g__exsheets_questions_id_int - \int_gincr:N \g__exsheets_questions_used_int + \bool_if:NT \l__exsheets_questions_use_bool + { + \prop_gput:NVV \g__exsheets_questions_used_prop + \l__exsheets_questions_id_tl + \g__exsheets_questions_id_int + \int_gincr:N \g__exsheets_questions_used_int + } + \tl_gset:Nx \g__exsheets_questions_current_id_tl + { \tl_use:N \l__exsheets_questions_id_tl } + } + \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 } + \exp_args:Nx \SetQuestionProperties + { + 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 } + \exp_args:Nx \SetQuestionProperties + { + ref = \exp_not:N \ref { \l__exsheets_questions_label_tl } , + pageref = \exp_not:N \pageref { \l__exsheets_questions_label_tl } + } } - \tl_gset:Nx \g__exsheets_questions_current_id_tl - { \tl_use:N \l__exsheets_questions_id_tl } } % Punktevergabe: \IfNoValueTF { #2 } @@ -1062,6 +1095,7 @@ } \bool_if:NT \l__exsheets_questions_print_bool { +% \exsheets_questions_debug: \bool_if:NTF \l__exsheets_exam_bool { \tl_set_eq:NN \l__exsheets_title_tl \l__exsheets_questions_name_tl } { \tl_set_eq:NN \l__exsheets_title_tl \l__exsheets_exsheets_name_tl } @@ -1217,6 +1251,7 @@ print .bool_set:N = \l__exsheets_questions_print_bool , print .default:n = true , ID .tl_set:N = \l__exsheets_questions_id_tl , + label .tl_set:N = \l__exsheets_questions_label_tl , class .code:n = \bool_set_true:N \l__exsheets_questions_class_bool \tl_set:Nn \l__exsheets_questions_class_tl { #1 } , @@ -1251,6 +1286,11 @@ \@onlypreamble\DeclareQuestionProperty \DeclareQuestionProperty{points} +\bool_if:NT \l__exsheets_auto_label_bool + { + \DeclareQuestionProperty{ref} + \DeclareQuestionProperty{pageref} + } \NewDocumentCommand \SetQuestionProperties { m } { \exsheets_set_question_properties:n { #1 } } @@ -1345,11 +1385,8 @@ \clist_new:N \l__exsheets_include_id_clist \int_new:N \l__exsheets_include_random_int \int_zero:N \l__exsheets_include_random_int -\tl_new:N \l__exsheets_random_seed_tl -\tl_set:Nn \l__exsheets_random_seed_tl { -1 } -\newcounter {exsheets@include@random} -\cs_new:Npn \file_input_if_exist:n #1 +\cs_new:Npn \exsheets_file_input_if_exist:n #1 { \file_if_exist:nT { #1 } { \file_input:n { #1 } } } \cs_if_exist:NF \prop_length:N @@ -1379,16 +1416,16 @@ \cs_new:Npn \exsheets_include_questions:n #1 { + \bool_set_true:N \l__exsheets_select_questions_bool \seq_set_split:Nnn \l__exsheets_tmpa_seq { , } { #1 } \seq_map_inline:Nn \l__exsheets_tmpa_seq { \bool_set_true:N \l__exsheets_questions_deactivate_bool - \file_input_if_exist:n { ##1 } + \int_set_eq:NN \l__exsheets_tmpc_int \g__exsheets_questions_id_int + \exsheets_file_input_if_exist:n { ##1 } \prop_length:NN \g__exsheets_selected_questions_prop \l__exsheets_tmpa_int - \int_gsub:Nn \g__exsheets_questions_id_int - { \l__exsheets_tmpa_int } \bool_if:NT \l__exsheets_questions_debug_bool { \colorbox { exsheetsdebugcolor } @@ -1400,18 +1437,22 @@ \exsheets_par: } \bool_set_false:N \l__exsheets_questions_deactivate_bool + \int_set_eq:NN \l__exsheets_tmpd_int \g__exsheets_questions_id_int + \int_gset_eq:NN \g__exsheets_questions_id_int \l__exsheets_tmpc_int \__exsheets_select_question_random:n { ##1 } - \file_input_if_exist:n { ##1 } + \exsheets_file_input_if_exist:n { ##1 } + \int_gset_eq:NN \g__exsheets_questions_id_int \l__exsheets_tmpd_int \prop_gclear:N \g__exsheets_selected_questions_prop \clist_clear:N \l__exsheets_include_id_clist + \int_gzero:N \g__exsheets_selection_number_int } + \bool_set_false:N \l__exsheets_select_questions_bool } % options: % - IDs=<list of IDs> % - all=true|false % default when no option is given % - random=<num> -% - seed=<num> % set the seed for the random selection \keys_define:nn { exsheets / include } { all .bool_set:N = \l__exsheets_include_all_bool , @@ -1422,20 +1463,34 @@ random .code:n = \bool_set_false:N \l__exsheets_include_all_bool \bool_set_true:N \l__exsheets_include_random_bool - \int_set:Nn \l__exsheets_include_random_int { #1 } , - seed .tl_set:N = \l__exsheets_random_seed_tl + \int_set:Nn \l__exsheets_include_random_int { #1 } } +\int_new:N \g__exsheets_selection_number_int + \cs_new:Npn \__exsheets_select_question:n #1 { - \bool_if:NTF \l__exsheets_questions_deactivate_bool + \bool_if:NT \l__exsheets_select_questions_bool { - \prop_gput:Nnn \g__exsheets_selected_questions_prop - { #1 } { \__exsheets_dummy: } - } - { - \bool_if:NF \l__exsheets_include_all_bool - { \__exsheets_select_question_by_id:n { #1 } } + \bool_if:NTF \l__exsheets_questions_deactivate_bool + { + \bool_if:NT \l__exsheets_questions_use_bool + { + \int_gincr:N \g__exsheets_selection_number_int + \exp_args:NNx + \prop_gput:Nnn \g__exsheets_selected_questions_prop + { \int_use:N \g__exsheets_selection_number_int } { #1 } + } + } + { + \int_gincr:N \g__exsheets_questions_id_int + \exp_args:NNx + \prop_get:NnN \g__exsheets_questions_id_prop + { \int_use:N \g__exsheets_questions_id_int } + \l_tmpa_tl + \bool_if:NF \l__exsheets_include_all_bool + { \__exsheets_select_question_by_id:V \l_tmpa_tl } + } } } \cs_generate_variant:Nn \__exsheets_select_question:n { V } @@ -1448,6 +1503,7 @@ { \bool_gset_true:N \g__exsheets_questions_use_bool } { \bool_gset_false:N \g__exsheets_questions_use_bool } } +\cs_generate_variant:Nn \__exsheets_select_question_by_id:n { V } % TODO: don't select questions whose topics or classes aren't chosen \cs_new:Npn \__exsheets_select_question_random:n #1 @@ -1464,44 +1520,22 @@ \bool_set_true:N \l__exsheets_include_all_bool } { - \group_begin: - \WarningsOff[lcg] - \tl_set:Nx \l__exsheets_tmpa_tl { \int_use:N \l__exsheets_tmpa_int } - \reinitrand - [ - first = 1 , - last = \l__exsheets_tmpa_tl , - counter = exsheets@include@random , - seed = \l__exsheets_random_seed_tl , - quiet = y - ] - \int_zero:N \l__exsheets_tmpa_int - \int_do_while:nNnn \l__exsheets_tmpa_int < \l__exsheets_include_random_int - { - \rand - \int_zero:N \l__exsheets_tmpb_int - \prop_map_inline:Nn \g__exsheets_selected_questions_prop - { - \int_incr:N \l__exsheets_tmpb_int - \int_compare:nT - { \l__exsheets_tmpb_int = \value{exsheets@include@random} } - { - \tl_set_rescan:Nnn \l__exsheets_tmpa_tl {} { ##1 } - \clist_if_in:NVTF \l__exsheets_include_id_clist \l__exsheets_tmpa_tl - { \int_decr:N \l__exsheets_tmpb_int } - { - \clist_gput_right:NV \l__exsheets_include_id_clist - \l__exsheets_tmpa_tl - \prop_map_break: - } - } - } - \clist_remove_duplicates:N \l__exsheets_include_id_clist - \int_set:Nn \l__exsheets_tmpa_int - { \clist_count:N \l__exsheets_include_id_clist } - } - \WarningsOn[lcg] - \group_end: + \int_zero:N \l__exsheets_tmpb_int + \int_do_while:nn { \l__exsheets_tmpb_int < \l__exsheets_include_random_int } + { + \pgfmathparse { random(\int_use:N \l__exsheets_tmpa_int) } + \tl_set_eq:NN \l__exsheets_tmpa_tl \pgfmathresult + \prop_get:NVN \g__exsheets_selected_questions_prop + \l__exsheets_tmpa_tl + \l__exsheets_tmpb_tl + \clist_if_in:NVF \l__exsheets_include_id_clist \l__exsheets_tmpb_tl + { + \clist_put_right:NV + \l__exsheets_include_id_clist + \l__exsheets_tmpb_tl + \int_incr:N \l__exsheets_tmpb_int + } + } } } } @@ -2040,12 +2074,11 @@ % ---------------------------------------------------------------------------- % the `tasks' list -\input { exsheets_tasks.def } -\bool_if:NT \l__exsheets_load_tasks_bool - { - \RequirePackage { amssymb } - \input { exsheets_tasks.cfg } - } +\bool_if:NTF \l__exsheets_load_tasks_bool + { \RequirePackage [ more ] { tasks } } + { \RequirePackage { tasks } } +\AddCounterPattern* [ tasks ] { question } { qu } +\ReadCounterFrom [ tasks ] { question } \l__exsheets_counter_qu_int % ---------------------------------------------------------------------------- % the \blank{<words>} command @@ -2365,9 +2398,17 @@ HISTORY: 2012/12/23 v0.6a - bug fix: labels and items of {tasks} weren't joined at their baselines 2013/01/06 v0.6b - bug fix: ID counting fixed in \includequestions +2013/01/19 v0.7 - extracted `tasks' environment into standalone package; + this also lead to a slightly new syntax and a few new + options for it + - changed internals for random selection of questions: + uses `pgf' instead of `lcg' and seems to be more reliable + than before +2013/01/21 v0.7a - added option `auto-label' and questions key `label', + also added question properties `ref' and `pageref' + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % TODO: - points/decimal-marker, points/frac (?), points/format (?,im interface) -- bug in {tasks} in {solution}: label werden nicht richtig upgedatet! -- bug: counter-format=se.qu und \begin{solution}[print]
\ No newline at end of file +- rewrite random selection |