From damir at x-si.org Thu Mar 9 14:51:15 2006 From: damir at x-si.org (Damir Horvat) Date: Thu, 9 Mar 2006 15:51:15 +0100 Subject: [cl-typesetting-devel] different text aligning in the same "line" Message-ID: <20060309145115.GA4074@semp.x-si.org> Hi! I'd like to align text on left and right side with text being in the same "line". I'd like to do this: ----------------------------------------------- |Left aligned text Right aligned text| | | | Centered text | | | I think this should be done within one paragraf? Regards, Damir From divanov at aha.ru Thu Mar 9 19:20:31 2006 From: divanov at aha.ru (Dmitriy Ivanov) Date: Thu, 9 Mar 2006 22:20:31 +0300 Subject: [cl-typesetting-devel] different text aligning in the same "line" References: <20060309145115.GA4074@semp.x-si.org> Message-ID: <000b01c643ae$951cf030$8100a8c0@digo> Hello Damir, | Hi! | | I'd like to align text on left and right side with text being in the | same "line". I'd like to do this: | | ----------------------------------------------- |> Left aligned text Right aligned text| | >> |> Centered text | | >> | | I think this should be done within one paragraf? Have you tried something like this (untested): (tt:paragraph (:h-align :fill) "left text" :hfill "right text" :eol :hfill "centered text" :hfill) ? -- Sincerely, Dmitriy Ivanov lisp.ystok.ru From marc.battyani at fractalconcept.com Thu Mar 9 20:12:50 2006 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Thu, 9 Mar 2006 21:12:50 +0100 Subject: [cl-typesetting-devel] different text aligning in the same "line" References: <20060309145115.GA4074@semp.x-si.org> Message-ID: <012201c643b5$d7809e70$1402a8c0@marcx2> "Damir Horvat" wrote: > > I'd like to align text on left and right side with text being in the > same "line". I'd like to do this: > > ----------------------------------------------- > |Left aligned text Right aligned text| > | | > | Centered text | > | | > > I think this should be done within one paragraf? The way suggested by Dmitriy is the good one. You can also have a look at the visit card examples for more things like this: http://www.fractalconcept.com:8000/public/open-source/cl-typesetting/examples/business-card.lisp Marc From damir at x-si.org Sat Mar 11 04:41:01 2006 From: damir at x-si.org (Damir Horvat) Date: Sat, 11 Mar 2006 05:41:01 +0100 Subject: [cl-typesetting-devel] document encoding Message-ID: <20060311044101.GA14751@semp.x-si.org> Hi! Is there a way to change default encoding? I'd like to have iso-8859-2 (or utf-8). specials.lisp has something about it, but only for clisp, if I understand this. I'm using cmucl. Thanks, Damir From pj at heslin.eclipse.co.uk Mon Mar 27 09:43:21 2006 From: pj at heslin.eclipse.co.uk (Peter Heslin) Date: Mon, 27 Mar 2006 10:43:21 +0100 Subject: [cl-typesetting-devel] Should justification change inter-letter spacing? Message-ID: <20060327094321.GA29553@heslin.eclipse.co.uk> A bit of experimentation shows that when setting a pathological paragraph with ( :h-align :justified ), cl-typesetting achieves the justification not only by stretching the inter-word space, as it should do, but also by slightly stretching the inter-letter spacing, which seems like very bad practice to me. TeX never does this -- instead, it warns you and sticks text into the margin, which makes it obvious that there is a problem. Here is an example. (defun test () (with-document () (draw-pages (compile-text () (paragraph (:h-align :justified) "aaaaaaaaaaaaa" "aaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa aaaaaaaaa aaaaaaaaaaa aaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaa aaaaaaaaaaaa aaaaaaaaaaaaaaaaaaa aaaaaaaaaaaa aaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaa ")) :margins '(72 72 72 72)) (when pdf:*page* (finalize-page pdf:*page*)) (pdf:write-document #P"/tmp/test.pdf"))) Best wishes, Peter From marc.battyani at fractalconcept.com Mon Mar 27 14:11:37 2006 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Mon, 27 Mar 2006 16:11:37 +0200 Subject: [cl-typesetting-devel] Should justification change inter-letterspacing? References: <20060327094321.GA29553@heslin.eclipse.co.uk> Message-ID: <05b801c651a8$5c8fee90$1402a8c0@marcx2> "Peter Heslin" wrote: >A bit of experimentation shows that when setting a pathological > paragraph with ( :h-align :justified ), cl-typesetting achieves the > justification not only by stretching the inter-word space, as it > should do, but also by slightly stretching the inter-letter spacing, > which seems like very bad practice to me. TeX never does this -- > instead, it warns you and sticks text into the margin, which makes it > obvious that there is a problem. > > Here is an example. > > (defun test () > (with-document () > (draw-pages (compile-text () > (paragraph (:h-align :justified) > "aaaaaaaaaaaaa" > "aaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa aaaaaaaaa > aaaaaaaaaaa aaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaa > aaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaa > aaaaaaaaaaaaaaaaaa aaaaaaaaaaaa aaaaaaaaaaaaaaaaaaa aaaaaaaaaaaa > aaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaa > ")) > :margins '(72 72 72 72)) > (when pdf:*page* (finalize-page pdf:*page*)) > (pdf:write-document #P"/tmp/test.pdf"))) Yes, but it's not a bug, it's a feature ;-) To change it, have a look at #'make-inter-char-glue and set the expansibility to 0 for instance. Maybe I should put this in a special variable. The fact that TeX sticks text into the margin in case of problems is one of the reasons I wrote cl-typesetting for (along with the fact that you can't make complex tables in a reasonably usable way). I mostly use cl-typesetting to generate pdf documents in applications and nobody wants to have text in the margin ;-) Marc From pj at heslin.eclipse.co.uk Mon Mar 27 20:57:30 2006 From: pj at heslin.eclipse.co.uk (Peter Heslin) Date: Mon, 27 Mar 2006 21:57:30 +0100 Subject: [cl-typesetting-devel] Should justification change inter-letterspacing? In-Reply-To: <05b801c651a8$5c8fee90$1402a8c0@marcx2> References: <20060327094321.GA29553@heslin.eclipse.co.uk> <05b801c651a8$5c8fee90$1402a8c0@marcx2> Message-ID: <20060327205730.GA10837@heslin.eclipse.co.uk> On Mon, Mar 27, 2006 at 04:11:37PM +0200, Marc Battyani wrote: > Yes, but it's not a bug, it's a feature ;-) > To change it, have a look at #'make-inter-char-glue and set the > expansibility to 0 for instance. > Maybe I should put this in a special variable. Thanks for the tip -- this does what I want: (defun make-inter-char-glue () (make-instance 'hglue :dx 0 :max-expansion 0 :max-compression 0 :expansibility 0 :compressibility 0)) Is it possible to have cl-typesetting signal a warning when the inter-word spacing stretches more than a certain amount? > The fact that TeX sticks text into the margin in case of problems is one of > the reasons I wrote cl-typesetting for (along with the fact that you can't > make complex tables in a reasonably usable way). I mostly use > cl-typesetting to generate pdf documents in applications and nobody wants > to have text in the margin ;-) Well, it's not that text in the margin is a good outcome, it's that for many people, letter-spacing text is not an acceptable way to solve the problem. Many good books on typographical design, such as Bringhurst's _The Elements of Typographical Style_, recommend strongly against ever, ever letter-spacing lower-case text. Goudy once famously compared the practice to stealing sheep. On a different but related matter, I have another problem for you. Here is another sample document: (defun test () (with-document () (draw-pages (compile-text () (paragraph (:h-align :justified) (enumerate () (item () "foo") (item () "bar" (enumerate () (item () "a") (item () "b"))) (item () "baz")))) :margins '(72 72 72 72) ) (when pdf:*page* (finalize-page pdf:*page*)) (pdf:write-document #P"/tmp/test.pdf"))) When you compile this, note that the word "bar" is in the wrong place. If you change the alignment of the paragraph to :left, then the problem goes away. I think that the reason the word "bar" is in the wrong place is that inter-word space is being added between the number "2." and the word "bar" in an effort to justify the text. But it shouldn't stretch the inter-word space in that position -- it should act as if the word "bar" is at the start of a line. Is there any way to fix this? Thanks for all your help, Peter -- Peter Heslin (http://www.dur.ac.uk/p.j.heslin) From pj at heslin.eclipse.co.uk Tue Mar 28 21:41:31 2006 From: pj at heslin.eclipse.co.uk (Peter Heslin) Date: Tue, 28 Mar 2006 22:41:31 +0100 Subject: [cl-typesetting-devel] Bug in hyphenate-string? Message-ID: <20060328214131.GA19433@heslin.eclipse.co.uk> When you give a string to the function hyphenate-string, it will fail to find any hyphenation-points in the last word of the string, unless the string has trailing whitespace. (tt::hyphenate-string "hyphenate") => NIL (tt::hyphenate-string "hyphenate ") => (5) (tt::hyphenate-string "hyphenate hyphenate") => (5) (tt::hyphenate-string "hyphenate hyphenate ") => (5 15) -- Peter Heslin (http://www.dur.ac.uk/p.j.heslin) From pj at heslin.eclipse.co.uk Wed Mar 29 22:27:47 2006 From: pj at heslin.eclipse.co.uk (Peter Heslin) Date: Wed, 29 Mar 2006 23:27:47 +0100 Subject: [cl-typesetting-devel] Serious hyphenation bug Message-ID: <20060329222746.GA23321@heslin.eclipse.co.uk> While playing with cl-typesetting, I have had the vague feeling that it did not find as many hyphenation points as TeX, which seemed strange, since it uses the same patterns. I tested this, using this function: (defun show-hyphens (string) (concatenate 'string (loop for char across string for i upfrom 0 for points = (tt::hyphenate-string string) appending (if (member i points) (list #\- char) (list char))))) Here is the output from TeX' showhyphens command for a piece of text: but tor-ture with-out end still urges, and a fiery del-uge, fed with ever-burning sul-phur un-con-sumed. such place eter-nal jus-tice had pre-pared for those re-bel-lious? here their prison or-dained in ut-ter dark-ness, and their por-tion set as far re-moved from god and light of heaven, as from the cen-tre thrice to the ut-most pole. oh, how un-like the place from whence they fell. Here is cl-typesetting, using the show-hyphens function defined above: but tor-ture without end still urges, and a fiery deluge, fed with ever-burning sulphur un-con-sumed. such place eter-nal justice had pre-pared for those re-bellious? here their pri-son or-dained in utter dark-ness, and their por-tion set as far re-moved from god and light of heaven, as from the centre thrice to the ut-most pole. oh, how unlike the place from whence they fell. Note that cl-typesetting finds only about half of the hyphenation points that TeX does, despite using similar patterns. I think I have discovered the cause of this bug. In the file hyphenation-fp.lisp, the function hyphen-make-trie has this comment: ;; Build a trie out of a sorted list ;; of pairs (word, hyph-points) So it is important that the input list is sorted. This is done by this line in the function read-hyphen-file: (setq patterns (sort patterns #'hyphen-cmp-char-lists) Here is that sort predicate: (defun hyphen-cmp-char-lists (l1 l2) (let (result done) (loop for c1 = (pop l1) for c2 = (pop l2) while (and (characterp c1) (characterp c2) (not done)) do (if (char< c1 c2) (setq result t done t) (if (char> c1 c2) (setq done t) )) finally (if done result nil)))) It seems to me that this function will fail to sort the lists of chars correctly when one of the lists represents an initial substring of the other string, which is not uncommon. The result of this bug is that the contents of the patterns variable are only partially sorted, and so hyphen-make-trie generates a trie that excludes many of the patterns. In fact, if you want to check it, you can see that, at least for some initial letters, the trie generated only includes patterns that correspond to a line in the hyphenation file that begins with a dot or a number. Here is my revised version of the sort predicate: (defun nix::hyphen-cmp-char-lists (l1 l2) (loop for c1 = (pop l1) for c2 = (pop l2) do (cond ((and (characterp c1) (not (characterp c2))) (return nil)) ((and (not (characterp c1)) (characterp c2)) (return t)) ((and (not (characterp c1)) (not (characterp c2))) (return)) ((char< c1 c2) (return t)) ((char> c1 c2) (return nil))))) When I use this function and re-load the american hyphen file, and run my show-hyphens function again, I get a correct result, like so: but tor-ture with-out end still urges, and a fiery del-uge, fed with ever-burn-ing sul-phur un-con-sumed. such place eter-nal jus-tice had pre-pared for those re-bel-lious? here their prison or-dained in ut-ter dark-ness, and their por-tion set as far re-moved from god and light of heaven, as from the cen-tre thrice to the ut-most pole. oh, how un-like the place from whence they fell. Now cl-typesetting has found all of the same hyphenation points that TeX did. So it looks from a very superficial test that this is the correct fix, but I should emphasize that I do not understand most of the code in hyphenation-fp.lisp, so I'm not entirely sure that my sort function is correct. It would nice if someone who understands the code fully could check this out. -- Peter Heslin (http://www.dur.ac.uk/p.j.heslin) From marc.battyani at fractalconcept.com Thu Mar 30 19:53:12 2006 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Thu, 30 Mar 2006 21:53:12 +0200 Subject: [cl-typesetting-devel] Serious hyphenation bug References: <20060329222746.GA23321@heslin.eclipse.co.uk> Message-ID: <074201c65433$93f80c90$1402a8c0@marcx2> "Peter Heslin" wrote: > While playing with cl-typesetting, I have had the vague feeling that > it did not find as many hyphenation points as TeX, which seemed > strange, since it uses the same patterns. I tested this, using this > function: > > (defun show-hyphens (string) > (concatenate 'string > (loop > for char across string > for i upfrom 0 > for points = (tt::hyphenate-string string) > appending (if (member i points) > (list #\- char) > (list char))))) > > Here is the output from TeX' showhyphens command for a piece of text: > > but tor-ture with-out end still urges, and a fiery del-uge, fed with > ever-burning sul-phur un-con-sumed. such place eter-nal jus-tice had > pre-pared for those re-bel-lious? here their prison or-dained in > ut-ter dark-ness, and their por-tion set as far re-moved from god and > light of heaven, as from the cen-tre thrice to the ut-most pole. oh, > how un-like the place from whence they fell. > > Here is cl-typesetting, using the show-hyphens function defined above: > > but tor-ture without end still urges, and a fiery deluge, fed with > ever-burning sulphur un-con-sumed. such place eter-nal justice had > pre-pared for those re-bellious? here their pri-son or-dained in > utter dark-ness, and their por-tion set as far re-moved from god and > light of heaven, as from the centre thrice to the ut-most pole. oh, > how unlike the place from whence they fell. > > Note that cl-typesetting finds only about half of the hyphenation > points that TeX does, despite using similar patterns. > > I think I have discovered the cause of this bug. > > In the file hyphenation-fp.lisp, the function hyphen-make-trie has > this comment: > > ;; Build a trie out of a sorted list > ;; of pairs (word, hyph-points) > > So it is important that the input list is sorted. This is done by this > line in the function read-hyphen-file: > > (setq patterns (sort patterns #'hyphen-cmp-char-lists) > > Here is that sort predicate: > > (defun hyphen-cmp-char-lists (l1 l2) > (let (result done) > (loop for c1 = (pop l1) > for c2 = (pop l2) > while (and (characterp c1) (characterp c2) (not done)) > do > (if (char< c1 c2) > (setq result t done t) > (if (char> c1 c2) > (setq done t) > )) > finally (if done result nil)))) > > It seems to me that this function will fail to sort the lists of chars > correctly when one of the lists represents an initial substring of the > other string, which is not uncommon. > > The result of this bug is that the contents of the patterns variable > are only partially sorted, and so hyphen-make-trie generates a trie > that excludes many of the patterns. In fact, if you want to check it, > you can see that, at least for some initial letters, the trie > generated only includes patterns that correspond to a line in the > hyphenation file that begins with a dot or a number. > > Here is my revised version of the sort predicate: > > (defun nix::hyphen-cmp-char-lists (l1 l2) > (loop > for c1 = (pop l1) > for c2 = (pop l2) > do (cond > ((and (characterp c1) (not (characterp c2))) > (return nil)) > ((and (not (characterp c1)) (characterp c2)) > (return t)) > ((and (not (characterp c1)) (not (characterp c2))) > (return)) > ((char< c1 c2) > (return t)) > ((char> c1 c2) > (return nil))))) > > When I use this function and re-load the american hyphen file, and run > my show-hyphens function again, I get a correct result, like so: > > but tor-ture with-out end still urges, and a fiery del-uge, fed with > ever-burn-ing sul-phur un-con-sumed. such place eter-nal jus-tice had > pre-pared for those re-bel-lious? here their prison or-dained in > ut-ter dark-ness, and their por-tion set as far re-moved from god and > light of heaven, as from the cen-tre thrice to the ut-most pole. oh, > how un-like the place from whence they fell. > > Now cl-typesetting has found all of the same hyphenation points that > TeX did. > > So it looks from a very superficial test that this is the correct fix, > but I should emphasize that I do not understand most of the code in > hyphenation-fp.lisp, so I'm not entirely sure that my sort function is > correct. It would nice if someone who understands the code fully > could check this out. Thanks for this well commented bug fix. :) I haven't closely looked at this code too and I'm not a TeX expert so I will forward this to Fabrice Popineau who wrote it. (and who is a TeX expert) BTW even though my interest in cl-typesetting/cl-pdf has not faded, don't be surprised if I don't reply very fast. I have an incredible amount of work to do these days with several deadlines at the end of April. Nevertheless I plan to make a new release with all the patches/modifications I've got before May. Marc From pj at heslin.eclipse.co.uk Thu Mar 30 21:52:26 2006 From: pj at heslin.eclipse.co.uk (Peter Heslin) Date: Thu, 30 Mar 2006 22:52:26 +0100 Subject: [cl-typesetting-devel] Serious hyphenation bug In-Reply-To: <074201c65433$93f80c90$1402a8c0@marcx2> References: <20060329222746.GA23321@heslin.eclipse.co.uk> <074201c65433$93f80c90$1402a8c0@marcx2> Message-ID: <20060330215226.GA24184@heslin.eclipse.co.uk> On Thu, Mar 30, 2006 at 09:53:12PM +0200, Marc Battyani wrote: > BTW even though my interest in cl-typesetting/cl-pdf has not faded, don't > be surprised if I don't reply very fast. I have an incredible amount of > work to do these days with several deadlines at the end of April. > Nevertheless I plan to make a new release with all the > patches/modifications I've got before May. No problem. For the May release, here's a fix for the bug I reported earlier, where hyphenations are not found for words without whitespace after them: (in-package :tt) (defparameter *hyphen-trie* nix::*american-hyphen-trie*) (defun hyphenate-string (string) (let ((min-word-size (+ nix::*left-hyphen-minimum* nix::*right-hyphen-minimum*))) (when (>= (length string) min-word-size) (loop for prev-word-end = 0 then word-end for word-start = (position-if #'alpha-char-p string :start prev-word-end) for word-end = (when word-start (or (position-if-not #'alpha-char-p string :start word-start) (length string))) while word-start when (>= (- word-end word-start) min-word-size) nconc (mapcar #'(lambda (n) (+ word-start n)) (nix::hyphen-find-hyphen-points *hyphen-trie* (subseq string word-start word-end))))))) In addition to fixing the bug, I have added the *hyphen-trie* parameter, so that american hyphenation is not hard-coded into the function, and you can switch languages on the fly. In the meantime, if anyone knows how to work around the problem with full justification and nested enumerate environments that I mentioned in an e-mail of a few days ago, I'd be grateful to hear of it. -- Peter Heslin (http://www.dur.ac.uk/p.j.heslin) From pj at heslin.eclipse.co.uk Fri Mar 31 19:46:37 2006 From: pj at heslin.eclipse.co.uk (Peter Heslin) Date: Fri, 31 Mar 2006 20:46:37 +0100 Subject: [cl-typesetting-devel] Should justification change inter-letterspacing? In-Reply-To: <20060327205730.GA10837@heslin.eclipse.co.uk> References: <20060327094321.GA29553@heslin.eclipse.co.uk> <05b801c651a8$5c8fee90$1402a8c0@marcx2> <20060327205730.GA10837@heslin.eclipse.co.uk> Message-ID: <20060331194637.GA32494@heslin.eclipse.co.uk> It turns out that I was somewhat mistaken when I wrote this: > Well, it's not that text in the margin is a good outcome, it's that > for many people, letter-spacing text is not an acceptable way to solve > the problem. Many good books on typographical design, such as > Bringhurst's _The Elements of Typographical Style_, recommend strongly > against ever, ever letter-spacing lower-case text. Goudy once > famously compared the practice to stealing sheep. I have just read in comp.text.tex: Bringhurst in ``The Elements of Typographic Style'' (Version 3.0) mentions that the software he used for setting Elements (InDesign, no version number given): ``...has been permitted to vary the intercharacter spacing by \pm 3% and to adjust the width of individual glyphs by \pm 2%.'' (pg 192) I have the second edition of Bringhurst's book, not the third; the second edition says nothing about this. So I guess the moral is that a very, very small amount of letter-spacing is allowable if it makes a better paragraph -- small enough that it is not noticeable. But I still think that the cl-typesetting default allows a bit too much. In the course of this discussion it transpired that pdftex has these capabilities also. -- Peter Heslin (http://www.dur.ac.uk/p.j.heslin) From marc.battyani at fractalconcept.com Fri Mar 31 21:04:36 2006 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Fri, 31 Mar 2006 23:04:36 +0200 Subject: [cl-typesetting-devel] Should justification changeinter-letterspacing? References: <20060327094321.GA29553@heslin.eclipse.co.uk><05b801c651a8$5c8fee90$1402a8c0@marcx2><20060327205730.GA10837@heslin.eclipse.co.uk> <20060331194637.GA32494@heslin.eclipse.co.uk> Message-ID: <0aa001c65506$b80a8620$1402a8c0@marcx2> "Peter Heslin" wrote: > It turns out that I was somewhat mistaken when I wrote this: > >> Well, it's not that text in the margin is a good outcome, it's that >> for many people, letter-spacing text is not an acceptable way to solve >> the problem. Many good books on typographical design, such as >> Bringhurst's _The Elements of Typographical Style_, recommend strongly >> against ever, ever letter-spacing lower-case text. Goudy once >> famously compared the practice to stealing sheep. > > I have just read in comp.text.tex: > > Bringhurst in ``The Elements of Typographic Style'' (Version 3.0) > mentions that the software he used for setting Elements (InDesign, > no version number given): > > ``...has been permitted to vary the intercharacter spacing by \pm > 3% and to adjust the width of individual glyphs by \pm 2%.'' (pg > 192) > > I have the second edition of Bringhurst's book, not the third; the > second edition says nothing about this. So I guess the moral is that > a very, very small amount of letter-spacing is allowable if it makes a > better paragraph -- small enough that it is not noticeable. But I > still think that the cl-typesetting default allows a bit too much. > > In the course of this discussion it transpired that pdftex has these > capabilities also. Well I think it's a good thing for some pathological cases like very narrow text columns for instance. One thing I also wanted to do is to apply a small amount of compression to avoid moving a word (or parts of a word) on the next line if only a small amount of x space is missing. Of course this should be done in correlation with the lines around that one. Marc