Notepad++ 将高亮显示的代码放入 LaTeX 中?

Notepad++ 将高亮显示的代码放入 LaTeX 中?

我想将 Notepad++ 高亮的代码导出到 LaTeX。可以吗?

请注意,我的代码是 PHP 代码。

答案1

考虑lstsetlistings包中使用。请注意,您不需要全局(或从技术上讲,对当前组全局)的任何选项都可以设置为 的可选参数的一部分\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}

输出

相关内容