filecontents
有没有一种等效的方法可以在不使用 TeX 原语的情况下将我的环境主体写入文件?
morewrites
或filecontents
限制
我怀疑这些包不能很好地协同工作。使用filecontents
下面显示的包中的成对宏,我可以将环境的内容(主体)写入名为的文件tmp.tex
:
\@tempswafalse\filec@ntents{tmp}
结尾
\endfilecontents
对于我的项目的另一部分,我用完了写入,因此我添加了\usepackage{morewrites}
。这适用于我的 TeX 原始写入,但在使用包时没有帮助filecontents
。
示例代码:
写得太多...
\documentclass{article}
\usepackage{etoolbox}
\usepackage{xcolor}
\usepackage{verbatimbox}
\usepackage{tikz}
\usepackage{filecontents}
\usepackage{morewrites}% Does not support extend filecontents package, limited \@tempswafalse\filec@ntents{tmp} writes
% I tried putting this into a loop, but I failed
\newwrite\writeA
\newwrite\writeB
\newwrite\writeC
\newwrite\writeD
\newwrite\writeE
\newwrite\writeF
\newwrite\writeG
\newwrite\writeH
\newwrite\writeI
\newwrite\writeJ
\newwrite\writeK
\newwrite\writeL % Comment this out to compile, one too many writes
%\newwrite\writeM
%\newwrite\writeN
%\newwrite\writeO
%\newwrite\writeP
%\newwrite\writeQ
%\newwrite\writeR
% Environments
\makeatletter
\newenvironment{environment}[2]
{\gdef\environame{#1}\gdef\envirodescription{#2}%
\@tempswafalse\filec@ntents{tmp}
}%
{\endfilecontents}
\makeatother
\AfterEndEnvironment{environment}{\setenviro}
\newcommand\setenviro{%
\def\hrulespacedist{2mm}
\vspace{\hrulespacedist}\hrule\vspace{\hrulespacedist}
\texttt{\environame}
\hfill
\begin{minipage}[t]{.75\textwidth}
\envirodescription
\end{minipage}\par\bigskip
\textcolor{green!30!black}{\textbf{Example:}}\par\bigskip
\input{tmp}
\par\bigskip
\textcolor{red!80!black}{\textbf{Code:}}\par\bigskip
\verbfilebox[\footnotesize]{tmp}
\theverbbox
\vspace{\hrulespacedist}\hrule\vspace{\hrulespacedist}
}
\begin{document}
\begin{environment}{enumerate}{An enumerated/numbered list.}
\begin{enumerate}
\item First item
\end{enumerate}
\end{environment}
\end{document}
输出
有关的
答案1
似乎需要同时写入 17 个文件有点奇怪,但无论如何,我认为你可以在 morewrites 开始重新定义事物之前让 filecontents 使用固定的写入流:
\documentclass{article}
\usepackage{etoolbox}
\usepackage{xcolor}
\usepackage{verbatimbox}
\usepackage{tikz}
\usepackage{filecontents}
\newwrite\fcwrite
\makeatletter
\let\zzzz\filec@ntents
\def\filec@ntents{\def\chardef##1\write{\let\reserved@c\fcwrite}\zzzz}
\makeatother
\usepackage{morewrites}% Does not support extend filecontents package, limited \@tempswafalse\filec@ntents{tmp} writes
% I tried putting this into a loop, but I failed
\newwrite\writeA
\newwrite\writeB
\newwrite\writeC
\newwrite\writeD
\newwrite\writeE
\newwrite\writeF
\newwrite\writeG
\newwrite\writeH
\newwrite\writeI
\newwrite\writeJ
\newwrite\writeK
\newwrite\writeL % Comment this out to compile, one too many writes
\newwrite\writeM
\newwrite\writeN
\newwrite\writeO
\newwrite\writeP
\newwrite\writeQ
\newwrite\writeR
% Environments
\makeatletter
\newenvironment{environment}[2]
{\gdef\environame{#1}\gdef\envirodescription{#2}%
\@tempswafalse\filec@ntents{tmp}
}%
{\endfilecontents}
\makeatother
\AfterEndEnvironment{environment}{\setenviro}
\newcommand\setenviro{%
\def\hrulespacedist{2mm}
\vspace{\hrulespacedist}\hrule\vspace{\hrulespacedist}
\texttt{\environame}
\hfill
\begin{minipage}[t]{.75\textwidth}
\envirodescription
\end{minipage}\par\bigskip
\textcolor{green!30!black}{\textbf{Example:}}\par\bigskip
\input{tmp}
\par\bigskip
\textcolor{red!80!black}{\textbf{Code:}}\par\bigskip
\verbfilebox[\footnotesize]{tmp}
\theverbbox
\vspace{\hrulespacedist}\hrule\vspace{\hrulespacedist}
}
\begin{document}
\begin{environment}{enumerate}{An enumerated/numbered list.}
\begin{enumerate}
\item First item
\end{enumerate}
\end{environment}
\end{document}