# [OS X TeX] The listings package; pdf or text from pdf searches

John Maindonald john.maindonald at anu.edu.au
Wed Aug 15 19:19:11 EDT 2007

```I've found a slightly clumsy way to achieve what I want.   Set
the option 'columns' to 'fullflexible', in order to generate a
pdf file that does not have the unwanted hidden spaces,
and a text file that is similarly searchable.
(I've an R language routine that searches for functions in
the listings and elsewhere, identified by a suitable regular
expression that ends with '(', for purposes of creating an
index of functions.)

The setting 'columns=fullflexible'  messes up the formatting
in places where I use tabbing, so that I need to change
'columns' back to the default for the final pdf.

{\lstset{language=R, xleftmargin=2pt,
basicstyle=\ttfamily,
columns=fullflexible,           % Omit for final manuscript
showstringspaces=false}}
{}

John Maindonald             email: john.maindonald at anu.edu.au
phone : +61 2 (6125)3473    fax  : +61 2(6125)5549
Centre for Mathematics & Its Applications, Room 1194,
John Dedman Mathematical Sciences Building (Building 27)
Australian National University, Canberra ACT 0200.

On 15 Aug 2007, at 10:00 AM, TeX on Mac OS X Mailing List wrote:

> Subject: Re: The listings package; pdf or text from pdf searches
> From: "John Maindonald" <john.maindonald at anu.edu.au>
> Date: Tue, 14 Aug 2007 21:52:57 +1000
>
> I find that if for example I have 'dir()' in code that is used in the
> listings environment given below, then using Preview on the
> pdf file that results, I have to search for 'd i r ( )', i.e. spaces
> must be placed between characters.
>
> I tried pdftotext (a binary xpdf-tools-3.dmg that will install this
> under
> MacOS X is available from http://users.phg-online.de/tk/MOSXS/ )
>
> The text appears as 'dir ()', i.e., it removes most of the spaces,
> but leaves the space that precedes the '('.
>
> 'file.show("travelbooks.txt")'  appears, in the file from pdfotext, as
> 'file . show ( " travelbooks . txt " )'
>
> I've tried several pdf to text  conversion utilities; all seem to give
> much the same result.
>
> Does anyone know of a good way to use the listings package,
> and/or some alternative choice of pdf to text conversion software,
> that creates a file where the text is searchable pretty much as
> one would expect?  Is there a choice of listings options
> (a different basicstyle?) that avoids the unwanted spaces?
>
> \definecolor{light}{gray}{.9}
> \lstnewenvironment{verbcode}
> {\lstset{language=R, xleftmargin=2pt, frame=single, framerule=0pt,
>            basicstyle=\ttfamily,
>           showstringspaces=false, backgroundcolor=\color{light}}}
> {}
>
> John Maindonald.