2

I want to export my Notepad++ highlighted code into LaTeX. Is it possible?

Note that my codes are PHP codes.

ilhan
  • 99

1 Answers1

4

Consider using lstset from the listings package. Note that any option you don't want globally (or technically, global to the current group) can be set as part of the optional argument to \begin{lstlisting}.

\documentclass{article}
\usepackage{xcolor} % for more colors

\usepackage{listings}
\lstset{
        basicstyle=\small\ttfamily,
       stringstyle=\color{black!40!white}\ttfamily,
      keywordstyle=\color{blue},
      commentstyle=\color{green!50!black},
  showstringspaces=false,
   backgroundcolor=\color{black!5!white}
}


\usepackage{framed} % for contrast
\begin{document}
% Example source from http://php.net/manual/en/function.readdir.php
\begin{framed}
\begin{lstlisting}[language=php]
<?php

if ($handle = opendir('/path/to/files')) {
    echo "Directory handle: $handle\n";
    echo "Entries:\n";

    /* This is the correct way to
       loop over the directory. */
    while (false !== ($entry = readdir($handle))) {
        echo "$entry\n";
    }

    /* This is the WRONG way to
       loop over the directory. */
    while ($entry = readdir($handle)) {
        echo "$entry\n";
    }

    closedir($handle);
}
?>
\end{lstlisting}
\end{framed}
\end{document}

output

Sean Allred
  • 27,421