summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/tcolorbox/tcblistings.code.tex
blob: 90402d26999eacae16e65af83558c4883fee91f3 (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
%% The LaTeX package tcolorbox - version 1.30 (2012/04/20)
%% tcblistings.code.tex: Code for colorboxes with listings
%%
%% -------------------------------------------------------------------------------------------
%% Copyright (c) 2006-2012 by Prof. Dr. Dr. Thomas F. Sturm <thomas dot sturm at unibw dot de>
%% -------------------------------------------------------------------------------------------
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status `author-maintained'.
%%
%% This work consists of all files listed in README
%%
\makeatletter
\def\tcblibrary@listings@loaded{}

\RequirePackage{listings}[2007/02/22]

\lstdefinestyle{tcblatex}{language={[LaTeX]TeX},
     aboveskip={0\p@ \@plus 6\p@}, belowskip={0\p@ \@plus 6\p@},
     columns=fullflexible, keepspaces=true,
     breaklines=true, breakatwhitespace=true,
     basicstyle=\ttfamily\small, extendedchars=true, nolol
     }

\def\tcbuselistingtext{\input{\kvtcb@listingfile}}%

\def\tcbuselistinglisting{%
  \toks@=\expandafter{\kvtcb@listingoptions}%
  \edef\tcb@temp{\noexpand\lstinputlisting[\the\toks@]}%
  \tcb@temp{\kvtcb@listingfile}%
}%

\def\tcb@listing@listingAndText{%
   \tcbuselistinglisting%
   \tcblower%
   \tcbuselistingtext%
}

\def\tcb@listing@listingAndComment{%
   \tcbuselistinglisting%
   \tcblower%
   \kvtcb@listingcomment%
}

\def\tcb@listing@textAndListing{%
   \tcbuselistingtext%
   \tcblower%
   \tcbuselistinglisting%
}

\def\tcb@listing@commentAndListing{%
   \kvtcb@listingcomment%
   \tcblower%
   \tcbuselistinglisting%
}

\tcbset{
  listing file/.store in=\kvtcb@listingfile,
  listing options/.store in=\kvtcb@listingoptions,
  comment/.store in=\kvtcb@listingcomment,
  listing style/.style={listing options={style=#1}},
  listing and text/.code={\let\tcp@listing@process\tcb@listing@listingAndText},
  text and listing/.code={\let\tcp@listing@process\tcb@listing@textAndListing},
  listing and comment/.code={\let\tcp@listing@process\tcb@listing@listingAndComment},
  comment and listing/.code={\let\tcp@listing@process\tcb@listing@commentAndListing},
  listing only/.code={\let\tcp@listing@process\tcbuselistinglisting},
  text only/.code={\let\tcp@listing@process\tcbuselistingtext},
}

\tcbset{
  listing file=\jobname.listing,
  listing style=tcblatex,
  comment=,
  listing and text,
}

\newenvironment{tcblisting}[1]{%
  \def\tcblisting@box{\begin{tcolorbox}[#1]\tcp@listing@process\end{tcolorbox}}%
  \begingroup\tcbverbatimwrite{\kvtcb@listingfile}%
}{\endtcbverbatimwrite\endgroup%
  \tcblisting@box%
}

\def\tcbinputlisting#1{%
  \begin{tcolorbox}[#1]\tcp@listing@process\end{tcolorbox}%
}

\newenvironment{tcboutputlisting}{%
  \begingroup\tcbverbatimwrite{\kvtcb@listingfile}%
}{\endtcbverbatimwrite\endgroup}

\def\tcbusetemplisting{%
  \toks@=\expandafter{\kvtcb@listingoptions}%
  \edef\tcb@temp{\noexpand\lstinputlisting[\the\toks@]}%
  \tcb@temp{\kvtcb@tempfile}%
}%