\documentclass[10pt,a4paper]{article}
%\usepackage[margin=13mm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[font=normalsize,format=plain,labelfont=bf,up,textfont=it,up]{caption}
\usepackage{xcolor}
\usepackage{hyperref}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{tcolorbox}
\usepackage{fancyvrb-ex}
\usepackage{tikz}
\usepackage{calc}
\usepackage{pygmentex}
\usepackage{lipsum}

\fvset{gobble=0,showtabs,tabsize=1,frame=lines,framerule=1pt,numbers=left,fontsize=\scriptsize}

\tcbuselibrary{skins,breakable}

\definecolor{shadecolor}{rgb}{0.9,0.9,0.9}
\definecolor{lightgreen}{rgb}{0.8,0.95,0.8}

\begin{document}

\title{Testing the Pygmen\TeX{} package}
\author{José Romildo Malaquias\\
\href{mailto:malaquias@ufop.edu.br}{malaquias@ufop.edu.br}\\
\href{https://bitbucket.org/romildo/pygmentex/src/master/}{bitbucket.org/romildo/pygmentex}
}
\maketitle

\section{The Pygmen\TeX{} package}

This document demonstrates how to use the Pygment\TeX{} package to
typeset code listings with \LaTeX{} and
Pygments\footnote{\url{http://pygments.org/}}.

Pygments is a generic syntax highlighter for general use in all kinds of
software such as forum systems, wikis or other applications that need to
prettify source code.

Pygmen\TeX{} provides an environment and two commands for typesetting code
listings in a \LaTeX{} document:
\begin{itemize}
  \item the \verb|pygmented| environment typesets its contents as a
  source code listing,
  \item the \verb|\inputpygmented| command typesets the contents of a
  file, including the result in the \LaTeX{} document, and
  \item the \verb|\pyginline| command typesets its contents, keeping the
  result in the same line.
\end{itemize}
They accept many options that allow the user to configure the listing in
many ways.

Read the remaining of this document to have an idea of what the package
is capable of.

\section{Requirements}

Current versions of Pygmen\TeX require Python version 3.  Earlier versions
required Python version 2.  All versions require the Python Pygments library.

\section{How to use the package}

\paragraph{1.} Add the package to the document preamble.
\begin{verbatim}
\usepackage{pygmentex}
\end{verbatim}

\paragraph{2.} Use the environment or commands mentioned previously to include source
code listings on your document.

\paragraph{3.} Compile using \texttt{pdflatex}.\footnote{Other \LaTeX compilers
may also work but have not been tested by the author.}
All the source code listings in the document wil be collected and saved in a
temporary file with the extension \texttt{.snippets} in its name.

\paragraph{4.} Run \texttt{pygmentex documentname.snippets}.
The python application \texttt{pygmentex} is
distributed with the Pygmen\TeX{} package).
It will produce another temporary file with the extension
\texttt{.pygmented}, containing \LaTeX{} code for the code listings
previously collected. The next time the document is compiled, they are
included to produce the final typeset document.

\paragraph{5.} Rerun \texttt{pdflatex} as usual.

\paragraph{Note.} Running the external python application
\texttt{pygmentex} can be done automatically from withing \LaTeX{} if
the optional argument \texttt{--shell-escape} is used.

With
\begin{verbatim}
pdflatex --shell-escape <file>
\end{verbatim}
the external run of \texttt{pygmentex} is not needed. It will be run
automatically at the end of the document compilation.

There is a package option \texttt{force} that will force running
\texttt{pygmentex} every time the document is compiled.

\section{First examples}

A simple verbatim text is the first example.

\begin{Example}
\begin{pygmented}[]
Hello world!
  This is a simple demonstration text.
\end{pygmented}
\end{Example}

The followig C program reads two integers and calculates their sum.

\begin{Example}
\begin{pygmented}[lang=c]
#include <stdio.h>
int main(void)
{
   int a, b, c;
   printf("Enter two numbers to add: ");
   scanf("%d%d", &a, &b);
   c = a + b;
   printf("Sum of entered numbers = %d\n", c);
   return 0;
}
\end{pygmented}
\end{Example}

\begin{Example}
  In this program, \pyginline[lang=c]|int| is a type and
  \pyginline[lang=c]|"Enter two numbers to add: "| is a literal string.
\end{Example}

Next you can see a Java program to calculate the factorial of a number.

\begin{Example}
\inputpygmented[lang=java]{Factorial.java}
\end{Example}

\section{Options}
\subsection{\texttt{lang}}
The programming language of the listing code can be specified using the
\verb|lang| option.

To get a list of all available languages, execute the following command
on the command line:
\begin{verbatim}
$ pygmentize -L lexers
\end{verbatim}

\subsection{\texttt{sty}}

Instead of using the default style you may choose another stylesheet
provided by Pygments by its name using the \verb|sty| option.

To get a list of all available stylesheets, execute the following
command on the command line:
\begin{verbatim}
$ pygmentize -L styles
\end{verbatim}

Creating your own styles is also very easy. Just follow the instructions
provided on the website.

As examples you can see a C program typeset with different styles.

\begin{Example}
\noindent
\begin{minipage}[t]{0.49\linewidth}
  \begin{pygmented}[lang=c,gobble=4,sty=murphy]
    #include<stdio.h>
    main()
    { int n;
      printf("Enter a number: ");
      scanf("%d",&n);
      if ( n%2 == 0 )
         printf("Even\n");
      else
         printf("Odd\n");
      return 0;
    }
  \end{pygmented}
\end{minipage}
\hfil
\begin{minipage}[t]{0.49\linewidth}
  \begin{pygmented}[lang=c,gobble=4,sty=trac]
    #include<stdio.h>
    main()
    { int n;
      printf("Enter a number: ");
      scanf("%d",&n);
      if ( n%2 == 0 )
         printf("Even\n");
      else
         printf("Odd\n");
      return 0;
    }
  \end{pygmented}
\end{minipage}
\end{Example}

\subsection{\texttt{font}}

The value of the option \verb|font| is typeset before the content of the
listing. Usualy it is used to specify a font to be used. See the
following example.

\begin{Example}
\begin{pygmented}[lang=scala,font=\rmfamily\scshape\large]
object bigint extends Application {
  def factorial(n: BigInt): BigInt =
    if (n == 0) 1 else n * factorial(n-1)

  val f50 = factorial(50); val f49 = factorial(49)
  println("50! = " + f50)
  println("49! = " + f49)
  println("50!/49! = " + (f50 / f49))
}
\end{pygmented}
\end{Example}

\subsection{\texttt{colback}}

The option \verb|colback| can be used to choose a background color, as
is shown in the folowing example.

\begin{Example}
\begin{pygmented}[lang=fsharp,colback=green!25]
let rec factorial n =
    if n = 0
    then 1
    else n * factorial (n - 1)
System.Console.WriteLine(factorial anInt)
\end{pygmented}
\end{Example}


\subsection{\texttt{gobble}}

The option \verb|gobble| specifies the number of characters to suppress
at the beginning of each line (up to a maximum of 9). This is mainly
useful when environments are indented (Default: empty — no character
suppressed).

\begin{Example}
A code snippet inside a minipage:
\begin{minipage}[t]{.5\linewidth}
    \begin{pygmented}[lang=d,gobble=8]
        ulong fact(ulong n)
        {
          if(n < 2)
            return 1;
          else
            return n * fact(n - 1);
        }
      \end{pygmented}
\end{minipage}
\end{Example}


\subsection{\texttt{tabsize}}

The option \verb|tabsize| specifies the number of of spaces given by a
tab character (Default: 8).

\begin{Verbatim}[showtabs,tabsize=1]
\begin{pygmented}[lang=common-lisp,tabsize=4]
;; Triple the value of a number
(defun triple	(X)
	"Compute three times X."
	(* 3 X))
\end{pygmented}
\end{Verbatim}

\begin{pygmented}[lang=common-lisp,tabsize=4]
;; Triple the value of a number
(defun triple	(X)
	"Compute three times X."
	(* 3 X))
\end{pygmented}


\subsection{\texttt{linenos}, \texttt{linenostart}, \texttt{linenostep}, \texttt{linenosep}}

The lines of a listing can be numbered. The followig options control
numbering of lines.
\begin{itemize}
  \item Line numbering is enabled or disable with the \verb|linenos|
  boolean option.
  \item The number used for the first line can be set with the option
  \verb|linenostart|.
  \item The step between numbered lines can be set with the option
  \verb|linenostep|.
  \item The space between the line number and the line of the listing
  can be set with the option \verb|linenosep|.
\end{itemize}

In the followig listing you can see a Scheme function to calculate the
factorial of a number.

\begin{Example}
\begin{pygmented}[lang=scheme,linenos,linenostart=1001,linenostep=2,linenosep=5mm]
;; Building a list of squares from 0 to 9.
;; Note: loop is simply an arbitrary symbol used as
;; a label. Any symbol will do.

(define (list-of-squares n)
  (let loop ((i n) (res '()))
    (if (< i 0)
        res
        (loop (- i 1) (cons (* i i) res)))))
\end{pygmented}
\end{Example}

\subsection{\texttt{caption} and \texttt{label}}

The option \verb|caption| can be used to set a caption for the listing.
The option \verb|label| allows the assignment of a label to the listing.

Here is an example:

\begin{Example}
\begin{pygmented}[lang=c++,label=lst:test,caption=A \textbf{C++} example]
// This program adds two numbers and prints their sum.
#include <iostream>
int main()
{
  int a;
  int b;
  int sum;
  sum = a + b;
  std::cout << "The sum of " << a << " and " << b
            << " is " << sum << "\n";
  return 0;
}
\end{pygmented}
\end{Example}

\begin{Example}
  Listing \ref{lst:test} is a C++ program.
\end{Example}

\subsection{\texttt{texcomments}, \texttt{mathescape} and \texttt{escapeinside}}

The option \verb|texcomments|, if set to \texttt{true}, enables \LaTeX{}
comment lines. That is, LaTex markup in comment tokens is not escaped
so that \LaTeX{} can render it.

The \verb|mathescape|, if set to \texttt{true}, enables \LaTeX{} math
mode escape in comments. That is, \verb|$...$| inside a comment will
trigger math mode.

The option \verb|escapeinside|, if set to a string of length two,
enables escaping to \LaTeX{}. Text delimited by these two characters
is read as \LaTeX{} code and typeset accordingly. It has no effect in
string literals. It has no effect in comments if \verb|texcomments| or
\verb|mathescape| is set.

Some examples follows.

\begin{Example}
\begin{pygmented}[lang=c++,texcomments]
#include <iostream>
using namespace std;
main()
{
   cout << "Hello World";  // prints \underline{Hello World}
   return 0;
}
\end{pygmented}
\end{Example}

\begin{Example}
\begin{pygmented}[lang=python,mathescape]
# Returns $\sum_{i=1}^{n}i$
def sum_from_one_to(n):
    r = range(1, n + 1)
    return sum(r)
\end{pygmented}
\end{Example}

\begin{Example}
\begin{pygmented}[lang=c,escapeinside=||]

if (|\textit{condition}|)
    |\textit{command$_1$}|
else
    |\textit{command$_2$}|
\end{pygmented}
\end{Example}


\subsection{\texttt{inline method} and \texttt{boxing method}}

After being prettified by Pygments, the listings are enclosed in a
command (for \verb|\pyginline|) or in an environment (for
\verb|pygmented| and \verb|inputpygmented|). By default
\verb|\pyginline| uses the command \verb|\efbox| from the \texttt{efbox}
package, and \verb|pygmented| and \verb|inputpygmented| use the
environment \verb|mdframed| from the \texttt{mdframed} package.

The enclosing command or environment should be configurable using a list
of key-value pairs written between square brackets.

The enclosing command for
\verb|\pyginline| can be changed with the option
\verb|inline method|. For instance, in the following the command
\verb|\tcbox| from the \verb|tcolorbox| package is used:

\begin{Example}
  In the previous Java program,
  \pyginline[lang=java,inline method=tcbox]|"Factorial of "| is a
  literal string.
\end{Example}

The enclosing environment for \verb|pygmented| and
\verb|inputpygmented| can be changed with the option
\verb|boxing method|. For instance, here is a hello world program in
C\#, enclosed in a \verb|tcolorbox| environment:

\begin{Example}
\begin{pygmented}[lang=csharp,boxing method=tcolorbox]
using System;
class Program
{
    public static void Main(string[] args)
    {
        Console.WriteLine("Hello, world!");
    }
}
\end{pygmented}
\end{Example}

Any option unknown to Pygmen\TeX{} are passed to the enclosing command
or environment.

For instance:

\begin{Example}
\begin{pygmented}[lang=xml,boxing method=tcolorbox,colframe=red,boxrule=2mm]
<!-- This is a note -->
<note>
   <to>Tove</to>
   <from>Jani</from>
   <heading>Reminder</heading>
   <body>Don't forget me this weekend!</body>
</note>
\end{pygmented}
\end{Example}

\section{Setting global options for Pygmen\TeX{}}

Global options can be setting using the \verb|setpygmented| command.
See the examples that follows.

\begin{Example}
\setpygmented{lang=haskell, colback=red!30, font=\ttfamily\small}

\begin{pygmented}[]
sum :: Num a => [a] -> a
sum [] = 0
sum (x:xs) = x + sum xs
\end{pygmented}
\end{Example}

\begin{Example}
\begin{pygmented}[colback=blue!20, boxing method=tcolorbox]
elem :: Eq a => a -> [a] -> Bool
elem _ [] = False
elem x (y:ys) = x == y || elem x ys
\end{pygmented}
\end{Example}

\begin{Example}
\setpygmented{lang=snobol}

\begin{pygmented}[]
          OUTPUT = "What is your name?"
          Username = INPUT
          OUTPUT = "Thank you, " Username
END
\end{pygmented}
\end{Example}

\begin{Example}
\setpygmented{test/.style={colback=yellow!33,boxing method=tcolorbox,colframe=blue}}

\begin{pygmented}[test, lang=vbnet]
Module Module1
    Sub Main()
        Console.WriteLine("Hello, world!")
    End Sub
End Module
\end{pygmented}
\end{Example}

\begin{Example}
\begin{pygmented}[lang=tcl]
puts "Hello, world!"
\end{pygmented}
\end{Example}

\section{More examples of inline code snippets}

\begin{Example}
  An inline source code snippet:
  \pyginline[lang=c]|const double alfa = 3.14159;|.
  This is a C declaration with initialization.
\end{Example}

\begin{Example}
  \pyginline[lang=prolog,colback=yellow]=avo(A,B) :- pai(A,X), pai(X,B).=
  is a Prolog clause. Its head is
  \pyginline[lang=prolog,sty=emacs,colback=yellow,linecolor=red]=avo(A,B)=
  and its body is
  \pyginline[lang=prolog,sty=vim,colback=black,hidealllines]=pai(A,X), pai(X,B)=.
\end{Example}

\begin{Example}
  See the identifier \pyginline[inline method=efbox,colback=green!25]|variable|,
  which names something. String literals in C looks like
  \pyginline[lang=c,inline method=tcbox,colback=blue!20,boxrule=2pt]|"hello, world!\n"|.
\end{Example}

\setpygmented{colback=shadecolor}

\begin{Example}
  This one
  \pyginline[lang=ocaml,font=\ttfamily\scriptsize,topline=false]:let x = [1;2;3] in length x:
  is an OCaml expression with local bindings. With OCaml one can do
  imperative, functional and object oriented programming.
\end{Example}

\begin{Example}
  Now some Java code:
  \pyginline[lang=java,sty=colorful,font=\ttfamily\itshape,linewidth=1pt]|public int f(double x)|.
  This is a method header.
\end{Example}

\section{More examples of displayed code snippets}

\setpygmented{lang=scheme,colback=shadecolor,sty=emacs}

In listing \ref{lst:fact} you can see a function definition in the
Scheme language. This function computes the factorial of a natural
number.
\newline\rule{\linewidth}{2pt}
\begin{pygmented}[
  sty=emacs,
  linenos,
  label=lst:fact,
  caption=A Scheme function.
  ]
(define fact
    (lambda (n)
        (if (= n 0)
            1
            (* n (fact (- n 1))))))
\end{pygmented}

Here you have some more code to further testing the package. Listing
\ref{lst:haskell} is a Haskell program. When run this program interacts
with the user asking the user name, reading a line input by the user,
and showing a greeting message to the user.

\inputpygmented[%
  lang=haskell,
  linenos,
  linenostart=79831,
  innerlinecolor=yellow, innerlinewidth=6pt,
  middlelinecolor=blue, middlelinewidth=10pt,
  outerlinecolor=green, outerlinewidth=12pt,
  roundcorner=4,
  colback=shadecolor,
  caption=A haskell interactive program,
  label=lst:haskell,
  ]{pygmentex_demo.hs}

This is a rule:

\noindent\rule{\linewidth}{2pt}

Now a Pascal procedure:

\inputpygmented[
  lang=delphi,
  linewidth=1.5pt,
  font=\ttfamily\sffamily\large,
  colback=yellow
  ]{pygmentex_demo.delphi}
and a Pascal program
\inputpygmented[lang=pascal,linenos,linenostart=5801]{pygmentex_demo.pas}

A Python code snippet:

\inputpygmented[
  lang=python,
  sty=emacs,
  linenos,
  linenostep=3,
  linewidth=1pt,
  colback=lightgreen
  ]{pygmentex_demo.py}

\section{Using code snippets in environments}

The following is a \textbf{description} environment.

\begin{description}
  \item[An item] \lipsum[31]
  \begin{pygmented}[lang=scala,colback=yellow,
    % title=Item A
    ]
def qsort(xs: List[Int]): List[Int] =
  xs match {
    case Nil =>
      Nil
    case pivot :: tail =>
      qsort(tail filter { _ < pivot }) :::
        pivot :: qsort(tail filter { _ >= pivot })
  }
  \end{pygmented}
  \lipsum[32]

  \item[Another item] \lipsum[33]
  \begin{pygmented}[lang=lua,colback=yellow]
function entry0 (o)
  N=N + 1
  local title = o.title or '(no title)'
  fwrite('<LI><A HREF="#%d">%s</A>\n', N, title)
end
  \end{pygmented}
  \lipsum[34]
\end{description}

\section{A long program}

Here you can read the source code for a hand written lexical analyser
for the \emph{straight-line} programming language that I have developed
in Java.

\inputpygmented[boxing method=mdframed,lang=java,sty=autumn,colback=red!8,font=\ttfamily\small,tabsize=2,frametitle=\emph{Ad hoc} lexical analyser]{pygmentex_demo.java}

\section{Some fancy examples using \texttt{tcolorbox}}

The followig example uses \texttt{tcolorbox} to typeset the code
listing.

\newcounter{example}
\newlength{\examlen}
\colorlet{colexam}{red!75!black}

\begin{pygmented}[boxing method=tcolorbox,lang=scala,
  title=Example \arabic{example}: hello from \texttt{Scala},
  code={\refstepcounter{example}%
        \settowidth{\examlen}{\Large\bfseries Example \arabic{example}}},%
  coltitle=colexam,fonttitle=\Large\bfseries,
  enhanced,breakable,
  before=\par\medskip,
  parbox=false,
  frame hidden,interior hidden,segmentation hidden,
  boxsep=0pt,left=0pt,right=3mm,toptitle=2mm,pad at break=0mm,
  overlay unbroken={\draw[colexam,line width=1pt] (frame.north west)
    --([xshift=-0.5pt]frame.north east)--([xshift=-0.5pt]frame.south east)
    --(frame.south west);
    \draw[colexam,line width=2pt] ([yshift=0.5pt]frame.north west)
    -- +(\examlen,0pt);},
  overlay first={\draw[colexam,line width=1pt] (frame.north west)
    --([xshift=-0.5pt]frame.north east)--([xshift=-0.5pt]frame.south east);
    \draw[red!75!black,line width=2pt] ([yshift=0.5pt]frame.north west)
    -- +(\examlen,0pt);},
  overlay middle={\draw[colexam,line width=1pt] ([xshift=-0.5pt]frame.north east)
    --([xshift=-0.5pt]frame.south east); },
  overlay last={\draw[colexam,line width=1pt] ([xshift=-0.5pt]frame.north east)
    --([xshift=-0.5pt]frame.south east)--(frame.south west);}%
  ]
object HelloWorld extends App {
  println("Hello, world!")
}\end{pygmented}

\begin{pygmented}[boxing method=tcolorbox,lang=java,
  enhanced,colback=blue!10!white,colframe=orange,top=4mm,
  enlarge top by=\baselineskip/2+1mm,
  enlarge top at break by=0mm,pad at break=2mm,
  fontupper=\normalsize,
  overlay unbroken and first={%
    \node[rectangle,rounded corners,draw=black,fill=blue!20!white,
    inner sep=1mm,anchor=west,font=\small]
    at ([xshift=4.5mm]frame.north west) {\strut\textbf{My fancy title}};},
  ]
public class Hello {
  public static void main(String[] args) {
    System.out.println("Hello, world!")
  }
}
\end{pygmented}

\begin{pygmented}[boxing method=tcolorbox,lang=haskell,
  enhanced,sharp corners=uphill,
  colback=blue!25!white,colframe=blue!25!black,coltext=blue!90!black,
  fontupper=\Large\bfseries,arc=6mm,boxrule=2mm,boxsep=5mm,
  borderline={0.3mm}{0.3mm}{white}
  ]
module Main (main) where

main :: IO ()
main = putStrLn "Hello, world!"
\end{pygmented}

\begin{pygmented}[boxing method=tcolorbox,lang=c++,
  enhanced,frame style image=blueshade.png,
  opacityback=0.75,opacitybacktitle=0.25,
  colback=blue!5!white,colframe=blue!75!black,
  title=My title
  ]
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
  cout << "Hello, world!" << endl;
  return 0;
}
\end{pygmented}

\begin{pygmented}[boxing method=tcolorbox,lang=d,
  enhanced,attach boxed title to top center={yshift=-3mm,yshifttext=-1mm},
  colback=blue!5!white,colframe=blue!75!black,colbacktitle=red!80!black,
  title=My title,fonttitle=\bfseries,
  boxed title style={size=small,colframe=red!50!black}
  ]
/* This program prints a
   hello world message
   to the console.  */

import std.stdio;

void main()
{
    writeln("Hello, World!");
}
\end{pygmented}


\section{Some fancy examples using \texttt{mdframed}}

The followig example uses \texttt{mdframed} to typeset the code listing.

\global\mdfdefinestyle{exampledefault}{%
  linecolor=red,linewidth=3pt,%
  leftmargin=1cm,rightmargin=1cm
}

\begin{pygmented}[boxing method=mdframed,lang=ada,style=exampledefault]
with Ada.Text_IO;

procedure Hello_World is
 use Ada.Text_IO;
begin
    Put_Line("Hello, world!");
end;
\end{pygmented}

\global\mdfapptodefinestyle{exampledefault}{%
  topline=false,bottomline=false,
}

\begin{pygmented}[boxing method=mdframed,lang=pascal,style=exampledefault,frametitle={Saying \emph{hello} from Pascal}]
program HelloWorld;

begin
  WriteLn('Hello, world!');
end.
\end{pygmented}

\global\mdfdefinestyle{separateheader}{%
  frametitle={%
    \tikz[baseline=(current bounding box.east),outer sep=0pt]
    \node[anchor=east,rectangle,fill=blue!20]
    {\strut Saying \emph{hello} in Modula-2};},
  innertopmargin=10pt,linecolor=blue!20,%
  linewidth=2pt,topline=true,
  frametitleaboveskip=\dimexpr-\ht\strutbox\relax,
  frametitlerule=false,
  backgroundcolor=white,
}

\begin{pygmented}[boxing method=mdframed,lang=modula2,style=separateheader]
MODULE Hello;
FROM STextIO IMPORT WriteString;
BEGIN
  WriteString("Hello World!");
END Hello.
\end{pygmented}


\tikzset{titregris/.style =
     {draw=gray, thick, fill=white, shading = exersicetitle, %
      text=gray, rectangle, rounded corners, right,minimum height=.7cm}}
\pgfdeclarehorizontalshading{exersicebackground}{100bp}
          {color(0bp)=(green!40); color(100bp)=(black!5)}
\pgfdeclarehorizontalshading{exersicetitle}{100bp}
          {color(0bp)=(red!40);color(100bp)=(black!5)}
\newcounter{exercise}
\renewcommand*\theexercise{Exercise~n\arabic{exercise}}
\makeatletter
\def\mdf@@exercisepoints{}%new mdframed key:
\define@key{mdf}{exercisepoints}{%
    \def\mdf@@exercisepoints{#1}
}
\mdfdefinestyle{exercisestyle}{%
  outerlinewidth=1em,outerlinecolor=white,%
  leftmargin=-1em,rightmargin=-1em,%
  middlelinewidth=1.2pt,roundcorner=5pt,linecolor=gray,
  apptotikzsetting={\tikzset{mdfbackground/.append style ={%
                       shading = exersicebackground}}},
  innertopmargin=1.2\baselineskip,
  skipabove={\dimexpr0.5\baselineskip+\topskip\relax},
  skipbelow={-1em},
  needspace=3\baselineskip,
  frametitlefont=\sffamily\bfseries,
  settings={\global\stepcounter{exercise}},
  singleextra={%
      \node[titregris,xshift=1cm] at (P-|O) %
         {~\mdf@frametitlefont{\theexercise}\hbox{~}};
      \ifdefempty{\mdf@@exercisepoints}%
      {}%
      {\node[titregris,left,xshift=-1cm] at (P)%
        {~\mdf@frametitlefont{\mdf@@exercisepoints points}\hbox{~}};}%
   },
  firstextra={%
      \node[titregris,xshift=1cm] at (P-|O) %
         {~\mdf@frametitlefont{\theexercise}\hbox{~}};
      \ifdefempty{\mdf@@exercisepoints}%
      {}%
      {\node[titregris,left,xshift=-1cm] at (P)%
        {~\mdf@frametitlefont{\mdf@@exercisepoints points}\hbox{~}};}%
   },
}
\makeatother

\begin{pygmented}[boxing method=mdframed,lang=go,style=exercisestyle]
// hello world in 'go'
package main

import "fmt"

func main() {
   fmt.Println("Hello, world!")
}
\end{pygmented}

\begin{pygmented}[boxing method=mdframed,lang=objective-c,style=exercisestyle,exercisepoints=10]
/* hello from objective-c */

#import <stdio.h>
#import <Foundation/Foundation.h>

int main(void)
{
    NSLog(@"Hello, world!\n");
    return 0;
}
\end{pygmented}

\mdfdefinestyle{another}{%
  linecolor=red,middlelinewidth=2pt,%
  frametitlerule=true,%
  apptotikzsetting={\tikzset{mdfframetitlebackground/.append style={%
        shade,left color=white, right color=blue!20}}},
  frametitlerulecolor=green!60,
  frametitlerulewidth=1pt,
  innertopmargin=\topskip,
}

\begin{pygmented}[boxing method=mdframed,lang=c,style=another,frametitle={Hello from C}]
#include <stdio.h>
int main(int argc, char **argv) {
  printf("Hello, world!\n");
  return 0;
}
\end{pygmented}

\section{Debugging}
Paths given to \verb|\inputpygmented| should be relative to the top level project
directory, not to the file that contains the command (if that file is in a
subdirectory).  Pygmen\TeX generates only a single top-level \texttt{.snippets} file,
and paths are not munged to account for code in subdirectories.

\section{Conclusion}

That is all.

\end{document}
