You are on page 1of 2

7

Saving and Loading of Verbatim Texts

The following macros are slightly modified versions of the original macros from the known
packages moreverb and verbatim. They are used implicitly inside of a tcolorbox environment,
but they can be used outside also.
\begin{tcbverbatimwrite}{hfile namei}
henvironment contenti
\end{tcbverbatimwrite}
Saves the henvironment contenti to a file named by hfile namei. TEX macros inside the
environment are not expanded.
\begin{tcbverbatimwrite}{\jobname_verbexp.tex}
This text is saved \textit{as is}.
\end{tcbverbatimwrite}
Now, we are using the file:\par
\input{\jobname_verbexp.tex}
Now, we are using the file:
This text is saved as is.

This environment may be used inside an own environment. Note, that inside the environment definition \tcbverbatimwrite has to be used instead of \begin{tcbverbatimwrite}
and \endtcbverbatimwrite instead of \end{tcbverbatimwrite}.
\newenvironment{myverbatim}{%
\begingroup\tcbverbatimwrite{\jobname_myverb.tex}}%
{\endtcbverbatimwrite\endgroup}
\begin{myverbatim}
This is the text which is saved by my own environment.
\end{myverbatim}
Now, we are using the file:\par
\input{\jobname_myverb.tex}
Now, we are using the file:
This is the text which is saved by my own environment.

\begin{tcbwritetemp}
henvironment contenti
\end{tcbwritetemp}
Has the same function as tcbverbatimwrite, but uses the key value of tempfile for the
file name.
\begin{tcbwritetemp}
This text is saved \textit{as is}.
\end{tcbwritetemp}
Now, we are using the file:\par
\tcbusetemp
Now, we are using the file:
This text is saved as is.

\tcbusetemp
Loads the current temporary file which was saved by tcbwritetemp.

118

Recording

The package provides some macros and options to take records during compilation. This is
done by LATEX file operations to save some data to a file for later usage. The main application
scenario is depicted in Section 8.3 on the next page where information about example solutions
is recorded and read again in Section 8.4 on page 123.

8.1

Makros

N 2014-11-28

\tcbstartrecording[hfile namei]
Opens a file denoted by hfile namei for writing the records. The default file name is
\jobname.records. See Section 8.3 on the next page for an example application.

N 2014-11-28

\tcbrecord{hcontenti}
Records any hcontenti to the record file. \tcbrecord is implemented as \immediate\write.
\tcbstartrecording has to be called before; otherwise, \tcbrecord is silently ignored.
\tcbrecord{\string\solution{\thetcbcounter}{solutions/exercise-\thetcbcounter.tex}}

N 2014-11-28

\tcbstoprecording
Closes the current record file which was opened by \tcbstartrecording before.

N 2014-11-28

\tcbinputrecords[hfile namei]
Opens a file denoted by hfile namei for reading the records via \input. The default file
name is the name of the last used record file for saving. \tcbstoprecording has to be
called before.

8.2
N 2014-11-28

Options

/tcb/record=hcontenti
(style, no default)
Records any hcontenti to the record file, see \tcbrecord. This key can be used several
times to write several lines.
record={\string\solution{\thetcbcounter}{solutions/exercise-\thetcbcounter.tex}}

N 2014-11-28

/tcb/no recording
Disables \tcbrecord and /tcb/record inside the current group.

119

You might also like