summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tcolorbox/tcblistings.code.tex
blob: aedb6eb143501f82e7a7db9ea4577a7290a8057a (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
%% The LaTeX package tcolorbox - version 4.30 (2020/04/28)
%% tcblistings.code.tex: Code for colorboxes with listings
%%
%% -------------------------------------------------------------------------------------------
%% Copyright (c) 2006-2020 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
\tcb@set@library@version{4.30}

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

\tcbuselibrary{listings@core}

\let\tcb@listing@MakeCaption@org=\lst@MakeCaption

\def\tcb@listing@set@MakeCaption@org{%
  \let\lst@MakeCaption\tcb@listing@MakeCaption@org}
\def\tcb@listing@set@MakeCaption@empty{%
  \lst@HRefStepCounter{lstlisting}%
  \let\lst@MakeCaption\@gobble}

\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,
     inputencoding=\kvtcb@listingencoding}

\def\tcb@listing@input@listing#1#2{%
  \begingroup%
  \toks@=\expandafter{#1}%
  \edef\tcb@temp{\noexpand\lstinputlisting[nolol,\the\toks@]}%
  \tcb@listing@set@MakeCaption%
  \tcb@temp{#2}%
  \endgroup%
}%


\def\tcb@listing@uselistinglisting{%
  \tcb@listing@input@listing{\kvtcb@listingoptions}{\kvtcb@listingfile}%
}%

\def\tcb@listing@usetemplisting{%
  \tcb@listing@input@listing{\kvtcb@listingoptions}{\kvtcb@tempfile}%
}%

\def\tcb@listing@doc@usetemplisting{%
  \tcb@listing@input@listing{\kvtcb@doclistingoptions}{\kvtcb@tempfile}%
}

\tcbset{%
  listing options/.store in=\kvtcb@listingoptions,%
  listing style/.style={listing options={style=#1}},%
  no listing options/.style={listing options=},%
  listing inputencoding/.store in=\kvtcb@listingencoding,%
  listing remove caption/.is choice,
  listing remove caption/true/.code={\let\tcb@listing@set@MakeCaption\tcb@listing@set@MakeCaption@empty},
  listing remove caption/false/.code={\let\tcb@listing@set@MakeCaption\tcb@listing@set@MakeCaption@org},
  listing remove caption/.default=true,
  listing engine/listings/.code={\let\tcbuselistinglisting\tcb@listing@uselistinglisting%
    \let\tcbusetemplisting\tcb@listing@usetemplisting%
    \let\tcb@doc@usetemplisting\tcb@listing@doc@usetemplisting},
  every listing line/.code={%
    \def\lst@NewLine{%
      \ifx\lst@OutputBox\@gobble\else
          \par\noindent \hbox{}#1%
      \fi
      \global\advance\lst@newlines\m@ne
      \lst@newlinetrue}},%
  every listing line*/.style={every listing line={#1},%
    code={\setbox\z@=\hbox{#1}\tcbdimto\kvtcb@rightupper{\kvtcb@rightupper+\wd\z@}}},%
}


\tcbset{%
  reset@listings/.style={%
    listing style=tcblatex,
    listing inputencoding=\inputencodingname,
    listing remove caption,
    listing engine=listings,
  },
  initialize@reset=reset@listings,
}