Skip to content

Instantly share code, notes, and snippets.

@emir-munoz
Created January 10, 2016 19:01
Show Gist options
  • Save emir-munoz/ae2261f73b112c715b83 to your computer and use it in GitHub Desktop.
Save emir-munoz/ae2261f73b112c715b83 to your computer and use it in GitHub Desktop.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[spanish]{babel}
\usepackage{times}
\usepackage{color}
\definecolor{gray97}{gray}{.97}
\definecolor{gray75}{gray}{.75}
\definecolor{gray45}{gray}{.45}
\usepackage{listings}
\lstset{ frame=Ltb,
framerule=0pt,
aboveskip=0.5cm,
framextopmargin=3pt,
framexbottommargin=3pt,
framexleftmargin=0.4cm,
framesep=0pt,
rulesep=.4pt,
backgroundcolor=\color{gray97},
rulesepcolor=\color{black},
texcl=true,
%
stringstyle=\ttfamily,
showstringspaces = false,
basicstyle=\small\ttfamily,
commentstyle=\color{gray45},
keywordstyle=\bfseries,
%
numbers=left,
numbersep=15pt,
numberstyle=\tiny,
numberfirstline = false,
breaklines=true,
}
% minimize listing breaks
\lstnewenvironment{listing}[1][]
{\lstset{#1}\pagebreak[0]}{\pagebreak[0]}
\lstdefinestyle{consola}
{basicstyle=\scriptsize\bf\ttfamily,backgroundcolor=\color{gray75}}
\lstdefinestyle{C}
{language=C}
\begin{document}
Write the following code in a file named \texttt{hello.c}:
\begin{lstlisting}[style=C]
// This is the smallest C program
// This code is in \LaTeX{} (inline)
#include <stdio.h>
int main(int argc, char* argv[]) {
puts("Hello World!");
}
\end{lstlisting}
This is the same importing the code from a file:
% \lstinputlisting[style=C, firstline=3]{hello.c}
Now compile it using \texttt{gcc}:
\begin{listing}[style=consola, numbers=none]
$ gcc -o hello hello.c
\end{listing}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment