Function to include one document within another? #214

Closed
opened 4 years ago by anthrolisp · 5 comments
anthrolisp commented 4 years ago (Migrated from github.com)

In Scribble, it's possible to include one document within another, through @include-section["file.scrbl"]. Is it possible to do something similar with Pollen, especially with poly.pm documents?
Many thanks in advance!

In Scribble, it's possible to include one document within another, through @include-section["file.scrbl"]. Is it possible to do something similar with Pollen, especially with poly.pm documents? Many thanks in advance!
otherjoel commented 4 years ago (Migrated from github.com)

Check out this comment in the Pollen Users repo

Check out [this comment](https://github.com/mbutterick/pollen-users/issues/18#issuecomment-549584276) in the Pollen Users repo
anthrolisp commented 4 years ago (Migrated from github.com)

How difficult would it be to create an include function to work with poly.pm files with support for multiple (e.g. html, txt and pdf) outputs? Many thanks in advance!

Starting from the Pollen fourth tutorial on making a multple-output project based on a poly output type with additional support for txt, latex and pdf in pollen.rkt file, and following from the suggestion linked here, I added the following to the pollen.rkt

#lang racket/base

(require pollen/core pollen/decode)

(provide root include)

(define (root . elems)
  `(body ,@(decode-paragraphs elems #:force? #t)))

(define (include file)
  `(@ ,@(cdr (get-doc file))))

Adding a line to the cv.poly.pm file:

#lang pollen
 
◊heading{Brennan Huff}
 
Today is ◊(get-date). I ◊emph{really} want this job.

◊include["new.poly.pm"]

Contents of "new.poly.pm":


#lang pollen

I ◊emph{really} need this job.

Thank you.

Working from within the pollen server, the html output works fine.

However, I get an error for txt output:

decode-paragraphs: contract violation
  expected: txexpr-elements?
  given: '("I " ("**" "really" "**") " need this job." "\n" "\n" "Thank you." "\n" "\n")
  in: the 1st argument of
      (->*
       (txexpr-elements?)
       ((or/c
         txexpr-tag?
         (-> (listof xexpr?) txexpr?))
        #:force?
        boolean?
        #:linebreak-proc
        (-> txexpr-elements? txexpr-elements?))

and pdf output:

string-append: contract violation
  expected: string?
  given: '(p "{\\huge Brennan Huff}")
  argument position: 1st
  other arguments...:
   '(p "Today is " "Wednesday, January 1st, 2020" ". I " "{\\bf really}" " want this job.")
   '(p "I " "{\\bf really}" " need this job.")
   '(p "Thank you.")

Thanks again!

How difficult would it be to create an include function to work with poly.pm files with support for multiple (e.g. html, txt and pdf) outputs? Many thanks in advance! Starting from the [Pollen fourth tutorial](https://docs.racket-lang.org/pollen/fourth-tutorial.html) on making a multple-output project based on a poly output type with additional support for txt, latex and pdf in pollen.rkt file, and following from the suggestion linked [here](https://github.com/mbutterick/pollen-users/issues/18), I added the following to the pollen.rkt ``` #lang racket/base (require pollen/core pollen/decode) (provide root include) (define (root . elems) `(body ,@(decode-paragraphs elems #:force? #t))) (define (include file) `(@ ,@(cdr (get-doc file)))) ``` Adding a line to the cv.poly.pm file: ``` #lang pollen ◊heading{Brennan Huff} Today is ◊(get-date). I ◊emph{really} want this job. ◊include["new.poly.pm"] ``` Contents of "new.poly.pm": ``` #lang pollen I ◊emph{really} need this job. Thank you. ``` Working from within the pollen server, the html output works fine. However, I get an error for txt output: ``` decode-paragraphs: contract violation expected: txexpr-elements? given: '("I " ("**" "really" "**") " need this job." "\n" "\n" "Thank you." "\n" "\n") in: the 1st argument of (->* (txexpr-elements?) ((or/c txexpr-tag? (-> (listof xexpr?) txexpr?)) #:force? boolean? #:linebreak-proc (-> txexpr-elements? txexpr-elements?)) ``` and pdf output: ``` string-append: contract violation expected: string? given: '(p "{\\huge Brennan Huff}") argument position: 1st other arguments...: '(p "Today is " "Wednesday, January 1st, 2020" ". I " "{\\bf really}" " want this job.") '(p "I " "{\\bf really}" " need this job.") '(p "Thank you.") ``` Thanks again!
kisaragi-hiu commented 4 years ago (Migrated from github.com)

I can see that your root needs to dispatch on (current-poly-target), as described by this section.

I can see that your `root` needs to dispatch on [`(current-poly-target)`](https://docs.racket-lang.org/pollen/Setup.html#%28def._%28%28lib._pollen%2Fsetup..rkt%29._current-poly-target%29%29), as described by [this section](https://docs.racket-lang.org/pollen/fourth-tutorial.html#(part._.Branching_tag_functions)).
mbutterick commented 4 years ago (Migrated from github.com)

I’m not yet persuaded that there’s a bug or gap here. For instance, with txt, the issue is that you’re inserting decode-paragraphs without updating the underlying tag functions. That’s what the error message indicates: something like '("**" "really" "**") is not a valid txexpr-element?. You can fix it by putting a @ tag on the front, turning it into a splicing txexpr. And so on.

I’m not yet persuaded that there’s a bug or gap here. For instance, with `txt`, the issue is that you’re inserting `decode-paragraphs` without updating the underlying tag functions. That’s what the error message indicates: something like `'("**" "really" "**")` is not a valid `txexpr-element?`. You can fix it by putting a `@` tag on the front, turning it into a splicing txexpr. And so on.
mbutterick commented 4 years ago (Migrated from github.com)

Closing as abandoned. Please reopen if needed.

Closing as abandoned. Please reopen if needed.
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: mbutterick/pollen#214
Loading…
There is no content yet.