summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tcolorbox/tcbminted.code.tex
blob: 09a6e9c6c79fdd20c194a9b2b8e6a620c5c52f54 (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
%% The LaTeX package tcolorbox - version 6.0.3 (2023/03/17)
%% tcbminted.code.tex: Code for colorboxes with listings
%%
%% -------------------------------------------------------------------------------------------
%% Copyright (c) 2006-2023 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{6.0.3}

\RequirePackage{minted}[2021/12/24]

% to be removed, if integrated into the minted package (#281)
\minted@def@optcl{envname}{-P envname}{#1}

\tcbuselibrary{listings@core}

\ExplSyntaxOn

\cs_new_nopar:Npn \__tcobox_minted_input_listing:nnnn #1#2#3#4
  {
    \tl_if_empty:nF { #4 }
      {
        \usemintedstyle { #4 }
      }
    \tl_set:Nn \l_tmpa_tl { \inputminted[#1 }
    \cs_if_exist:NT \tcb@listing@capture
      {
        \str_if_eq:VnT \tcb@listing@capture { hbox }
          {
            \tl_put_right:Nn \l_tmpa_tl { ,envname=BVerbatim }
          }
      }
    \tl_put_right:Nn \l_tmpa_tl { ] }
    \file_if_exist:nTF { \minted@outputdir #3 }
      {
        \l_tmpa_tl { #2 }{ \minted@outputdir #3 }
      }
      {
        \l_tmpa_tl { #2 }{ #3 }
      }
  }

\cs_generate_variant:Nn \__tcobox_minted_input_listing:nnnn {VVVV}


\cs_new_nopar:Npn \__tcbbox_minted_uselistinglisting:
  {
    \__tcobox_minted_input_listing:VVVV
      \kvtcb@minted@options
      \kvtcb@minted@language
      \kvtcb@listingfile
      \kvtcb@minted@style
  }


\cs_new_nopar:Npn \__tcbbox_minted_usetemplisting:
  {
    \__tcobox_minted_input_listing:VVVV
      \kvtcb@minted@options
      \kvtcb@minted@language
      \kvtcb@tempfile
      \kvtcb@minted@style
  }


\cs_new_nopar:Npn \__tcbbox_minted_doc_usetemplisting:
  {
    \__tcobox_minted_input_listing:VVVV
      \kvtcb@docmintoptions
      \kvtcb@docminted@language
      \kvtcb@tempfile
      \kvtcb@docmintstyle
  }


\tcbset
  {
    listing~engine/minted/.code=
      {
        \cs_set_eq:NN \tcbuselistinglisting   \__tcbbox_minted_uselistinglisting:
        \cs_set_eq:NN \tcbusetemplisting      \__tcbbox_minted_usetemplisting:
        \cs_set_eq:NN \tcb@doc@usetemplisting \__tcbbox_minted_doc_usetemplisting:
      },
  }

\ExplSyntaxOff


\tcbset{%
  minted language/.store in=\kvtcb@minted@language,
  minted options/.store in=\kvtcb@minted@options,
  default@minted@options/.store in=\kvtcb@default@minted@options,
  default minted options/.style={default@minted@options={#1},minted options={#1}},
  minted style/.store in=\kvtcb@minted@style,
}


\tcbset{%
  default@minted@options={tabsize=2,fontsize=\small,breaklines,autogobble},
  reset@minted/.style={%
    minted language=latex,
    code={\let\kvtcb@minted@options\kvtcb@default@minted@options},
    minted style=,
    listing engine=minted,
  },
  initialize@reset=reset@minted,
}