diff options
author | Karl Berry <karl@freefriends.org> | 2011-08-07 23:40:10 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2011-08-07 23:40:10 +0000 |
commit | 7822e32d4066bb81d8e6ed47697c93301b86fe9f (patch) | |
tree | f5eca2b975844d3853d1e21daccfc3419362cf7c /Master/texmf-dist | |
parent | 20ff44ce9e3f008751e5b3730036a2c97d5031df (diff) |
new latex package verbments (13jun11)
git-svn-id: svn://tug.org/texlive/trunk@23452 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r-- | Master/texmf-dist/doc/latex/verbments/README | 13 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/verbments/verbments.pdf | bin | 0 -> 82607 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/latex/verbments/verbments.tex | 284 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/verbments/verbments.sty | 142 |
4 files changed, 439 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/latex/verbments/README b/Master/texmf-dist/doc/latex/verbments/README new file mode 100644 index 00000000000..46723a18afe --- /dev/null +++ b/Master/texmf-dist/doc/latex/verbments/README @@ -0,0 +1,13 @@ +verbments (v1.1) -- syntax highlighting of source code in LaTeX documents + +The verbments package provides an environment for syntax highlighting +of source code in LaTeX documents. The highlighted source code output is +formatted via powerful Pygments library of the Python language. + +See the documentation (verbments.pdf) for examples and instructions for +installation and usage. + +This work may be distributed and/or modified under the conditions of the +LaTeX Project Public License, either version 1.2 of this license or (at your +option) any later version. Additionally, the project may be distributed +under the terms of the new BSD license. diff --git a/Master/texmf-dist/doc/latex/verbments/verbments.pdf b/Master/texmf-dist/doc/latex/verbments/verbments.pdf Binary files differnew file mode 100644 index 00000000000..5465b5ef5eb --- /dev/null +++ b/Master/texmf-dist/doc/latex/verbments/verbments.pdf diff --git a/Master/texmf-dist/doc/latex/verbments/verbments.tex b/Master/texmf-dist/doc/latex/verbments/verbments.tex new file mode 100644 index 00000000000..069220b6e38 --- /dev/null +++ b/Master/texmf-dist/doc/latex/verbments/verbments.tex @@ -0,0 +1,284 @@ +% This file requires Pygments and Python installed on the computer, +% as well as the --shell-escape LaTeX compiler option +% +\documentclass{article} + +\usepackage{doc} +\usepackage{url,multicol} +\usepackage{hyperref} +\usepackage{verbments} + +\hypersetup{ + pdftitle=The verbments package: Pretty printing source code in LaTeX, + pdfauthor=Dejan Zivkovic, + pdfsubject={verbments LaTeX package manual}, + colorlinks, linkcolor={DarkBlue}, + citecolor={black}, urlcolor={black} +} + +% Special dashes +\def\thinskip{\hskip 0.16667em\relax} +\def\endash{--} +\def\emdash{\endash-} +\def\d@sh#1#2{\unskip#1\thinskip#2\thinskip\ignorespaces} +\def\dash{\d@sh\nobreak\endash} +\def\Dash{\d@sh\nobreak\emdash} + +% A list of options for a package/class +\newenvironment{optlist}{\begin{description}% + \renewcommand\makelabel[1]{% + \descriptionlabel{\mdseries\textsf{##1}}}% + \itemsep0.25\itemsep}% + {\end{description}} +% +\newenvironment{verlist}{\begin{description}% + \renewcommand\makelabel[1]{% + \descriptionlabel{\bfseries{##1}}}% + \itemsep0.25\itemsep}% + {\end{description}} +% +\setlength{\parindent}{0pt} +\addtolength{\parskip}{0.3\baselineskip} +\setlength{\columnseprule}{0.6pt} +\newcommand{\vmPackage}{\texttt{verbments}} +\MakeShortVerb{\|} + +\begin{document} + +\title{The \vmPackage{} package:\\Pretty printing source code in \LaTeX\thanks{This work has been supported by the Serbian Ministry of Education and Science (project III44006).}} +\author{Dejan \v{Z}ivkovi\'{c}\\{\small Singidunum University, Serbia}\\[-1mm]{\footnotesize\href{mailto:dzivkovic@singidunum.ac.rs} + {\nolinkurl{dzivkovic@singidunum.ac.rs}}}} +\date{Version 1.1\\ July 7, 2011} + +\maketitle + +\begin{abstract} +\noindent The \vmPackage{} package provides an environment for syntax highlighting of source code in \LaTeX{} documents. The highlighted source code output is formatted via powerful Pygments library of the Python language. +\end{abstract} + +\begin{multicols}{2} +\setlength{\parskip}{0pt} +\tableofcontents +\end{multicols} + +\section{Introduction} + +The \vmPackage{} package overcomes some deficiencies of two other popular packages for pretty printing source code in \LaTeX{}. Namely, the \texttt{listings} package is relatively old and lacks the utf-8 support. On the other hand, the \texttt{minted} package cannot split the highlighted source code over pages, nor it provides an option for individual highlighting styles. + +The \vmPackage{} package uses \texttt{minted} idea to delegate the task of actual syntax markup of the source code to an external software\Dash the Pygments library. Marked code is then typeset using the \texttt{fancyvrb} and \texttt{framed} packages. (The package name \emph{verbments} tries to convey this as being a compound word resembling two words \emph{verbatim} and \emph{pygments}.) + +Pygments is written in Python and provides far superior syntax highlighting compared to conventional packages. For example, \texttt{listings} basically only highlights strings, comments, and keywords. Pygments, on the other hand, can be completely customized to markup any token of the source language. Furthermore, the number of supported languages is clearly in favor of Pygments with over 150 different programming and other languages supported. More information on Python and Pygments can be found at \url{http://python.org} and \url{http://pygments.org}. + +\section{Installation} + +Installation of the \vmPackage{} package itself is simple\Dash the \vmPackage{}.\texttt{sty} file only needs to be on the path where \LaTeX{} can find it. However, \vmPackage{} additionally requires that the Python language and its Pygments library are installed on the computer. + +Python and Pygments are free software and can be downloaded from their web sites. Bear in mind that Windows support is sketchy at the moment, but instructions to properly configure the software may be found elsewhere on the Internet. (For example, good starting point is the documentation of the \texttt{minted} package.) + +\section{Usage} + +\DescribeEnv{{-}{-}shell-escape} +First of all, don't forget to call the \LaTeX{} complier (\texttt{latex}, \texttt{pdflatex}, or \texttt{xelatex}) by passing it the \texttt{{-}{-}shell-escape} option. + +\DescribeEnv{pyglist} +Using \vmPackage{} in a \LaTeX{} document is straightforward\Dash you simply enclose a source code in the \texttt{pyglist} environment: + +\def\lb{\{} +\def\rb{\}} +\begin{Verbatim}[commandchars=+\{\},gobble=1,fontsize=\MacroFont] +\begin+lb{pyglist}+rb[+meta{options}] + +meta{source code} +\end+lb{pyglist}+rb +\end{Verbatim} + +The \texttt{pyglist} environment accepts a number of options in the \texttt{key=value} notation. For example, to highlight a Java source code, you may use the following \texttt{pyglist} environment: + +\begin{verbatim} +\begin{pyglist}[language=java] +// Hello Java program +import java.util.*; +public class Hello { + public static void main(String[] args) { + Scanner kb = new Scanner(System.in); + System.out.print("What is your name? "); + String name = kb.nextLine(); + System.out.println("Hello " + name + "!"); + } +} +\end{pyglist} +\end{verbatim} + +This environment uses the default Pygments style and it is typeset as follows: + +\bigskip +\begin{pyglist}[language=java,fontsize=\MacroFont] +// Hello Java program +import java.util.*; +public class Hello { + public static void main(String[] args) { + Scanner kb = new Scanner(System.in); + System.out.print("What is your name? "); + String name = kb.nextLine(); + System.out.println("Hello " + name + "!"); + } +} +\end{pyglist} + +If the \texttt{texcl=true}, \texttt{style=vs} and \texttt{bgcolor=Moccasin} options are added to the option list of the previous \texttt{pyglist} environment for the similar Java code, i.e., + +\begin{verbatim} +\begin{pyglist}[language=java,texcl=true,style=vs,bgcolor=Moccasin] +// \fbox{Hello} Java program + + . . . + +\end{pyglist} +\end{verbatim} + +then the code is typeset with the Visual Studio style and Moccasin background color: + +\bigskip +\begin{pyglist}[language=java,texcl=true,style=vs,bgcolor=Moccasin,fontsize=\MacroFont] +// \fbox{Hello} Java program +import java.util.*; +public class Hello { + public static void main(String[] args) { + Scanner kb = new Scanner(System.in); + System.out.print("What is your name? "); + String name = kb.nextLine(); + System.out.println("Hello " + name + "!"); + } +} +\end{pyglist} + +\bigskip +\DescribeMacro{\plset} +Since the option list of the \texttt{pyglist} environment may become lengthy, options can be globally specified using the |\plset| command. For example: + +\begin{verbatim} +\plset{language=java,texcl=true,style=vs,bgcolor=Moccasin} +\end{verbatim} + +With these options set in this way then, to get the previous highlighted code it is enough to specify: + +\begin{verbatim} +\begin{pyglist} +// \fbox{Hello} Java program + + . . . + +\end{pyglist} +\end{verbatim} + +\bigskip +\DescribeMacro{\listofpyglistings} +If source code listings in a document are decorated with captions, their list can be produced with the |\listofpyglistings| command. This is akin to list of figures, list of tables and other table-of-contents counterparts. + +\bigskip +\DescribeMacro{\listofpyglistingsname} +Heading of the list of listings is |Listings| by default. This can be changed using the |\listofpyglistingsname| command. For example: + +\begin{verbatim} +\listofpyglistingsname{List of Programs} +\end{verbatim} + + +\begin{center}*\quad*\quad*\end{center}\nopagebreak[4] + +The \texttt{pyglist} environment is actualy typeset using the \texttt{Verbatim} environment of the \texttt{fancyvrb} package. That's why all \texttt{Verbatim} options are also in effect in the \texttt{pyglist} environment. For example, + +\begin{verbatim} +\fvset{frame=single} +\begin{pyglist}[language=c,style=tango,numbers=left,numbersep=5pt] +/* Hello World program */ + +#include<stdio.h> + +main() +{ + printf("Hello World"); +} +\end{pyglist} +\fvset{frame=none} +\end{verbatim} + +produces the following result: + +\bigskip +\fvset{frame=single} +\begin{pyglist}[language=c,style=tango,numbers=left,numbersep=5pt,fontsize=\MacroFont] +/* Hello World program */ + +#include<stdio.h> + +main() +{ + printf("Hello World"); +} +\end{pyglist} +\fvset{frame=none} + +\medskip +For a more detailed \texttt{Verbatim} option descriptions, please refer to the documentation of the \texttt{fancyvrb} package. + +\section{Options} + +The following is a full list of available options for the \texttt{pyglist} environment. + +\begin{optlist} + \item[abovecaptionskip (dimension)] + White space length above caption of the listing (default: |\bigskipamount|). + \item[belowcaptionskip (dimension)] + White space length below caption of the listing (default: |0pt|). + \item[bgcolor (color name)] + Background color of the listing (default: |white|). + \item[caption (string)] + Caption text of the listing (default: \emph{none}). + \item[encoding (string)] + Encoding of intermediate input and output files with syntax markup used by Pygments (default: |latin1|). For more information, please refer to the Pygments documentation. + \item[fontsize (font size)] + Font size to use for the listing (default: |auto|\Dash the same as the +current font). + \item[gobble (integer)] + Removes the first $n$ characters from each input line of the source code (default: |0|). + \item[language (string)] + Language of the source code whose syntax is to be highlighted by Pygments (default: |text|). For more information, please refer to the Pygments documentation. + \item[label (string)] + Label that makes the listing referable via |\ref{label}| (default: \emph{none}). + \item[listingname (string)] + Caption label to use as a prefix to the caption text of the listing (default: |Listing|). + \item[mathescape (boolean)] + Enables \LaTeX{} math mode inside comments (default: |false|). + \item[numbers (none$\mid$left$\mid$right)] + Numbering of the listing lines (default: \emph{none}). + \item[numbersep (dimension)] + Gap between numbers and start of the listing lines (default: |12pt|). + \item[showspaces (boolean)] + Enables visible spaces. The space character is printed as the symbol \verb*/ / (default: |false|). + \item[style (string)] + Style for Pygments to use for the source code highlighting (default: |default|). For more information, please refer to the Pygments documentation. + \item[texcl (boolean)] + Enables \LaTeX{} code inside comments (default: |false|). +\end{optlist} + +\section{Todo list} + +\begin{itemize} +\item Implement package distribution file. (Problems: (1) the \% sign in the Pygments style file is gobbled up by |\DocStrip| in examples; (2) spurious blanks appear in the highlighted example code.) +\item Implement escape sequences. (This is probably more suitable task for Pygments lexers and formatters?) +\item More testing. +\end{itemize} + +\section{Version history} + +\begin{verlist} +\item[v1.1\quad 2011/07/07] \mbox{}\\ +Added the |\listofpyglistingsname| user command\\ +Changed handling of the list of listings\\ +Revised documentation and examples + +\item[v1.0\quad 2011/06/07] \mbox{}\\ +Initial public release +\end{verlist} + +\end{document} diff --git a/Master/texmf-dist/tex/latex/verbments/verbments.sty b/Master/texmf-dist/tex/latex/verbments/verbments.sty new file mode 100644 index 00000000000..cbcb8c64661 --- /dev/null +++ b/Master/texmf-dist/tex/latex/verbments/verbments.sty @@ -0,0 +1,142 @@ +% verbments.sty v1.1 2011/07/07 +% +% Copyright (C) 2011 by Dejan Zivkovic +% ----------------------------------- +% +% This file may be distributed and/or modified under the +% conditions of the LaTeX Project Public License, either version 1.2 +% of this license or (at your option) any later version. +% The latest version of this license is in: +% +% http://www.latex-project.org/lppl.txt +% +% and version 1.2 or later is part of all distributions of LaTeX +% version 1999/12/01 or later. +% +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{verbments}[2011/07/07 v1.1 Pygments/fancyvrb source code highlighting for LaTeX] +\RequirePackage[svgnames]{xcolor} +\RequirePackage{xkeyval,fancyvrb,framed} +% +\newcommand{\@listofpyglistingsname}{Listings}% +\newcommand{\listofpyglistingsname}[1]{% +\renewcommand\@listofpyglistingsname{#1}} +\newcommand{\listofpyglistings}{% + \begingroup + \let\contentsname\@listofpyglistingsname + \let\@pygtoc\@starttoc \def\@starttoc##1{\@pygtoc{pyg.lol}}% + \tableofcontents% + \endgroup +} +\newcommand{\lol@caption}[1]{% + \addcontentsline{pyg.lol}{pyglist}{#1} +} +\newcommand{\l@pyglist}[2]{% + \@dottedtocline{1}{1.5em}{2.3em}{#1}{#2} +} +% +\newlength{\@tmpwidth} +% +\newskip\@tmpskipa +\def\max@vskip #1{% + \@tmpskipa = #1\relax + \ifdim\lastskip < \@tmpskipa + \ifdim\lastskip = 0pt + \else \vskip -\lastskip + \fi + \vskip \@tmpskipa + \fi% +} + +\setlength{\FrameSep}{0pt} +\setlength{\FrameRule}{0pt} +% +\define@cmdkey{pyglist}[pl@]{caption}{} +\define@cmdkey{pyglist}[pl@]{abovecaptionskip}[\bigskipamount]{} +\define@cmdkey{pyglist}[pl@]{belowcaptionskip}[0pt]{} +\define@cmdkey{pyglist}[pl@]{listingname}[Listing]{} +\define@cmdkey{pyglist}[pl@]{label}{} +% +\define@cmdkey{pyglist}[pl@]{bgcolor}[white]{} +\define@cmdkey{pyglist}[pl@]{language}[text]{} +\define@cmdkey{pyglist}[pl@]{encoding}[latin1]{} +\define@boolkey{pyglist}[pl@]{mathescape}[false]{} +\define@boolkey{pyglist}[pl@]{texcl}[false]{} +\define@cmdkey{pyglist}[pl@]{style}[default]{} +\define@cmdkey{pyglist}[pl@]{gobble}[0]{} +% +\define@cmdkey{pyglist}[pl@]{fontsize}{} +\define@cmdkey{pyglist}[pl@]{numbers}{} +\define@cmdkey{pyglist}[pl@]{numbersep}{} +\define@boolkey{pyglist}[pl@]{showspaces}[false]{} + +\newcommand\plset[1]{% + \setkeys{pyglist}{#1}% +} + +\newenvironment{pyglist}{% + \catcode`\^^M=\active + \@ifnextchar[% + {\catcode`\^^M=5 \pyglist@} + {\catcode`\^^M=5 \pyglist@[]} +}{% + \end{VerbatimOut}% + \immediate\write18{\pyg@cmd} + \immediate\write18{\pyg@style} + \input{\jobname.pyg.sty}% +% + \partopsep = 0pt\parskip = 0pt\parindent = 0pt% + \@ifundefined{pl@caption}% + {\setlength{\topsep}{-2pt}}% + {\par% + \allowbreak% + \max@vskip{\pl@abovecaptionskip}% + \refstepcounter{pllisting}% + \@ifundefined{pl@label}{}{\label{\pl@label}}% + \settowidth{\@tmpwidth}{\bfseries\pl@listingname~\thepllisting:\space}% + \mbox{\bfseries\pl@listingname~\thepllisting:\space}% + \parbox[t]{\linewidth-\@tmpwidth}{\pl@caption}% + \par\nobreak\vskip\pl@belowcaptionskip\nobreak% + \setlength{\topsep}{\smallskipamount}% + \lol@caption{\rlap{\thepllisting}\hskip5ex \pl@caption} + }% +% + \@ifundefined{pl@fontsize}{}{\fvset{fontsize=\pl@fontsize}}% + \@ifundefined{pl@numbers}{}{\fvset{numbers=\pl@numbers}}% + \@ifundefined{pl@numbersep}{}{\fvset{numbersep=\pl@numbersep}}% + \ifpl@showspaces\fvset{showspaces}\fi% +% + \definecolor{shadecolor}{named}{\pl@bgcolor}% + \begin{snugshade} + \input{\jobname.pyg.vrb} + \end{snugshade} +} + +\def\pyglist@[#1]{% + \setkeys{pyglist}{#1} + \edef\pyg@cmd{pygmentize -P encoding=\pl@encoding\space -l \pl@language\space + -F tokenmerge \ifnum\pl@gobble=0\space \else -F gobble:n=\pl@gobble\space\fi + -f latex + \ifpl@texcl -P texcomments\space\fi + \ifpl@mathescape -P mathescape\space\fi + -o \jobname.pyg.vrb \jobname.pyg.lst} + \edef\pyg@style{pygmentize -S \pl@style\space -f latex > \jobname.pyg.sty} + \VerbatimEnvironment + \begin{VerbatimOut}{\jobname.pyg.lst}% No char whatsoever to the next brace +} + +\AtBeginDocument{ + \@ifundefined{thechapter}{ + \newcounter{pllisting} + \gdef\thepllisting{\@arabic\c@pllisting} + }{ + \newcounter{pllisting}[chapter] + \gdef\thepllisting% + {\ifnum \c@chapter>\z@ \thechapter.\fi \@arabic\c@pllisting} + } +} + +\plset{abovecaptionskip,belowcaptionskip,listingname,% + bgcolor,language,encoding,mathescape,texcl,style,gobble,% + showspaces} % set default key values +\endinput |