mbutterick / pollen-users

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

One source file → multiple outputs of same type? #122

Closed jaybonthius closed 2 years ago

jaybonthius commented 2 years ago

I know I can have multiple poly-targets, like html, txt, ltx pdf, but can I have multiple poly-targets of the same type?

My use case: I'm writing lecture notes and I would like to add a second html poly-target for some sort of javascript browser slideshow.

I'm hoping for the following: a single source file lecture.poly.pm is rendered as two separate html files: lecture-doc.html, lecture-slides.html, each processed through their own separate branches of tag functions.

Is that doable?

In the same vein, I see a similar use case with pdf: exam.poly.pm renders into exam.pdf and exam-solutions.pdf, where in the latter, solutions are made visible.

bdeket commented 2 years ago

As a work-around I once did this with htm and html as different targets. But in general, I think you can make the targets doc.html, slides.html, default.pdf and solutions.pdf. (resulting in exam.default.pdf etc.)

otherjoel commented 2 years ago

The reverse use case (many source files → one output file) came up recently, and the answer is much the same (see the second point in this comment). Thanks to the fact that Pollen sources are also Racket modules, whatever you need can be done by just writing your own code rather than depending solely on Pollen’s built-in command line tools.

The simplest hack I would try, given your “each processed through their own separate branches of tag functions” requirement, is to have html_l and html_s output targets, and then rename all the resulting files to .html with a shell script. But eventually you may find that you want to create your own Racket program that just builds everything you need in one go.

jaybonthius commented 2 years ago

Those sound like great solutions until I work up the courage to implement a Racket-based mechanism. Thank you, Joel and @bdeket!

mbutterick commented 2 years ago

I handle situations like this by using the POLLEN environment variable.

mbutterick commented 2 years ago

This is how typographyforlawyers.com and practicaltypography.com are generated from a single set of source files. Most of the text is shared. But then I have tag functions that show or hide certain text based on the status of an environment variable.* Then everything else is the same (templates, etc.)

* Strictly speaking, POLLEN is automatically supported, but you can use any environment variable and then add it to envvar-watchlist so it cooperates with the caching system.

jaybonthius commented 2 years ago

Ah, that's a cool solution. I was wondering how you managed both sites from one set of sources. Thanks for the tip!