[cl-typesetting-devel] paragraph macro

Cyrus Harmon ch-lisp at bobobeach.com
Sat May 5 16:15:05 UTC 2007


First of all, thanks for cl-typesetting and cl-pdf. After spending  
the last year or so wrangling my smarkup package into generating  
suitable latex for thinks like the UC thesis package and beamer, I've  
decided to bite the bullet and try to add a cl-typesetting backend to  
smarkup, noticing, of course, that Francois-Rene Rideau has done  
something similar for exscribe.

What strikes me from playing with cl-typesetting is that the  
interface, or at least the parts of it I'm looking at, look more like  
a DSL than a library. What I mean by this that the macros for things  
like paragraph allow for the following:

(paragraph (:h-align :center :font "Helvetica" :font-size 16 :color  
'(0.0 0 0.6))
            "Table of content")

Which is, of course, nice shorthand and saves the user from typing:

(paragraph '(:h-align :center :font "Helvetica" :font-size 16 :color  
'(0.0 0 0.6))
            "Table of content")

which would allow (but certainly other reasons might prevent this  
from being the case) for paragraph to be a function instead of a macro.

But the problem comes in when I try to do something like:

(defparameter *default-paragraph-font*
   '(:font "Times-Roman" :font-size 12))

(defmethod %render-elt ((tag (eql :p)) contents)
   (tt::paragraph *default-paragraph-font*
     (tt:put-string (collect-elements contents))))

Now perhaps I'm just showing my lack of mad macro-skillz. I suppose I  
could rewrite my code as macros that generate the appropriate forms  
but then I start to get lost in nested backquotes. It would seem  
easier to have something like this:

(defmacro paragraph2 (style &body body)
   (with-gensyms (top-margin bottom-margin first-line-indent
                             new-style restore-style first-indent)
     `(let* ((,top-margin (getf ,style :top-margin 0))
             (,bottom-margin (getf ,style :bottom-margin 0))
             (,first-line-indent (getf ,style :first-line-indent 0))
             (,new-style (apply #'make-instance 'text-style ,style))
             (,restore-style (make-restore-style ,new-style))
             (,first-indent ,first-line-indent))
        (add-box ,new-style)
        (use-style ,new-style)
        (add-box (make-instance 'v-spacing :dy ,top-margin))
        (unless (zerop ,first-indent)
          (add-box (make-instance 'h-spacing :dx ,first-indent)))
        ,@(mapcar 'insert-stuff body)
        (unless (eq (first (boxes-tail *content*)) :eol)
          (add-box :eol))
        (add-box (make-instance 'v-spacing :dy ,bottom-margin))
        (add-box ,restore-style)
        (use-style ,restore-style))))

but then perhaps I'm missing the point of why style is not evaluated  
in the paragraph macro.

Anyway, I see the argument for the shorthand syntax, but it would be  
nice if there were an equivalent form that evaluated its arguments so  
that one can build functions that call the typesetting functionality.

It's quite possible that I'm 1) completely missing the point here or  
that there are some simple macro tricks that render this point moot,  
but if so the point or the tricks are not obvious to me.

Thanks again for cl-typesetting and cl-pdf.

Cyrus




More information about the cl-typesetting-devel mailing list