Lisp HUG Maillist Archive

Printing Lisp sources in color...

Hi,

It seems to me that LispWorks for Mac can only print in black & white  
(or I am missing something). I would like to have a printout, or  
actually a PDF file, that includes syntax coloring for my Lisp sources.

Does anyone know how to achieve that? (I also have access to a  
Windows machine, if that helps...)


Any help is appreciated!

Cheers,
Pascal

-- 
OOPSLA'05 tutorial on generic functions & the CLOS Metaobject Protocol
++++ see http://p-cos.net/oopsla05-tutorial.html for more details ++++

Pascal Costanza, mailto:pc@p-cos.net, http://p-cos.net
Vrije Universiteit Brussel, Programing Technology Lab
Pleinlaan 2, B-1050 Brussel, Belgium




Re: Printing Lisp sources in color...

Hi Pascal,
On Aug 16, 2005, at 1:39 PM, Pascal Costanza wrote:

> It seems to me that LispWorks for Mac can only print in black &  
> white (or I am missing something). I would like to have a printout,  
> or actually a PDF file, that includes syntax coloring for my Lisp  
> sources.
>
> Does anyone know how to achieve that? (I also have access to a  
> Windows machine, if that helps...)


Black and white is all I have seen.

The only way I have approached doing this with the LispWorks editor  
is to convert to HTML/CSS or Docbook XML and then use some other tool  
to print it.


John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL


Re: Printing Lisp sources in color...

Hi Pascal,

Google for 'lgrind' if you're willing to use LaTeX. I did some customization
of fonts etc. and it should be easy enough to extend that to colors. lgrind
may be too limited for your purposes. Let me know if you want my files or
other hints.

I used miktek for latex and dvipdf under cygwin to produce pdf's.

Jeff Caldwell

--- Pascal Costanza <pc@p-cos.net> wrote:

> Hi,
> 
> It seems to me that LispWorks for Mac can only print in black & white  
> (or I am missing something). I would like to have a printout, or  
> actually a PDF file, that includes syntax coloring for my Lisp sources.
> 
> Does anyone know how to achieve that? (I also have access to a  
> Windows machine, if that helps...)


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


Re: Printing Lisp sources in color...

"Pascal Costanza" <pc@p-cos.net> wrote:
> 
> It seems to me that LispWorks for Mac can only print in black & white  
> (or I am missing something). I would like to have a printout, or  
> actually a PDF file, that includes syntax coloring for my Lisp sources.
> 
> Does anyone know how to achieve that? (I also have access to a  
> Windows machine, if that helps...)

Have you looked at cl-typesetting ? There is a simple lisp formatter in it.
Fixes and improvements welcome ;-) 

The formatter formatted by itself: 
http://www.fractalconcept.com/pprint.pdf

Marc



Re: Printing Lisp sources in color...

Pascal Costanza <pc@p-cos.net> wrote:

> It seems to me that LispWorks for Mac can only print in black & white
> (or I am missing something). I would like to have a printout, or
> actually a PDF file, that includes syntax coloring for my Lisp sources.
>
> Does anyone know how to achieve that? (I also have access to a
> Windows machine, if that helps...)

Here's my quick and dirty Elisp for converting some Emacs buffer into 
HTML:

------------------------------------8<------------------------------------
(defun replace-string* (from to)
  (while (search-forward from (point-max) t)
    (backward-char 1)
    (let ((props (text-properties-at (point))))
      (delete-char (length from))
      (let ((string (format "%s" to)))
	(set-text-properties 0 (length string) props string)
	(insert string)))))

(defun faces:save-as-html ()
  (interactive) 
  (let* ((buffer-name (format "*HTML:%s*" (buffer-name)))
	 (buffer (get-buffer (buffer-name)))
	 (buffer-html (or (get-buffer buffer-name)
			  (generate-new-buffer buffer-name))))
    (save-excursion
      (set-buffer buffer-html)
      (insert-buffer buffer)
      (save-excursion
	(goto-char (point-min)) 
	(replace-string* "&" "&amp;"))
      (save-excursion
	(goto-char (point-min)) 
	(replace-string* "<" "&lt;"))
      (save-excursion
	(goto-char (point-min)) 
	(replace-string* ">" "&gt;"))
      (let ((current-color nil))
	(insert "<body text=\"white\" bgcolor=\"black\"><pre>\n")
	(while (not (eobp))
	  (let ((color (let ((face (get-text-property (point) 'face)))
			 (if face
			     (face-foreground (if (consp face)
						  (first face)
						face))
			   nil))))
	    (if (not (eq color current-color))
		(progn
		  (when current-color
		    (insert "</font>"))
		  (when color
		    (insert (format "<font color=\"%s\">" color)))
		  (setq current-color color)))
	    (forward-char 1)))
	(when current-color
	  (insert "</font>")))
      (insert "</pre></body>\n"))
    (display-buffer buffer-html)))
------------------------------------8<------------------------------------

One small problem is that some colors (named by name) displayed by the
Web browser do not exactly match those displayed by Emacs (ligther or
darker).
-- 
 Georges Ko                     gko@gko.net                      2005-08-18
 If you are not in my white list, add [m2gko] in the subject of your mail.


Updated at: 2020-12-10 08:50 UTC