tikz.dev / tcolorbox Manual

The tcolorbox package

The Core Package

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}{⟨file name⟩}
    ⟨environment content⟩
    \end{tcbverbatimwrite}

  • Saves the ⟨environment content⟩ to a file named by ⟨file name⟩. macros inside the environment are not expanded.

    Compiled output

    \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}

    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}.

    Compiled output

    \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}
  • \tcbusetemp

  • Loads the current temporary file which was saved by tcbwritetemp.

  • /tcb/verbatim ignore percent=true|false(default true, initially false)New: 2017-07-05

  • If this option is set to be true, the percent sign % is silently ignored for tcbverbatimwrite and all macros and environments which are built using tcbverbatimwrite, e. g. tcbwritetemp, tcblisting, or dispExample. This option may be useful for creating some special effects, but mainly it is intended to be applied for documentation with DocStrip. The creation of this option was motivated by Yudai Nakata. Note that this option is not getting reset by /tcb/reset.

    Compiled output

    Normal usage:
    \begin{tcbwritetemp}
    %\begin{center}\bfseries
    This is my text.
    %\end{center}
    \end{tcbwritetemp}

    \tcbusetemp

    \tcbset{verbatim ignore percent}
    \bigskip Option applied:
    \begin{tcbwritetemp}
    %\begin{center}\bfseries
    This is my text.
    %\end{center}
    \end{tcbwritetemp}

    \tcbusetemp

    Note that every percent sign is removed, also escaped ones.

    Compiled output

    % \tcbuselibrary{listings}
    \def\percent{\%}

    \begin{tcblisting}{title=Normal}
    %\begin{center}\bfseries
    This is my 5\percent\ text
    and this is my 10\% text.
    %\end{center}
    \end{tcblisting}

    \begin{tcblisting}{
    title=Option applied,
    verbatim ignore percent}
    %\begin{center}\bfseries
    This is my 5\percent\ text
    and this is my 10\% text.
    %\end{center}
    \end{tcblisting}