我已经建立了一个结构如下的文档
\documentclass[a4paper,12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{exsheets}
\usepackage{tasks}
\newcommand{\righty}{$\checkmark$}
\newcommand{\checky}{$\Box$}
\SetupExSheets{counter-format=se.qu,counter-within=section}
\settasks{label={\checky}}
\begin{document}
\begin{question}
How much do you like your teacher?
\begin{tasks}
\task[\righty] I'm indifferent to this
\task I hate them to death
...
\end{tasks}
\end{question}
\end{document}
如您所见,此文档目前正在生成问题的答案。我现在想添加一个开关来生成未回答的问题,将任务环境中的项目随机化。
如果不改变当前结构,这样的事情是否可行?我的文档中大约有 250 个问题,因此最好不要改变每个问题,但最佳实践总是值得赞赏的。对于这种请求,我很抱歉,但我对此类任务还很陌生,不知道从哪里开始。
答案1
添加开关非常简单:
\newif\ifanswers
% \answerstrue % uncomment to display answers
\newcommand{\righty}{\ifanswers$\checkmark$\else\checky\fi}
这样,您只需要\answerstrue
对文档的两个版本进行注释或取消注释。
对环境中的项目进行混洗tasks
也不是那么困难,尽管这是一种黑客行为,因为它需要重新定义tasks
内部。请注意,每次重新编译时,顺序都会发生不同的变化:
\ExplSyntaxOn
\cs_set_protected:Npn \tasks_environment:nnnn #1#2#3#4
{
\bool_if:NT \l__tasks_debug_bool { \dim_set:Nn \fboxsep {0pt} }
\seq_set_split:Nnn \l__tasks_seq {#3} {#4}
\seq_pop_left:NN \l__tasks_seq \l__tasks_tmpa_tl
\seq_shuffle:N \l__tasks_seq % <<< this is added
\tl_if_blank:VF \l__tasks_tmpa_tl
{ \msg_warning:nnVn {tasks}{no-item} \l__tasks_tmpa_tl {#3} }
\int_gset:Nn \g__tasks_total_items_int
{ \seq_count:N \l__tasks_seq }
\UseInstance {tasks} {#1}
{ \g__tasks_total_items_int }
{#2}
{ }
\seq_clear:N \l__tasks_seq
}
\ExplSyntaxOff
完整示例:
\documentclass[a4paper,12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amssymb}
\usepackage{exsheets}
\usepackage{tasks}
\newif\ifanswers
% \answerstrue % uncomment to display answers
\newcommand{\righty}{\ifanswers$\checkmark$\else\checky\fi}
\newcommand{\checky}{$\Box$}
\SetupExSheets{counter-format=se.qu,counter-within=section}
\settasks{label={\checky}}
\ExplSyntaxOn
\cs_set_protected:Npn \tasks_environment:nnnn #1#2#3#4
{
\bool_if:NT \l__tasks_debug_bool { \dim_set:Nn \fboxsep {0pt} }
\seq_set_split:Nnn \l__tasks_seq {#3} {#4}
\seq_pop_left:NN \l__tasks_seq \l__tasks_tmpa_tl
\seq_shuffle:N \l__tasks_seq % <<< this is added
\tl_if_blank:VF \l__tasks_tmpa_tl
{ \msg_warning:nnVn {tasks}{no-item} \l__tasks_tmpa_tl {#3} }
\int_gset:Nn \g__tasks_total_items_int
{ \seq_count:N \l__tasks_seq }
\UseInstance {tasks} {#1}
{ \g__tasks_total_items_int }
{#2}
{ }
\seq_clear:N \l__tasks_seq
}
\ExplSyntaxOff
\begin{document}
\begin{question}
How much do you like your teacher?
\begin{tasks}
\task[\righty] I'm indifferent to this
\task I hate them to death
\task What is Love?
\task I have a crush.
\end{tasks}
\end{question}
\end{document}