Dans mes polys de cours, j'ai des environnement faits avec tcolorbox ou tikz.
J'aimerais qqchose de semblable (un peu) pour mes programmes python, qui je le précise, sont appelés de l'extérieur.
Je souhaiterais un rendu avec le nom du programme en haut de la jolie boite, qui serait colorée, avec des arrondis et des ombres.
Voici le code que j'utilise en ce moment (il est un peu long mais peut intéresser des curieux) :
Code : Tout sélectionner
\documentclass{article}
\usepackage[utf8x]{inputenc}
\usepackage{tcolorbox}
\usepackage{pythonhighlight}
\usepackage{listings}
\usepackage{xcolor}
\definecolor{intdef}{rgb}{0.9 1 0.8}
\definecolor{intprop}{rgb}{1 1 0.7}
\renewcommand*{\lstlistlistingname}{Code Listings}
\renewcommand*{\lstlistingname}{Code Listing}
\definecolor{gray}{gray}{0.5}
\colorlet{commentcolour}{green!60!black}
\colorlet{stringcolour}{red!80!black}
\colorlet{keywordcolour}{magenta!90!black}
\colorlet{exceptioncolour}{yellow!80!red}
\colorlet{commandcolour}{blue!60!black}
\colorlet{numpycolour}{blue!80!green}
\colorlet{literatecolour}{magenta!90!black}
\colorlet{promptcolour}{red!80!black}
\colorlet{specmethodcolour}{violet}
\makeatletter
\lstdefinestyle{mypython_list}{
inputencoding=utf8,
language=python,
showtabs=true,
tab=,
tabsize=2,
basicstyle=\ttfamily,
stringstyle=\color{stringcolour},
showstringspaces=false,
keepspaces=true,
alsoletter={1234567890},
otherkeywords={\%, \}, \{, \&, \|},
morekeywords={as},
keywordstyle=\color{keywordcolour}\bfseries,
emph={and,break,class,continue,def,yield,del,elif ,else,%
except,exec,finally,for,from,global,if,import,in,%
lambda,not,or,pass,print,raise,return,try,while,assert,with},
emphstyle=\color{blue}\bfseries,
emph={[2]True, False, None},
emphstyle=[2]\color{keywordcolour},
emph={[3]object,type,isinstance,copy,deepcopy,zip,enumerate,reversed,list,len,dict,tuple,xrange,append,execfile,real,imag,reduce,str,repr},
emphstyle=[3]\color{commandcolour},
emph={Exception,NameError,IndexError,SyntaxError,TypeError,ValueError,OverflowError,ZeroDivisionError},
emphstyle=\color{exceptioncolour}\bfseries,
morecomment=[s]{"""}{"""},
commentstyle=\color{commentcolour}\slshape,
emph={[4]ode, fsolve, sqrt, exp, sin, cos,arctan, arctan2, arccos, pi, array,
norm, solve, dot, arange, , isscalar, max, sum, flatten, flat, size, new, open, Image, save, load,
getdata, putpixel, putdata, getpixel, shape, reshape, find,
any, all, abs, plot, show, linspace, legend, quad, polyval,polyfit, hstack,
concatenate,vstack,column_stack,empty,zeros,ones,rand,vander,grid,pcolor,eig,
eigs,eigvals,svd,qr,tan,det,logspace,roll,min,mean,cumsum,cumprod,diff,vectorize
,lstsq,cla,eye,xlabel,ylabel,squeeze},
emphstyle=[4]\color{numpycolour},
emph={[5]__init__,__add__,__mul__,__div__,__sub__,__call__,__getitem__,__setitem__,__eq__,__ne__,__nonzero__,__rmul__,__radd__,__repr__,__str__,__get__,__truediv__,__pow__,__name__,__future__,__all__},
emphstyle=[5]\color{specmethodcolour},
emph={[6]assert,yield},
emphstyle=[6]\color{keywordcolour}\bfseries,
emph={[7]range},
emphstyle={[7]\color{keywordcolour}\bfseries},
escapeinside={<@}{@>},
literate=
{é}{{\'e}}{1}%
{è}{{\`e}}{1}%
{à}{{\`a}}{1}%
{â}{{\^a}}{1}%
{ç}{{\c{c}}}{1}%
{æ}{{\ae}}{1}%
{œ}{{\oe}}{1}%
{ù}{{\`u}}{1}%
{É}{{\'E}}{1}%
{È}{{\`E}}{1}%
{À}{{\`A}}{1}%
{Ç}{{\c{C}}}{1}%
{Æ}{{\AE}}{1}%
{Œ}{{\OE}}{1}%
{Ê}{{\^E}}{1}%
{ê}{{\^e}}{1}%
{î}{{\^i}}{1}%
{ï}{{\"i}}{1}%
{ô}{{\^o}}{1}%
{û}{{\^u}}{1}%
{:}{{\literatecolour:}}{1}%
{=}{{\literatecolour=}}{1}%
{-}{{\literatecolour-}}{1}%
{+}{{\literatecolour+}}{1}%
{*}{{\literatecolour*}}{1}%
{**}{{\literatecolour{**}}}2%
{/}{{\literatecolour/}}{1}%
{//}{{\literatecolour{//}}}2%
{!}{{\literatecolour!}}{1}%
{[}{{\literatecolour[}}{1}%
{]}{{\literatecolour]}}{1}%
{<}{{\literatecolour<}}{1}%
{>}{{\literatecolour>}}{1}%
{>>>}{\pythonprompt}{3}%
,
backgroundcolor=\color{violet!10}
}
\makeatother
\newcommand*{\inputpythonini}[4]{
\lstinputlisting[
firstline=#2,
lastline=#3,
firstnumber=#4,
breakindent=.5\textwidth,
numbers=left,
framexleftmargin=8mm,
frame=shadowbox,
frameround=tttt,
rulesepcolor=\color{lightgray},
numberstyle=\ttfamily \footnotesize \bf \color{blue},
numbersep=11pt,
xleftmargin=1cm,
breaklines=true,
columns=flexible,
style=mypython_list]{#1}}
\begin{document}
\inputpythonini{condition-compacte.py}{1}{100}{3}
\end{document}
Code : Tout sélectionner
# -*- coding: utf-8 -*-
print("Entrez 2 entiers :")
x=int(input("x ? "))
y=int(input("y ? "))
# méthode classique :
if x < y:
petit = x
else:
petit = y
# méthode compacte :
petit = x if x < y else y
print("\nLe plus petit est", petit)
Si vous avez des choses jolies à proposer...
Je ne souhaite pas utiliser minted pour éviter shell-escape.