刚造完一个,,,还是用楼上的吧
\documentclass{article}
\ExplSyntaxOn
\clist_new:N \g_tags_clist
\clist_new:N \g_contents_clist
\cs_new:Npn \__tagit:n #1 {
\clist_gput_right:Nn \g_tags_clist { { #1 } }
}
\NewDocumentCommand{\tagit}{}{\__tagit:n}
\newcounter{problem}
\NewDocumentEnvironment{problem}{+b}{
\stepcounter{problem}
\clist_gput_right:Nn \g_contents_clist {\exp_not:N\begin{problem} #1 \exp_not:N\end{problem} }
#1
}{}
\iow_new:N \g_tags_file
\cs_new:Npn \__print_by_tag:n #1 {
\tl_clear:N \l_tmpa_tl
\int_step_inline:nn { \the\value{problem} } {
\exp_args:Ne \clist_if_in:nnT
{ \clist_item:Nn \g_tags_clist { ##1 } }
{ #1 }
{
\tl_put_right:Ne \l_tmpa_tl { \clist_item:Nn \g_contents_clist { ##1 } }
}
}
\iow_open:Nn \g_tags_file { \jobname-#1.tex }
\iow_now:Ne \g_tags_file { \l_tmpa_tl }
\iow_close:N \g_tags_file
}
\NewDocumentCommand{\printByTag}{}{\__print_by_tag:n}
\ExplSyntaxOff
\begin{document}
\begin{problem}
aa
\tagit{tag1, tag2, tag3}
\end{problem}
\begin{problem}
aa
\tagit{tag2, tag3}
\end{problem}
\begin{problem}
aa
\tagit{tag1, tag2, tag3}
\end{problem}
\printByTag{tag1}
\end{document}
问 如何给题库中的题目打标签?