Possible Duplicate:
Syntax Coloring in LaTeX
I want to add source code of my program in document but verbatim really bugs me. All that ugly fonts and stuff.
Possible Duplicate:
Syntax Coloring in LaTeX
I want to add source code of my program in document but verbatim really bugs me. All that ugly fonts and stuff.
I suggest using listings package.
For example
\documentclass[twocolumn,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[turkish]{babel}
\usepackage{listings}
\lstset{language=C++}
\lstset{breaklines=true}
\begin{document}
\newpage
\onecolumn
\begin{lstlisting}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <math.h>
typedef struct word //struct to contain words
{
char *string;
} word;
void print(int ** matrix, char str [], int n)
//this is a comment too long to fit on a line. So listings will break this line because I used \lstset{breaklines=true} But this is not default
{
printf("--- %s ---\n",str);
int i,j;
for(i=1; i<=n; i++)
{
for(j=1; j<=n; j++)
if(matrix[i][j]!=INT_MAX)
printf("%3d ",matrix[i][j]);
else(printf("%3s ","INF"));
printf("\n");
}
}
\end{lstlisting}
\end{document}
Produces this output with LaTeX
As you can see \lstset{language=C++} defines the language in code. I prefer this approach because I think it is easier to read.