summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tcolorbox/tcolorbox.doc.verbatim.tex
blob: b2228a7b6a522656487a9f7279711fd35692e4d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
% !TeX root = tcolorbox.tex
% include file of tcolorbox.tex (manual of the LaTeX package tcolorbox)
\clearpage
\section{Saving and Loading of Verbatim Texts}%
\tcbset{external/prefix=external/verbatim_}%
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.
\enlargethispage*{1.5cm}

\begin{docEnvironment}{tcbverbatimwrite}{\marg{file name}}
  Saves the \meta{environment content} to a file named by \meta{file name}.
  \TeX\ macros inside the environment are not expanded.
\begin{dispExample}
\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}
\end{dispExample}

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}|.
\begin{dispExample}
\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}
\end{dispExample}
\end{docEnvironment}

\begin{docEnvironment}{tcbwritetemp}{}
  Has the same function as \refEnv{tcbverbatimwrite}, but uses the key value
  of |tempfile| for the file name.
\begin{dispExample}
\begin{tcbwritetemp}
  This text is saved \textit{as is}.
\end{tcbwritetemp}

Now, we are using the file:\par
\tcbusetemp
\end{dispExample}
\end{docEnvironment}


\begin{docCommand}{tcbusetemp}{}
  Loads the current temporary file which was saved by \refEnv{tcbwritetemp}.
\end{docCommand}

\clearpage

\begin{docTcbKey}[][doc new=2017-07-05]{verbatim ignore percent}{\colOpt{=true\textbar false}}{default |true|, initially |false|}
  If this option is set to be |true|, the percent sign \% is silently
  ignored for \refEnv{tcbverbatimwrite} and all macros and environments
  which are built using \refEnv{tcbverbatimwrite}, e.g.\ 
  \refEnv{tcbwritetemp}, \refEnv{tcblisting}, or \refEnv{dispExample}.\par
  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 \refKey{/tcb/reset}.
\begin{dispExample*}{sidebyside}
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
\end{dispExample*}

\begin{marker}
Note that \emph{every} percent sign is removed, also escaped ones.
\end{marker}

\begin{dispExample*}{sidebyside}
% \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}
\end{dispExample*}

\end{docTcbKey}

\clearpage

\begin{docTcbKey}[][doc new=2023-02-10]{verbatim ignore indention at end}{\colOpt{=true\textbar false}}{default |true|, initially |true|}
  If this option is set to be |true|, spaces and tabs before |\end{tcbverbatimwrite}|
  on the same line are ignored. The same is true for all environments based
  on \refEnv{tcbverbatimwrite}. If anything else precedes |\end{tcbverbatimwrite}|
  on the same line, the complete content is written.\par
  If this option is set to be |false|, everything preceding |\end{tcbverbatimwrite}|
  is written. This was the default behavior before version 6.0.0.\par
  The idea of \refKey{/tcb/verbatim ignore indention at end} is that the
  environment can be indented. The creation of this option was inspired by Yukai Chou.

\begin{dispExample}
% \tcbuselibrary{minted}
\texttt{verbatim ignore indention at end=false}

    \begin{tcblisting}{listing engine=minted, listing only,
                       verbatim ignore indention at end=false}
      int a;
    \end{tcblisting}

    \begin{tcblisting}{listing engine=minted, listing only,
                       verbatim ignore indention at end=false}
      int a;
      int b;  \end{tcblisting}

\texttt{verbatim ignore indention at end=true}

    \begin{tcblisting}{listing engine=minted, listing only,
                       verbatim ignore indention at end}
      int a;
    \end{tcblisting}

    \begin{tcblisting}{listing engine=minted, listing only,
                       verbatim ignore indention at end}
      int a;
      int b;  \end{tcblisting}
\end{dispExample}
\end{docTcbKey}