10 为什么在\AtEndDocument后的代码,运行后不能成功显示

发布于 2024-08-06 08:03:48

请问大佬,为什么在\AtEndDocument后的代码,运行后不能成功显示

\documentclass{ctexart}
\usepackage{xcolor,tasks,xeCJKfntef}

\ExplSyntaxOn
\seq_new:N \l_fillin_count_seq

\NewDocumentCommand{\fillin}{+m}
 {
   \textcolor{red}{\CJKunderline{#1}}
   \seq_gput_right:Nn \l_fillin_count_seq {#1}
}


\AtEndDocument{
    \newcommand{\printanswers}{
    \newpage
    \section*{填空题答案}
    \begin{tasks}(4)
    \seq_map_inline:Nn \l_fillin_count_seq {
        \task ##1
    }
    \end{tasks}
    }
    \printanswers
}
\ExplSyntaxOff

\begin{document}
这是1 \fillin{这是1}

这是2 \fillin{这是2}

这是3 \fillin{这是3}

这是4 \fillin{这是4}

这是5 \fillin{这是5}
\end{document}

查看更多

关注者
0
被浏览
309
鱼香肉丝没有鱼先生
鱼香肉丝没有鱼先生.

还是展开问题,tasks 环境内部以 \task 这个 token 作为分隔符, \task 本身并没有被定义, 所以当 tasks 环境读取的时候遇到

\seq_map_inline:Nn \l_fillin_count_seq
{
  \task ##1
}

时, 它没有找到 \task(注意这里的 \task 在 group 内部), 于是就会抛出警告, 且没有解析到 item.

解决办法是先展开

\seq_map_inline:Nn \l_fillin_count_seq
{
  \task ##1
}

\task xxx
\task xxx
\task xxxx
...
\documentclass{ctexart}
\usepackage{xcolor,tasks,xeCJKfntef}

\ExplSyntaxOn
\seq_new:N \l_fillin_count_seq

\NewDocumentCommand{\fillin}{+m}
 {
   \textcolor{red}{\CJKunderline{#1}}
   \seq_gput_right:Nn \l_fillin_count_seq {#1}
}

\AtEndDocument{
    \newcommand{\printanswers}{
    \newpage
    \section*{填空题答案}

      \seq_map_inline:Nn \l_fillin_count_seq
      {
        \tl_put_right:Nn \l_tmpa_tl { \task ##1 }
      }

      \use:e
      {
        \exp_not:n { \begin{tasks}(4) }
          \exp_not:V \l_tmpa_tl
        \exp_not:n { \end{tasks} }
      }
    }
    \printanswers
}
\ExplSyntaxOff

\begin{document}
这是1 \fillin{这是1}

这是2 \fillin{这是2}

这是3 \fillin{这是3}

这是4 \fillin{这是4}

这是5 \fillin{这是5}
\end{document}
2 个回答
o(∩_∩)o
o(∩_∩)o 2024-08-06
这家伙很懒,什么也没写!

佬,还有两个问题
第一个是,组内是\task被花括号包裹在里面的意思吗?
第二个是,没有解析到item是什么意思呀?
第三个是,查了interface3\exp_not:V还是不太明白
麻烦了

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览