Le paquet pour le formatage du code source dans LATEX est listings. Découvrez ce qu'il peut faire dans son manuel here.
C'est la proximité j'ai réussi à:
The listing, as typeset in LaTeX http://i29.tinypic.com/wb8bdi.png
Le nom de la légende est aussi la cible du lien Download
. Désolé pour le manque de coins arrondis. Ceux-ci peuvent probablement être fait avec TikZ.
Voici le préambule:
\usepackage{listings}
\usepackage[T1]{fontenc}
\usepackage[scaled]{beramono}
\usepackage{tgadventor}
\usepackage[usenames,dvipsnames]{color}
\usepackage[colorlinks=true]{hyperref}
\definecolor{lineno}{rgb}{0.5,0.5,0.5}
\definecolor{code}{rgb}{0,0.1,0.6}
\definecolor{keyword}{rgb}{0.5,0.1,0.1}
\definecolor{titlebox}{rgb}{0.85,0.85,0.85}
\definecolor{download}{rgb}{0.8,0.1,0.5}
\definecolor{title}{rgb}{0.4,0.4,0.4}
\lstset{
language=Lisp,
basicstyle=\ttfamily\small\color{code},
showspaces=false,
showstringspaces=false,
numbers=left,
firstnumber=1,
stepnumber=5,
numberfirstline=true,
numberstyle=\color{lineno}\sffamily\scriptsize,
keywordstyle=\color{keyword}\bfseries,
stringstyle=\itshape,
morekeywords={dosync,if},
deletekeywords={alter}
}
\makeatletter
\gdef\[email protected]{%
\ifnum\[email protected]=\[email protected]
\global\advance\[email protected]\[email protected]\relax
\[email protected]
\[email protected]
\else
\[email protected]
{\def\thelstnumber{Line \@arabic\[email protected]}\[email protected]}%
\[email protected]
\else
{\def\thelstnumber{-}\[email protected]}%
\fi
\fi
\global\advance\[email protected]\@ne}%
\def\[email protected]#1{
\vskip\abovecaptionskip
\colorbox{titlebox}{
\scriptsize
\color{download}\ttfamily\href{http://example.com/#1}{Download}
\color{title}\sffamily\bfseries#1}
\vskip\belowcaptionskip}
\makeatother
Ensuite, une liste dans typeset le corps avec:
\begin{lstlisting}[title=examples/introduction.clj]
(defn hello
"Writes hello message to *out*. Calls you by username.
Knows if you have been here before."
[username]
(dosync
(let [past-visitor (@visitors username)]
(if past-visitor
(str "Welcome back, " username)
(do
(alter visitors conj username)
(str "Hello, " username))))))
\end{lstlisting}
I love LaTeX.
@Voter pour fermer: Sur meta, il a été déterminé que les questions LaTeX appartiennent à SO. http://meta.stackexchange.com/questions/12918/can-we-have-a-ruling-on-latex-on-stackoverflow – Thomas
Bien que Stack Overflow soit un bon endroit pour poser des questions à LaTeX, il y a une proposition pour mettre en place un site similaire spécifiquement pour TeX/LaTeX. S'il vous plaît [allez ici et "commettez"] (http://area51.stackexchange.com/proposals/2148/tex-latex-and-friends?referrer=LtGW8MKLMIWU41zfK7oIpw2) si vous souhaitez participer à un tel site. – ShreevatsaR
@Thomas: questionneur qui veut latex q sur le s.o. accepte une réponse opinant latex q appartenir à s.o. = "il a été déterminé sur méta que ..." –