minted.sty 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. %%
  2. %% This is file `minted.sty',
  3. %% generated with the docstrip utility.
  4. %%
  5. %% The original source files were:
  6. %%
  7. %% minted.dtx (with options: `package')
  8. %% Copyright 2010--2011 Konrad Rudolph
  9. %%
  10. %% This work may be distributed and/or modified under the
  11. %% conditions of the LaTeX Project Public License, either version 1.3
  12. %% of this license or (at your option) any later version.
  13. %% The latest version of this license is in
  14. %% http://www.latex-project.org/lppl.txt
  15. %% and version 1.3 or later is part of all distributions of LaTeX
  16. %% version 2005/12/01 or later.
  17. %%
  18. %% Additionally, the project may be distributed under the terms of the new BSD
  19. %% license.
  20. %%
  21. %% This work has the LPPL maintenance status `maintained'.
  22. %%
  23. %% The Current Maintainer of this work is Konrad Rudolph.
  24. %%
  25. %% This work consists of the files minted.dtx and minted.ins
  26. %% and the derived file minted.sty.
  27. \NeedsTeXFormat{LaTeX2e}
  28. \ProvidesPackage{minted}[2013/12/21 v2.0-alpha3 ]
  29. \RequirePackage{keyval}
  30. \RequirePackage{kvoptions}
  31. \RequirePackage{fancyvrb}
  32. \RequirePackage{float}
  33. \RequirePackage{ifthen}
  34. \RequirePackage{calc}
  35. \RequirePackage{ifplatform}
  36. \RequirePackage{pdftexcmds}
  37. \RequirePackage{etoolbox}
  38. \RequirePackage{xstring}
  39. \AtBeginDocument{\@ifpackageloaded{color}{}{\RequirePackage{xcolor}}}
  40. \DeclareVoidOption{chapter}{\def\minted@float@within{chapter}}
  41. \DeclareVoidOption{section}{\def\minted@float@within{section}}
  42. \newboolean{minted@cache}
  43. \DeclareVoidOption{cache}{%
  44. \minted@cachetrue
  45. \AtEndOfPackage{\ProvideDirectory{\minted@outputdir\minted@cachedir}}%
  46. }
  47. \StrSubstitute{\jobname}{ }{_}[\minted@jobname]
  48. \StrSubstitute{\minted@jobname}{"}{}[\minted@jobname]
  49. \StrSubstitute{\minted@jobname}{*}{-}[\minted@jobname]
  50. \newcommand{\minted@cachedir}{.minted-\minted@jobname}
  51. \let\minted@cachedir@windows\minted@cachedir
  52. \define@key{minted}{cachedir}{%
  53. \@namedef{minted@cachedir}{#1}%
  54. \StrSubstitute{\minted@cachedir}{/}{\@backslashchar}[\minted@cachedir@windows]}
  55. \let\minted@outputdir\@empty
  56. \let\minted@outputdir@windows\@empty
  57. \define@key{minted}{outputdir}{%
  58. \@namedef{minted@outputdir}{#1/}%
  59. \StrSubstitute{\minted@outputdir}{/}%
  60. {\@backslashchar}[\minted@outputdir@windows]}
  61. \newboolean{minted@langlinenos}
  62. \DeclareVoidOption{langlinenos}{\minted@langlinenostrue}
  63. \ProcessKeyvalOptions*
  64. \newcommand{\minted@infile}{\jobname.out.pyg}
  65. \newcommand{\minted@cachefiles}{}
  66. \newcommand{\minted@addcachefile}[1]{%
  67. \expandafter\gdef\expandafter\minted@cachefiles\expandafter{%
  68. \minted@cachefiles,#1}%
  69. \expandafter\gdef\csname minted@current@#1\endcsname{}%
  70. }
  71. \newcommand{\minted@savecachefiles}{%
  72. \immediate\write\@mainaux{%
  73. \string\gdef\string\minted@oldcachefiles\string{%
  74. \minted@cachefiles\string}}%
  75. }
  76. \newcommand{\minted@cleancache}{%
  77. \ifthenelse{\boolean{minted@cache}}{%
  78. \ifcsname minted@oldcachefiles\endcsname
  79. \renewcommand{\do}[1]{%
  80. \ifthenelse{\equal{##1}{}}{}{%
  81. \ifcsname minted@current@##1\endcsname\else
  82. \DeleteFile[\minted@outputdir\minted@cachedir]{##1.pygtex}%
  83. \fi
  84. }%
  85. }%
  86. \expandafter\docsvlist\expandafter{\minted@oldcachefiles}%
  87. \else
  88. \fi
  89. }{}%
  90. }
  91. \ifthenelse{\boolean{minted@cache}}%
  92. {\AtEndDocument{%
  93. \minted@savecachefiles
  94. \minted@cleancache}}%
  95. {}%
  96. \ifwindows
  97. \providecommand{\DeleteFile}[2][]{%
  98. \ifthenelse{\equal{#1}{}}%
  99. {\IfFileExists{#2}{\immediate\write18{del "#2"}}{}}%
  100. {\IfFileExists{#1/#2}{%
  101. \StrSubstitute{#1}{/}{\@backslashchar}[\minted@windir]
  102. \immediate\write18{del "\minted@windir\@backslashchar #2"}}{}}}
  103. \else
  104. \providecommand{\DeleteFile}[2][]{%
  105. \ifthenelse{\equal{#1}{}}%
  106. {\IfFileExists{#2}{\immediate\write18{rm "#2"}}{}}%
  107. {\IfFileExists{#1/#2}{\immediate\write18{rm "#1/#2"}}{}}}
  108. \fi
  109. \ifwindows
  110. \newcommand{\ProvideDirectory}[1]{%
  111. \StrSubstitute{#1}{/}{\@backslashchar}[\minted@windir]
  112. \immediate\write18{if not exist "\minted@windir" mkdir "\minted@windir"}}
  113. \else
  114. \newcommand{\ProvideDirectory}[1]{%
  115. \immediate\write18{mkdir -p "#1"}}
  116. \fi
  117. \newboolean{AppExists}
  118. \newread\minted@appexistsfile
  119. \newcommand{\TestAppExists}[1]{
  120. \ifwindows
  121. \DeleteFile{\jobname.aex}
  122. \immediate\write18{for \string^\@percentchar i in (#1.exe #1.bat #1.cmd)
  123. do set >\jobname.aex <nul: /p
  124. x=\string^\@percentchar \string~$PATH:i>>\jobname.aex}
  125. %$ <- balance syntax highlighting
  126. \immediate\openin\minted@appexistsfile\jobname.aex
  127. \expandafter\def\expandafter\@tmp@cr\expandafter{\the\endlinechar}
  128. \endlinechar=-1\relax
  129. \readline\minted@appexistsfile to \minted@apppathifexists
  130. \endlinechar=\@tmp@cr
  131. \ifthenelse{\equal{\minted@apppathifexists}{}}
  132. {\AppExistsfalse}
  133. {\AppExiststrue}
  134. \immediate\closein\minted@appexistsfile
  135. \DeleteFile{\jobname.aex}
  136. \immediate\typeout{file deleted}
  137. \else
  138. \immediate\write18{which #1 && touch \jobname.aex}
  139. \IfFileExists{\jobname.aex}
  140. {\AppExiststrue
  141. \DeleteFile{\jobname.aex}}
  142. {\AppExistsfalse}
  143. \fi
  144. }
  145. \newcommand{\minted@optg}{}
  146. \let\minted@lang\@empty
  147. \newcommand{\minted@optlang}{}
  148. \newcommand{\minted@optcmd}{}
  149. \newcommand{\minted@checklang}{%
  150. \ifcsname minted@optlang\minted@lang\endcsname\else
  151. \expandafter\def\csname minted@optlang\minted@lang\endcsname{}%
  152. \fi
  153. \ifcsname minted@optlang\minted@lang @extra\endcsname\else
  154. \expandafter\def\csname minted@optlang\minted@lang @extra\endcsname{}%
  155. \fi
  156. }
  157. \newcommand{\minted@resetoptcmd}{%
  158. \@namedef{minted@optcmd@extra}{}%
  159. \let\minted@optcmd@autogobble\relax}
  160. \newcommand{\minted@getoptg}[1]{%
  161. \expandafter\detokenize%
  162. \expandafter\expandafter\expandafter{\csname minted@optg@#1\endcsname}}
  163. \newcommand{\minted@getoptlang}[1]{%
  164. \expandafter\detokenize\expandafter\expandafter\expandafter{%
  165. \csname minted@optlang\minted@lang @#1\endcsname}}
  166. \newcommand{\minted@getoptcmd}[1]{%
  167. \expandafter\detokenize%
  168. \expandafter\expandafter\expandafter{\csname minted@optcmd@#1\endcsname}}
  169. \newcommand{\minted@regoptg}[1]{%
  170. \ifcsname minted@optg@#1@reg\endcsname\else
  171. \expandafter\let\csname minted@optg@#1@reg\endcsname\@empty
  172. \expandafter\def\expandafter\minted@optg\expandafter{%
  173. \minted@optg\space\minted@getoptg{#1}}%
  174. \fi
  175. }
  176. \newcommand{\minted@regoptlang}[1]{%
  177. \ifcsname minted@optlang\minted@lang @#1@reg\endcsname\else
  178. \ifcsname minted@optlang\minted@lang\endcsname\else
  179. \expandafter\def\csname minted@optlang\minted@lang\endcsname{}%
  180. \fi
  181. \expandafter\let\csname minted@optlang\minted@lang @#1@reg\endcsname\@empty
  182. \expandafter\let\expandafter\minted@optlang%
  183. \csname minted@optlang\minted@lang\endcsname
  184. \expandafter\def\expandafter\minted@optlang\expandafter{%
  185. \minted@optlang\space\minted@getoptlang{#1}}%
  186. \expandafter\let\csname minted@optlang\minted@lang\endcsname\minted@optlang
  187. \let\minted@optlang\@empty
  188. \fi
  189. }
  190. \newcommand{\minted@regoptcmd}[1]{%
  191. \ifcsname minted@optcmd@#1@reg\endcsname\else
  192. \expandafter\let\csname minted@optcmd@#1@reg\endcsname\@empty
  193. \expandafter\def\expandafter\minted@optcmd\expandafter{%
  194. \minted@optcmd\space\minted@getoptcmd{#1}}%
  195. \expandafter\def\expandafter\minted@resetoptcmd\expandafter{%
  196. \minted@resetoptcmd
  197. \@namedef{minted@optcmd@#1}{}}
  198. \fi
  199. }
  200. \newcommand{\minted@define@opt}[4][]{%
  201. \ifthenelse{\equal{#1}{}}%
  202. {\define@key{minted@optg}{#2}{\@namedef{minted@optg@#2}{#3=#4}%
  203. \@namedef{minted@optg@#2@val}{#4}%
  204. \minted@regoptg{#2}}%
  205. \define@key{minted@optlang}{#2}{%
  206. \@namedef{minted@optlang\minted@lang @#2}{#3=#4}%
  207. \@namedef{minted@optlang\minted@lang @#2@val}{#4}%
  208. \minted@regoptlang{#2}}%
  209. \define@key{minted@optcmd}{#2}{\@namedef{minted@optcmd@#2}{#3=#4}%
  210. \@namedef{minted@optcmd@#2@val}{#4}%
  211. \minted@regoptcmd{#2}}}%
  212. {\define@key{minted@optg}{#2}[#1]{\@namedef{minted@optg@#2}{#3=#4}%
  213. \@namedef{minted@optg@#2@val}{#4}%
  214. \minted@regoptg{#2}}%
  215. \define@key{minted@optlang}{#2}[#1]{%
  216. \@namedef{minted@optlang\minted@lang @#2}{#3=#4}%
  217. \@namedef{minted@optlang\minted@lang @#2@val}{#4}%
  218. \minted@regoptlang{#2}}%
  219. \define@key{minted@optcmd}{#2}[#1]{\@namedef{minted@optcmd@#2}{#3=#4}%
  220. \@namedef{minted@optcmd@#2@val}{#4}%
  221. \minted@regoptcmd{#2}}}%
  222. }
  223. \newcommand{\minted@define@optstyle}{%
  224. \define@key{minted@optg}{style}{%
  225. \@namedef{minted@optg@style}{-P style=##1 -P commandprefix=PYG##1}%
  226. \minted@regoptg{style}\minted@regstyle{##1}}%
  227. \define@key{minted@optlang}{style}{%
  228. \@namedef{minted@optlang\minted@lang @style}%
  229. {-P style=##1 -P commandprefix=PYG##1}%
  230. \minted@regoptlang{style}\minted@regstyle{##1}}%
  231. \define@key{minted@optcmd}{style}{%
  232. \@namedef{minted@optcmd@style}{-P style=##1 -P commandprefix=PYG##1}%
  233. \minted@regoptcmd{style}\minted@regstyle{##1}}%
  234. }
  235. \newcommand{\minted@regstyle}[1]{%
  236. \ifcsname minted@stylereg@#1\endcsname\else
  237. \expandafter\global\expandafter%
  238. \let\csname minted@stylereg@#1\endcsname\@empty
  239. \ifthenelse{\boolean{minted@cache}}%
  240. {\IfFileExists{\minted@outputdir\minted@cachedir/#1.pygstyle}{}{%
  241. \ifwindows
  242. \immediate\write18{\MintedPygmentize\space -S #1 -f latex
  243. -P commandprefix=PYG#1
  244. > "\minted@outputdir@windows\minted@cachedir@windows\@backslashchar#1.pygstyle"}%
  245. \else
  246. \immediate\write18{\MintedPygmentize\space -S #1 -f latex
  247. -P commandprefix=PYG#1
  248. > "\minted@outputdir\minted@cachedir/#1.pygstyle"}%
  249. \fi
  250. }%
  251. \begingroup
  252. \let\def\gdef
  253. \endlinechar=-1\relax
  254. \input{\minted@outputdir\minted@cachedir/#1.pygstyle}%
  255. \endgroup}%
  256. {\ifwindows
  257. \immediate\write18{\MintedPygmentize\space -S #1 -f latex
  258. -P commandprefix=PYG#1 > "\minted@outputdir@windows\jobname.out.pyg"}%
  259. \else
  260. \immediate\write18{\MintedPygmentize\space -S #1 -f latex
  261. -P commandprefix=PYG#1 > "\minted@outputdir\jobname.out.pyg"}%
  262. \fi
  263. \begingroup
  264. \let\def\gdef
  265. \endlinechar=-1\relax
  266. \input{\minted@outputdir\jobname.out.pyg}%
  267. \endgroup}%
  268. \fi
  269. }
  270. \newcommand{\minted@define@switch}[3][]{
  271. \define@booleankey{minted@optg}{#2}
  272. {\@namedef{minted@optg@#2}{#3}\minted@regoptg{#2}}
  273. {\@namedef{minted@optg@#2}{#1}\minted@regoptg{#2}}
  274. \define@booleankey{minted@optlang}{#2}
  275. {\@namedef{minted@optlang\minted@lang @#2}{#3}\minted@regoptlang{#2}}
  276. {\@namedef{minted@optlang\minted@lang @#2}{#1}\minted@regoptlang{#2}}
  277. \define@booleankey{minted@optcmd}{#2}
  278. {\@namedef{minted@optcmd@#2}{#3}\minted@regoptcmd{#2}}
  279. {\@namedef{minted@optcmd@#2}{#1}\minted@regoptcmd{#2}}
  280. }
  281. \newcommand{\minted@define@extra}[1]{
  282. \define@key{minted@optg}{#1}{%
  283. \expandafter\def\expandafter\minted@optg@extra\expandafter{%
  284. \minted@optg@extra,#1=##1}}
  285. \@namedef{minted@optg@extra}{}
  286. \define@key{minted@optlang}{#1}{%
  287. \ifcsname minted@optlang\minted@lang @extra\endcsname\else
  288. \expandafter\def\csname minted@optlang\minted@lang @extra\endcsname{}%
  289. \fi
  290. \expandafter\let\expandafter\minted@optlang@extra%
  291. \csname minted@optlang\minted@lang @extra \endcsname
  292. \expandafter\def\expandafter\minted@optlang@extra\expandafter{%
  293. \minted@optlang@extra,#1=##1}%
  294. \expandafter\let\csname minted@optlang\minted@lang @extra\endcsname%
  295. \minted@optlang@extra
  296. \let\minted@optlang@extra\@empty}%
  297. \@namedef{minted@optlang@extra}{}
  298. \define@key{minted@optcmd}{#1}{%
  299. \expandafter\def\expandafter\minted@optcmd@extra\expandafter{%
  300. \minted@optcmd@extra,#1=##1}}
  301. \@namedef{minted@optcmd@extra}{}
  302. }
  303. \newcommand{\minted@define@extra@switch}[1]{
  304. \define@booleankey{minted@optg}{#1}
  305. {\expandafter\def\expandafter\minted@optg@extra\expandafter{%
  306. \minted@optg@extra,#1}}
  307. {\expandafter\def\expandafter\minted@optg@extra\expandafter{%
  308. \minted@optg@extra,#1=false}}
  309. \define@booleankey{minted@optlang}{#1}
  310. {%
  311. \ifcsname minted@optlang\minted@lang @extra\endcsname\else
  312. \expandafter\def\csname minted@optlang\minted@lang @extra\endcsname{}%
  313. \fi
  314. \expandafter\let\expandafter\minted@optlang@extra%
  315. \csname minted@optlang\minted@lang @extra\endcsname
  316. \expandafter\def\expandafter\minted@optlang@extra\expandafter{%
  317. \minted@optlang@extra,#1}%
  318. \expandafter\let\csname minted@optlang\minted@lang @extra\endcsname%
  319. \minted@optlang@extra
  320. \let\minted@optlang@extra\@empty}
  321. {%
  322. \ifcsname minted@optlang\minted@lang @extra\endcsname\else
  323. \expandafter\def\csname minted@optlang\minted@lang @extra\endcsname{}%
  324. \fi
  325. \expandafter\let\expandafter\minted@optlang@extra%
  326. \csname minted@optlang\minted@lang @extra\endcsname
  327. \expandafter\def\expandafter\minted@optlang@extra\expandafter{%
  328. \minted@optlang@extra,#1=false}%
  329. \expandafter\let\csname minted@optlang\minted@lang @extra\endcsname%
  330. \minted@optlang@extra
  331. \let\minted@optlang@extra\@empty}
  332. \define@booleankey{minted@optcmd}{#1}
  333. {\expandafter\def\expandafter\minted@optcmd@extra\expandafter{%
  334. \minted@optcmd@extra,#1}}
  335. {\expandafter\def\expandafter\minted@optcmd@extra\expandafter{%
  336. \minted@optcmd@extra,#1=false}}
  337. }
  338. \minted@define@opt{encoding}{-P encoding}{#1}
  339. \minted@define@opt{outencoding}{-P outencoding}{#1}
  340. \minted@define@opt{stripnl}{-P stripnl}{#1}
  341. \minted@define@switch{python3}{-P python3=True}
  342. \minted@define@switch[-P funcnamehighlighting=False]%
  343. {funcnamehighlighting}{-P funcnamehighlighting}
  344. \minted@define@switch{startinline}{-P startinline}
  345. \minted@define@opt{gobble}{-F gobble:n}{#1}
  346. \minted@define@opt{codetagify}{-F codetagify:codetags}{#1}
  347. \minted@define@opt{keywordcase}{-F keywordcase:case}{#1}
  348. \minted@define@switch{texcl}{-P texcomments}
  349. \minted@define@switch{texcomments}{-P texcomments}
  350. \minted@define@switch{mathescape}{-P mathescape}
  351. \minted@define@switch{linenos}{-P linenos}
  352. \minted@define@optstyle
  353. \minted@define@extra{frame}
  354. \minted@define@extra{framesep}
  355. \minted@define@extra{framerule}
  356. \minted@define@extra{rulecolor}
  357. \minted@define@extra{numbersep}
  358. \minted@define@extra{numbers}
  359. \minted@define@extra{firstnumber}
  360. \minted@define@extra{stepnumber}
  361. \minted@define@extra{firstline}
  362. \minted@define@extra{lastline}
  363. \minted@define@extra{baselinestretch}
  364. \minted@define@extra{xleftmargin}
  365. \minted@define@extra{xrightmargin}
  366. \minted@define@extra{fillcolor}
  367. \minted@define@extra{tabsize}
  368. \minted@define@extra{fontfamily}
  369. \minted@define@extra{fontsize}
  370. \minted@define@extra{fontshape}
  371. \minted@define@extra{fontseries}
  372. \minted@define@extra{formatcom}
  373. \minted@define@extra{label}
  374. \minted@define@extra@switch{numberblanklines}
  375. \minted@define@extra@switch{showspaces}
  376. \minted@define@extra@switch{resetmargins}
  377. \minted@define@extra@switch{samepage}
  378. \minted@define@extra@switch{showtabs}
  379. \minted@define@extra@switch{obeytabs}
  380. \let\minted@optcmd@bgcolor\@empty
  381. \define@key{minted@optcmd}{bgcolor}{\@namedef{minted@optcmd@bgcolor}{#1}}
  382. \newcommand{\minted@encoding}{%
  383. \ifcsname minted@optcmd@encoding@val\endcsname
  384. \csname minted@optcmd@encoding@val\endcsname
  385. \else
  386. \ifcsname minted@optlang\minted@lang @encoding@val\endcsname
  387. \csname minted@optlang\minted@lang @encoding@val\endcsname
  388. \else
  389. \ifcsname minted@optg@encoding@val\endcsname
  390. \csname minted@optg@encoding@val\endcsname
  391. \else
  392. UTF8%
  393. \fi
  394. \fi
  395. \fi
  396. }
  397. \define@booleankey{minted@optg}{autogobble}
  398. {\expandafter\let\csname minted@optg@autogobble\endcsname\@empty}
  399. {\expandafter\let\csname minted@optg@autogobble\endcsname\relax}
  400. \define@booleankey{minted@optlang}{autogobble}
  401. {\expandafter\let\csname minted@optlang\minted@lang @autogobble\endcsname\@empty}
  402. {\expandafter\let\csname minted@optlang\minted@lang @autogobble\endcsname\relax}
  403. \define@booleankey{minted@optcmd}{autogobble}
  404. {\expandafter\let\csname minted@optcmd@autogobble\endcsname\@empty}
  405. {\expandafter\let\csname minted@optcmd@autogobble\endcsname\relax}
  406. \newboolean{minted@autogobble}
  407. \newcommand{\minted@set@autogobble}{%
  408. \ifcsname minted@optg@autogobble\endcsname\else
  409. \expandafter\let\csname minted@optg@autogobble\endcsname\relax
  410. \fi
  411. \ifcsname minted@optlang\minted@lang @autogobble\endcsname\else
  412. \expandafter\let\csname minted@optlang\minted@lang @autogobble\endcsname\relax
  413. \fi
  414. \ifcsname minted@optcmd@autogobble\endcsname\else
  415. \expandafter\let\csname minted@optcmd@autogobble\endcsname\relax
  416. \fi
  417. \expandafter\ifx\csname minted@optcmd@autogobble\endcsname\@empty
  418. \setboolean{minted@autogobble}{true}%
  419. \else
  420. \expandafter\ifx\csname minted@optlang\minted@lang @autogobble\endcsname\@empty
  421. \setboolean{minted@autogobble}{true}%
  422. \else
  423. \expandafter\ifx\csname minted@optg@autogobble\endcsname\@empty
  424. \setboolean{minted@autogobble}{true}%
  425. \else
  426. \setboolean{minted@autogobble}{false}%
  427. \fi
  428. \fi
  429. \fi
  430. }
  431. \newsavebox{\minted@bgbox}
  432. \newenvironment{minted@colorbg}[1]{
  433. %\setlength{\fboxsep}{-\fboxrule}
  434. \def\minted@bgcol{#1}
  435. \noindent
  436. \begin{lrbox}{\minted@bgbox}
  437. \begin{minipage}{\linewidth-2\fboxsep}}
  438. {\end{minipage}
  439. \end{lrbox}%
  440. \colorbox{\minted@bgcol}{\usebox{\minted@bgbox}}}
  441. \newwrite\minted@code
  442. \newcommand{\minted@savecode}[1]{
  443. \immediate\openout\minted@code\jobname.pyg\relax
  444. \immediate\write\minted@code{\expandafter\detokenize\expandafter{#1}}%
  445. \immediate\closeout\minted@code}
  446. \newcommand{\minted@write@detok}[1]{%
  447. \immediate\write\FV@OutFile{\detokenize{#1}}}
  448. \newcommand{\minted@FVB@VerbatimOut}[1]{%
  449. \@bsphack
  450. \begingroup
  451. \FV@UseKeyValues
  452. \FV@DefineWhiteSpace
  453. \def\FV@Space{\space}%
  454. \FV@DefineTabOut
  455. \let\FV@ProcessLine\minted@write@detok
  456. \immediate\openout\FV@OutFile #1\relax
  457. \let\FV@FontScanPrep\relax
  458. \let\@noligs\relax
  459. \FV@Scan}
  460. \newcommand{\MintedPygmentize}{pygmentize}
  461. \newcommand{\minted@pygmentize}[2][\jobname.pyg]{%
  462. \minted@checklang
  463. \minted@set@autogobble
  464. \ifthenelse{\boolean{minted@autogobble}}%
  465. {\def\minted@codefile{\jobname.pyg}}%
  466. {\def\minted@codefile{#1}}%
  467. \def\minted@cmd{\MintedPygmentize\space -l #2
  468. -f latex -F tokenmerge
  469. \minted@optg \space \csname minted@optlang\minted@lang\endcsname
  470. \space \minted@optcmd \space -P "verboptions=\minted@getoptg{extra}%
  471. \minted@getoptlang{extra}\minted@getoptcmd{extra}"
  472. -o "\minted@outputdir\minted@infile" \space
  473. "\minted@outputdir\minted@codefile"}%
  474. % For debugging, uncomment:
  475. % \immediate\typeout{\minted@cmd}%
  476. \ifthenelse{\boolean{minted@cache}}%
  477. {%
  478. \expandafter\ifx\csname XeTeXinterchartoks\endcsname\relax
  479. \ifthenelse{\boolean{minted@autogobble}}%
  480. {\edef\minted@hash{\pdf@filemdfivesum{#1}%
  481. \pdf@mdfivesum{\minted@cmd autogobble}}}%
  482. {\edef\minted@hash{\pdf@filemdfivesum{#1}%
  483. \pdf@mdfivesum{\minted@cmd}}}%
  484. \else
  485. \immediate\openout\minted@code\jobname.mintedcmd\relax
  486. \immediate\write\minted@code{\minted@cmd}%
  487. \ifthenelse{\boolean{minted@autogobble}}%
  488. {\immediate\write\minted@code{autogobble}}{}%
  489. \immediate\closeout\minted@code
  490. %Cheating a little here by using ASCII codes to write `{` and `}`
  491. %in the Python code
  492. \def\minted@hashcmd{%
  493. \detokenize{python -c "import hashlib;
  494. hasher = hashlib.sha1();
  495. f = open(\'}\minted@outputdir\jobname.mintedcmd\detokenize{\', \'rb\');
  496. hasher.update(f.read());
  497. f.close();
  498. f = open(\'}\minted@outputdir#1\detokenize{\', \'rb\');
  499. hasher.update(f.read());
  500. f.close();
  501. f = open(\'}\minted@outputdir\jobname.mintedmd5\detokenize{\', \'w\');
  502. macro = \'\\edef\\minted@hash\' + chr(123) + hasher.hexdigest() + chr(125) + \'\';
  503. f.write(\'\\makeatletter\' + macro + \'\\makeatother\n\');
  504. f.close();"}}%
  505. \immediate\write18{\minted@hashcmd}
  506. \input{\minted@outputdir\jobname.mintedmd5}%
  507. \fi
  508. \ifwindows
  509. \edef\minted@infile{%
  510. \minted@cachedir@windows\@backslashchar\minted@hash.pygtex}%
  511. \else
  512. \edef\minted@infile{%
  513. \minted@cachedir/\minted@hash.pygtex}%
  514. \fi
  515. \IfFileExists{\minted@cachedir/\minted@hash.pygtex}{}{%
  516. \ifthenelse{\boolean{minted@autogobble}}{%
  517. %Need a version of open() that supports encoding under Python 2
  518. \edef\minted@autogobblecmd{%
  519. \detokenize{python -c "import sys;
  520. import textwrap;
  521. from io import open;
  522. f = open(\'}\minted@outputdir#1\detokenize{\', \'r\', encoding=\'}\minted@encoding\detokenize{\');
  523. t = f.read();
  524. f.close();
  525. f = open(\'}\minted@outputdir\jobname.pyg\detokenize{\', \'w\', encoding=\'}\minted@encoding\detokenize{\');
  526. f.write(textwrap.dedent(t));
  527. f.close();"}%
  528. }%
  529. \immediate\write18{\minted@autogobblecmd}}{}%
  530. \immediate\write18{\minted@cmd}}%
  531. \expandafter\minted@addcachefile\expandafter{\minted@hash}%
  532. \minted@inputpyg}%
  533. {%
  534. \ifthenelse{\boolean{minted@autogobble}}{%
  535. %Need a version of open() that supports encoding under Python 2
  536. \edef\minted@autogobblecmd{%
  537. \detokenize{python -c "import sys;
  538. import textwrap;
  539. from io import open;
  540. f = open(\'}\minted@outputdir#1\detokenize{\', \'r\', encoding=\'}\minted@encoding\detokenize{\');
  541. t = f.read();
  542. f.close();
  543. f = open(\'}\minted@outputdir\jobname.pyg\detokenize{\', \'w\', encoding=\'}\minted@encoding\detokenize{\');
  544. f.write(textwrap.dedent(t));
  545. f.close();"}%
  546. }%
  547. \immediate\write18{\minted@autogobblecmd}}{}%
  548. \immediate\write18{\minted@cmd}%
  549. \minted@inputpyg}%
  550. }
  551. \newcommand{\minted@inputpyg}{%
  552. \ifthenelse{\equal{\minted@optcmd@bgcolor}{}}%
  553. {}%
  554. {\begin{minted@colorbg}{\minted@optcmd@bgcolor}}%
  555. \input{\minted@outputdir\minted@infile}%
  556. \ifthenelse{\equal{\minted@optcmd@bgcolor}{}}%
  557. {}%
  558. {\end{minted@colorbg}}%
  559. }
  560. \newcounter{minted@FancyVerbLineTemp}
  561. \newcommand{\minted@langlinenoson}{%
  562. \ifcsname c@minted@lang\minted@lang\endcsname\else
  563. \newcounter{minted@lang\minted@lang}%
  564. \fi
  565. \setcounter{minted@FancyVerbLineTemp}{\value{FancyVerbLine}}%
  566. \setcounter{FancyVerbLine}{\value{minted@lang\minted@lang}}%
  567. }
  568. \newcommand{\minted@langlinenosoff}{%
  569. \setcounter{minted@lang\minted@lang}{\value{FancyVerbLine}}%
  570. \setcounter{FancyVerbLine}{\value{minted@FancyVerbLineTemp}}%
  571. }
  572. \ifthenelse{\boolean{minted@langlinenos}}{}{%
  573. \let\minted@langlinenoson\relax
  574. \let\minted@langlinenosoff\relax
  575. }
  576. \newcommand{\setminted}[2][]{%
  577. \ifthenelse{\equal{#1}{}}%
  578. {\setkeys{minted@optg}{#2}}%
  579. {\def\minted@lang{#1}\setkeys{minted@optlang}{#2}}%
  580. }
  581. \newcommand{\usemintedstyle}[2][]{\setminted[#1]{style=#2}}
  582. \newcommand{\mintinline}[2][]{%
  583. \minted@resetoptcmd
  584. \setkeys{minted@optcmd}{#1}%
  585. \def\minted@lang{#2}%
  586. \begingroup
  587. \let\do\@makeother\dospecials
  588. \catcode`\{=1
  589. \catcode`\}=2
  590. \catcode`\^^I=\active
  591. \@ifnextchar\bgroup
  592. {\minted@inline@iii}%
  593. {\catcode`\{=12\catcode`\}=12
  594. \minted@inline@i}}
  595. \def\minted@inline@i#1{%
  596. \endgroup
  597. \def\minted@inline@ii##1#1{%
  598. \minted@inline@iii{##1}}%
  599. \begingroup
  600. \let\do\@makeother\dospecials
  601. \minted@inline@ii}
  602. \newcommand{\minted@inline@iii}[1]{%
  603. \endgroup
  604. \immediate\openout\minted@code\jobname.pyg\relax
  605. \immediate\write\minted@code{\detokenize{#1}}%
  606. \immediate\closeout\minted@code
  607. \begingroup
  608. \RecustomVerbatimEnvironment{Verbatim}{BVerbatim}{}%
  609. \minted@pygmentize{\minted@lang}%
  610. \endgroup}
  611. \newcommand{\mint}[3][]{%
  612. \def\minted@lang{#2}%
  613. \DefineShortVerb{#3}%
  614. \minted@resetoptcmd
  615. \setkeys{minted@optcmd}{#1}%
  616. \SaveVerb[aftersave={%
  617. \UndefineShortVerb{#3}%
  618. \minted@savecode{\FV@SV@minted@verb}%
  619. \minted@langlinenoson
  620. \minted@pygmentize{#2}
  621. \minted@langlinenosoff}]{minted@verb}#3}
  622. \newenvironment{minted}[2][]
  623. {\VerbatimEnvironment
  624. \let\FVB@VerbatimOut\minted@FVB@VerbatimOut
  625. \def\minted@lang{#2}%
  626. \minted@resetoptcmd
  627. \setkeys{minted@optcmd}{#1}%
  628. \begin{VerbatimOut}[codes={\catcode`\^^I=12}]{\jobname.pyg}}%
  629. {\end{VerbatimOut}%
  630. \minted@langlinenoson
  631. \minted@pygmentize{\minted@lang}%
  632. \minted@langlinenosoff}
  633. \newcommand{\inputminted}[3][]{%
  634. \def\minted@lang{#2}%
  635. \minted@resetoptcmd
  636. \setkeys{minted@optcmd}{#1}%
  637. \minted@pygmentize[#3]{#2}}
  638. \newcommand{\newminted}[3][]{
  639. \ifthenelse{\equal{#1}{}}
  640. {\def\minted@envname{#2code}}
  641. {\def\minted@envname{#1}}
  642. \newenvironment{\minted@envname}
  643. {\VerbatimEnvironment
  644. \begin{minted}[#3]{#2}}
  645. {\end{minted}}
  646. \newenvironment{\minted@envname *}[1]
  647. {\VerbatimEnvironment\begin{minted}[#3,##1]{#2}}
  648. {\end{minted}}}
  649. \newcommand{\newmint}[3][]{
  650. \ifthenelse{\equal{#1}{}}
  651. {\def\minted@shortname{#2}}
  652. {\def\minted@shortname{#1}}
  653. \expandafter\newcommand\csname\minted@shortname\endcsname[2][]{
  654. \mint[#3,##1]{#2}##2}}
  655. \newcommand{\newmintedfile}[3][]{
  656. \ifthenelse{\equal{#1}{}}
  657. {\def\minted@shortname{#2file}}
  658. {\def\minted@shortname{#1}}
  659. \expandafter\newcommand\csname\minted@shortname\endcsname[2][]{
  660. \inputminted[#3,##1]{#2}{##2}}}
  661. \newcommand{\newmintinline}[3][]{%
  662. \ifthenelse{\equal{#1}{}}%
  663. {\def\minted@shortname{#2inline}}%
  664. {\def\minted@shortname{#1}}%
  665. \expandafter\newcommand\csname\minted@shortname\endcsname{%
  666. \begingroup
  667. \let\do\@makeother\dospecials
  668. \catcode`\{=1
  669. \catcode`\}=2
  670. \@ifnextchar[{\endgroup\minted@inliner[#3][#2]}%
  671. {\endgroup\minted@inliner[#3][#2][]}}%
  672. \def\minted@inliner[##1][##2][##3]{\mintinline[##1,##3]{##2}}%
  673. }
  674. \@ifundefined{minted@float@within}
  675. {\newfloat{listing}{h}{lol}}
  676. {\newfloat{listing}{h}{lol}[\minted@float@within]}
  677. \newcommand{\listingscaption}{Listing}
  678. \floatname{listing}{\listingscaption}
  679. \newcommand{\listoflistingscaption}{List of listings}
  680. \providecommand{\listoflistings}{\listof{listing}{\listoflistingscaption}}
  681. \AtEndOfPackage{
  682. \ifnum\pdf@shellescape=1\relax\else
  683. \PackageError{minted}
  684. {You must invoke LaTeX with the
  685. -shell-escape flag}
  686. {Pass the -shell-escape flag to LaTeX. Refer to the minted.sty
  687. documentation for more information.}%
  688. \fi
  689. \TestAppExists{pygmentize}
  690. \ifAppExists\else
  691. \PackageError{minted}
  692. {You must have `pygmentize' installed
  693. to use this package}
  694. {Refer to the installation instructions in the minted
  695. documentation for more information.}
  696. \fi
  697. \setminted{style=default}%
  698. }
  699. \AtEndDocument{
  700. \expandafter\ifx\csname XeTeXinterchartoks\endcsname\relax
  701. \else
  702. \DeleteFile[\minted@outputdir]{\jobname.mintedcmd}%
  703. \DeleteFile[\minted@outputdir]{\jobname.mintedmd5}%
  704. \fi
  705. \DeleteFile[\minted@outputdir]{\jobname.pyg}%
  706. \DeleteFile[\minted@outputdir]{\jobname.out.pyg}%
  707. }
  708. %% \Finale
  709. \endinput
  710. %%
  711. %% End of file `minted.sty'.