[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cjl@WHEATIES.AI.MIT.EDU: Problem with format]



Date: Thu, 4 Aug 88 12:49 EDT
From: Chris Lindblad <cjl@WHEATIES.AI.MIT.EDU>
Subject: Problem with format
To: psz@ZERMATT.LCS.MIT.EDU
cc: rz@ZERMATT.LCS.MIT.EDU
In-Reply-To: <19880804060204.7.PSZ@PASTEUR.LCS.MIT.EDU>

    Date: Thu, 4 Aug 88 02:02 EDT
    From: Peter Szolovits <psz@zermatt.lcs.mit.edu>

I really don't know anything about format.  Try asking either
slug@warbucks.ai.sri.com or customer-reports.

	    I'm confused about a Lisp format issue.  I have the following
    code that is supposed to print a description of a bibliographic entry in
    a "beautiful" way.  In particular, the format statement that contains
    the format string ",~%~8T~A=\"~A~{~<~%~16T~1,60:; and ~A~>~}\"" is
    supposed to print a list of names separated by the word "and" but making
    sure that no more that 60 chars go on a line.
	    What is funny is that when I "print" this to the pseudo-file
    made by with-output-to-string or to the file "t" (i.e., the terminal),
    it seems to work just fine, as shown in the example below.  When I print
    it to a real file, though format seems to ignore the 60-char line width
    spec.  Is this really a bug in format, or am I doing something
    brain-dead?  Thanks.  --Pete

    ----------------------------------------------------------------

    (defun generate-print-entry (e show-all &optional file)
      ;; Note that if file is real, we simply output to it and ignore the returned value.
      ;; Otherwise (NIL), we generate the entry as a string and return it.
      (if file
	  (generate-print-entry-inner e show-all file)
	  (with-output-to-string (pseudo-file)
	    (generate-print-entry-inner e show-all pseudo-file))))

    (defun generate-print-entry-inner (e show-all file
					 &aux (fields (bib-fields e))
					 (type (bib-type e)))
      (generate-comments e file)
      (format file "@~A{~A" (pretty type) (bib-id e))
      (loop for field in (if (not show-all) fields (generate-all-fields e))
	    for val = (cdr field)
	    do (cond ((typep (cdr field) 'string)
		      (format file (if (find #\" val :test #'char=)	;[mpw] member won't work
				       ",~%~8T~A={~A}"
				       ",~%~8T~A=\"~A\"")
			      (pretty (car field))
			      (generate-string val)))
		     ((member (car field) '(author editor))
		      (let* ((need-brace nil)
			     (ns (loop for n in val
				       for v = (name-pname n) 
				       when (find #\" v :test #'char=)
					 do (setq need-brace t)
				       collect v)))
			(format file
				(if need-brace
				    ",~%~8T~A={~A~{~<~%~16T~1,60:; and ~A~>~}}"
				    ",~%~8T~A=\"~A~{~<~%~16T~1,60:; and ~A~>~}\"")
				(pretty (car field))
				(car ns)
				(cdr ns))))
		     (t (format file ",~%~8T~A=~A"
				(pretty (car field))
				val))))
      (princ "}" file))

    (generate-print-entry xx t)
    "@Article{Eckman-McNutt87,
	    Author=\"Eckman, M. H. and McNutt, R. A.
		     and Parkinson, D. R. and Pauker, S. G.\",
	    Title=\"The timing of radical cystectomy after recent myocardial
		    infarction: Waiting for Godot\",
	    Journal=MDM,
	    Year=1987,
	    Volume=7,
	    Number=\"\",
	    Pages=\"52-66\",
	    Month=\"\",
	    Note=\"\"}"

    ----------------------------------------------------------------

    (with-open-file (f "z:>psz>foo.tex" :direction :output) (generate-print-entry xx t f))

    :Show File (file [default Z:>medg>bibcite>rbib.lisp.newest]) Z:>psz>foo.tex.newest

     ***  Z:>psz>foo.tex.newest  ***
     ***  (Z:>PSZ>foo.tex.1)  ***


    @Article{Eckman-McNutt87,
       Author="Eckman, M. H. and McNutt, R. A. and Parkinson, D. R. and Pauker, S. G.",
       Title="The timing of radical cystectomy after recent myocardial
		    infarction: Waiting for Godot",
       Journal=MDM,
       Year=1987,
       Volume=7,
       Number="",
       Pages="52-66",
       Month="",
       Note=""}