mbutterick / pollen-users

please use https://forums.matthewbutterick.com/c/typesetting/ instead
https://forums.matthewbutterick.com/c/typesetting/
52 stars 0 forks source link

How should I make a pagetree with poly sources? #23

Closed oldmankit closed 4 years ago

oldmankit commented 4 years ago

Do pagetrees only work with one output source?

Let's say I'm using poly sources (1.poly.pm and 2.poly.pm) to generate both html and txt output. If my pagetree contains:

then Pollen functions which rely on the pagetree (for example, previous here) work only when generating html output. The txt output seems to be unaware that there is any pagetree. So previous, next, parent and children links don't produce anything.

I tried making a pagetree with:

But that didn't fix it. None of the pagetree-depenent functions worked for either html or for txt.

mbutterick commented 4 years ago

So you want two pagetrees that are the same, except the file extension for each pagenode is txt rather than html?

oldmankit commented 4 years ago

So you want two pagetrees that are the same, except the file extension for each pagenode is txt rather than html?

Yes, that's exactly right.

mbutterick commented 4 years ago

I suppose I’d write the pagetree using poly extensions and then pass the tree through a tag function that converts tnem. Here’s one approach:

#lang pollen/ptree
◊(require racket/match txexpr pollen/setup racket/string)

◊(define (change-ext . xs)
  (cons '@
        (let loop ([x xs])
          (match x
            [(? list? xs) (map loop xs)]
            [(? string? str) #:when (string-suffix? str ".poly")
                             (string-replace str ".poly" (format ".~a" (current-poly-target)))]
            [(? symbol? sym) (string->symbol (loop (symbol->string sym)))]
            [_ x]))))

◊change-ext{
hello.poly
◊world.poly{
            this.poly
            that.poly
            }
}

(Taking the shortcut here of using string-manipulation functions on path-like things, which is not the most enviable practice but it shortens the example)

oldmankit commented 4 years ago

Thank you so much, @mbutterick That works perfectly.

I had a little flash of insight when I saw what you'd done: truly everything is programmable, even the .ptree which I was thinking of as a kind of black box.