| 1 |
% !TeX root = tcolorbox.tex |
| 2 |
% include file of tcolorbox.tex (manual of the LaTeX package tcolorbox) |
| 3 |
\clearpage |
| 4 |
\section{Saving and Loading of Verbatim Texts}% |
| 5 |
\tcbset{external/prefix=external/verbatim_}% |
| 6 |
The following macros are slightly modified versions of the original macros |
| 7 |
from the known packages \refPkg{moreverb} and \refPkg{verbatim}. |
| 8 |
They are used implicitly inside of a |tcolorbox| environment, |
| 9 |
but they can be used outside also. |
| 10 |
\enlargethispage*{1.5cm} |
| 11 |
|
| 12 |
\begin{docEnvironment}{tcbverbatimwrite}{\marg{file name}} |
| 13 |
Saves the \meta{environment content} to a file named by \meta{file name}. |
| 14 |
\TeX\ macros inside the environment are not expanded. |
| 15 |
\begin{dispExample} |
| 16 |
\begin{tcbverbatimwrite}{\jobname_verbexp.tex} |
| 17 |
This text is saved \textit{as is}. |
| 18 |
\end{tcbverbatimwrite} |
| 19 |
|
| 20 |
Now, we are using the file:\par |
| 21 |
\input{\jobname_verbexp.tex} |
| 22 |
\end{dispExample} |
| 23 |
|
| 24 |
This environment may be used inside an own environment. Note, that inside |
| 25 |
the environment definition |\tcbverbatimwrite| has to be used instead of |
| 26 |
|\begin{tcbverbatimwrite}| and |\endtcbverbatimwrite| instead of |\end{tcbverbatimwrite}|. |
| 27 |
\begin{dispExample} |
| 28 |
\newenvironment{myverbatim}{% |
| 29 |
\begingroup\tcbverbatimwrite{\jobname_myverb.tex}}% |
| 30 |
{\endtcbverbatimwrite\endgroup} |
| 31 |
|
| 32 |
\begin{myverbatim} |
| 33 |
This is the text which is saved by my own environment. |
| 34 |
\end{myverbatim} |
| 35 |
|
| 36 |
Now, we are using the file:\par |
| 37 |
\input{\jobname_myverb.tex} |
| 38 |
\end{dispExample} |
| 39 |
\end{docEnvironment} |
| 40 |
|
| 41 |
\begin{docEnvironment}{tcbwritetemp}{} |
| 42 |
Has the same function as \refEnv{tcbverbatimwrite}, but uses the key value |
| 43 |
of \refKey{/tcb/tempfile} for the file name. |
| 44 |
\begin{dispExample} |
| 45 |
\begin{tcbwritetemp} |
| 46 |
This text is saved \textit{as is}. |
| 47 |
\end{tcbwritetemp} |
| 48 |
|
| 49 |
Now, we are using the file:\par |
| 50 |
\tcbusetemp |
| 51 |
\end{dispExample} |
| 52 |
\end{docEnvironment} |
| 53 |
|
| 54 |
|
| 55 |
\begin{docCommand}{tcbusetemp}{} |
| 56 |
Loads the current temporary file which was saved by \refEnv{tcbwritetemp}. |
| 57 |
\end{docCommand} |
| 58 |
|
| 59 |
\clearpage |
| 60 |
|
| 61 |
\begin{docTcbKey}[][doc new=2017-07-05]{verbatim ignore percent}{\colOpt{=true\textbar false}}{default |true|, initially |false|} |
| 62 |
If this option is set to be |true|, the percent sign \% is silently |
| 63 |
ignored for \refEnv{tcbverbatimwrite} and all macros and environments |
| 64 |
which are built using \refEnv{tcbverbatimwrite}, e.\,g.\ |
| 65 |
\refEnv{tcbwritetemp}, \refEnv{tcblisting}, or \refEnv{dispExample}.\par |
| 66 |
This option may be useful for creating some special effects, but mainly |
| 67 |
it is intended to be applied for documentation with DocStrip. |
| 68 |
The creation of this option was motivated by Yudai Nakata. |
| 69 |
Note that this option is not getting reset by \refKey{/tcb/reset}. |
| 70 |
\begin{dispExample*}{sidebyside} |
| 71 |
Normal usage: |
| 72 |
\begin{tcbwritetemp} |
| 73 |
%\begin{center}\bfseries |
| 74 |
This is my text. |
| 75 |
%\end{center} |
| 76 |
\end{tcbwritetemp} |
| 77 |
|
| 78 |
\tcbusetemp |
| 79 |
|
| 80 |
\tcbset{verbatim ignore percent} |
| 81 |
\bigskip Option applied: |
| 82 |
\begin{tcbwritetemp} |
| 83 |
%\begin{center}\bfseries |
| 84 |
This is my text. |
| 85 |
%\end{center} |
| 86 |
\end{tcbwritetemp} |
| 87 |
|
| 88 |
\tcbusetemp |
| 89 |
\end{dispExample*} |
| 90 |
|
| 91 |
\begin{marker} |
| 92 |
Note that \emph{every} percent sign is removed, also escaped ones. |
| 93 |
\end{marker} |
| 94 |
|
| 95 |
\begin{dispExample*}{sidebyside} |
| 96 |
% \tcbuselibrary{listings} |
| 97 |
\def\percent{\%} |
| 98 |
|
| 99 |
\begin{tcblisting}{title=Normal} |
| 100 |
%\begin{center}\bfseries |
| 101 |
This is my 5\percent\ text |
| 102 |
and this is my 10\% text. |
| 103 |
%\end{center} |
| 104 |
\end{tcblisting} |
| 105 |
|
| 106 |
\begin{tcblisting}{ |
| 107 |
title=Option applied, |
| 108 |
verbatim ignore percent} |
| 109 |
%\begin{center}\bfseries |
| 110 |
This is my 5\percent\ text |
| 111 |
and this is my 10\% text. |
| 112 |
%\end{center} |
| 113 |
\end{tcblisting} |
| 114 |
\end{dispExample*} |
| 115 |
|
| 116 |
\end{docTcbKey} |
| 117 |
|
| 118 |
\clearpage |
| 119 |
|
| 120 |
\begin{docTcbKey}[][doc new=2023-02-10]{verbatim ignore indention at end}{\colOpt{=true\textbar false}}{default |true|, initially |true|} |
| 121 |
If this option is set to be |true|, spaces and tabs before |\end{tcbverbatimwrite}| |
| 122 |
on the same line are ignored. The same is true for all environments based |
| 123 |
on \refEnv{tcbverbatimwrite}. If anything else precedes |\end{tcbverbatimwrite}| |
| 124 |
on the same line, the complete content is written.\par |
| 125 |
If this option is set to be |false|, everything preceding |\end{tcbverbatimwrite}| |
| 126 |
is written. This was the default behavior before version 6.0.0.\par |
| 127 |
The idea of \refKey{/tcb/verbatim ignore indention at end} is that the |
| 128 |
environment can be indented. The creation of this option was inspired by Yukai Chou. |
| 129 |
|
| 130 |
\begin{dispExample} |
| 131 |
% \tcbuselibrary{minted} |
| 132 |
\texttt{verbatim ignore indention at end=false} |
| 133 |
|
| 134 |
\begin{tcblisting}{listing engine=minted, listing only, |
| 135 |
verbatim ignore indention at end=false} |
| 136 |
int a; |
| 137 |
\end{tcblisting} |
| 138 |
|
| 139 |
\begin{tcblisting}{listing engine=minted, listing only, |
| 140 |
verbatim ignore indention at end=false} |
| 141 |
int a; |
| 142 |
int b; \end{tcblisting} |
| 143 |
|
| 144 |
\texttt{verbatim ignore indention at end=true} |
| 145 |
|
| 146 |
\begin{tcblisting}{listing engine=minted, listing only, |
| 147 |
verbatim ignore indention at end} |
| 148 |
int a; |
| 149 |
\end{tcblisting} |
| 150 |
|
| 151 |
\begin{tcblisting}{listing engine=minted, listing only, |
| 152 |
verbatim ignore indention at end} |
| 153 |
int a; |
| 154 |
int b; \end{tcblisting} |
| 155 |
\end{dispExample} |
| 156 |
\end{docTcbKey} |