\newenvironment 中の filecontents のファイル名の指定

Re: \newenvironment 中の filecontents のファイル名の指定

- 北見 けん の投稿
返信数: 0
いろいろ振り回してすみません。
他のコメントでは一般化してがんばっていたのですが、
ファイルに追記するのが1、2行程度なのであれば、
次のものでもよいですね。
今回の目的だとこれが簡単でよいでしょう。

\documentclass{article}

\makeatletter
\newenvironment{question}[2]{%
\def\currfilename{#1}%
\begingroup
\filecontents{\currfilename}%
\immediate\write\reserved@c{\string\begin\string{mytcolorbox\string}[label=#1,title=#2]}
}{%
\immediate\write\reserved@c{\string\end\string{mytcolorbox\string}}%
\endfilecontents
\endgroup
\input{\currfilename}
}
\makeatother

\newenvironment{mytcolorbox}[1][]{}{}

\begin{document}

\begin{question}{q-hoge-fuga}{Title}
$E = mc^{2}$
\end{question}

\end{document}