![Xparse で生成されたリストを「セクションのような」環境で分割するにはどうすればよいですか?](https://rvso.com/image/335479/Xparse%20%E3%81%A7%E7%94%9F%E6%88%90%E3%81%95%E3%82%8C%E3%81%9F%E3%83%AA%E3%82%B9%E3%83%88%E3%82%92%E3%80%8C%E3%82%BB%E3%82%AF%E3%82%B7%E3%83%A7%E3%83%B3%E3%81%AE%E3%82%88%E3%81%86%E3%81%AA%E3%80%8D%E7%92%B0%E5%A2%83%E3%81%A7%E5%88%86%E5%89%B2%E3%81%99%E3%82%8B%E3%81%AB%E3%81%AF%E3%81%A9%E3%81%86%E3%81%99%E3%82%8C%E3%81%B0%E3%82%88%E3%81%84%E3%81%A7%E3%81%99%E3%81%8B%3F.png)
私は主に、xparse
整理されたリストを作成するためにライブラリを使用します。以下は MWE です。
\documentclass{article}
\usepackage{xparse}
\newcounter{quest}
\newcommand{\quest}{\noindent\stepcounter{quest}{\bf Q}{\bf \arabic{quest}.\ }}
\ExplSyntaxOn
\NewDocumentCommand{\answer}{ m }{ \malmedal_input_add:n { #1 } }
\NewDocumentCommand{\listanswers}{ }{ \malmedal_output_direct: }
\seq_new:N \g_malmedal_input_seq
\seq_new:N \l_malmedal_temp_seq
\int_new:N \l_malmedal_count_int
\cs_new:Npn \malmedal_input_add:n #1
{
\seq_gput_right:Nn \g_malmedal_input_seq { #1 }
}
\cs_new_protected:Npn \malmedal_output_direct:
{
\int_zero:N \l_malmedal_count_int
\seq_map_inline:Nn \g_malmedal_input_seq
{
\int_incr:N \l_malmedal_count_int
\malmedal_print:n { ##1 }
}
}
\cs_new:Npn \malmedal_print:n #1
{
\noindent{\textbf{Question } ~ \bfseries\int_to_arabic:n { \l_malmedal_count_int }} ~ : ~ #1 \par
}
\ExplSyntaxOff
\begin{document}
\section{Math}
\quest $1 + 1 = ?$
\answer{$2$.}
\quest If $a = 2$ and $b = 5$, then $a - b = ?$
\answer{$-3$.}
\quest Are there any natural numbers between $8$ and $9$?
\answer{No.}
\section{Physics}
\quest What's the speed of light in vacuum?
\answer{$\approx 3\cdot 10^8$ m/s}
\quest Name one thing one can't do without atmospheric pressure.
\answer{To drink water with a straw.}
\section{Answer Key}
\listanswers
\end{document}
これにより、次が生成されます。
以下のように、生成されたリストをセクションごとに分割する方法があるかどうか疑問に思いました。
そして、もしあなたが協力したいのであれば、ただ単に「回答キーを生成するもっと簡単な方法がある」と言うだけではいけません。xparse パッケージ内のソリューションが必要です。ありがとうございます!