Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang racket/base
- (require racket/date
- pollen/decode
- txexpr
- pollen/setup)
- (provide (all-defined-out))
- (module setup racket/base
- (provide (all-defined-out))
- (define poly-targets '(html txt ltx pdf)))
- (define rsquo
- (case (current-poly-target)
- [(ltx pdf) "\\textquoteright "]
- [else "’"]))
- ; BEGIN TAGS
- (define (p . elements)
- (case (current-poly-target)
- [(ltx pdf) (apply string-append `("" ,@elements "\\par "))]
- [else `(p ,@elements)]))
- (define (blockquote . elements)
- (case (current-poly-target)
- [(ltx pdf) (apply string-append `( "\\begin{quote}" ,@(filter string? elements) "\\end{quote}"))]
- [else `(blockquote ,@elements)]))
- (define (ol . elements)
- (case (current-poly-target)
- [(ltx pdf) (apply string-append `( "\\begin{enumerate}" ,@(filter string? elements) "\\end{enumerate}"))]
- [else `(ol ,@elements)]))
- (define (ul . elements)
- (case (current-poly-target)
- [(ltx pdf) (apply string-append `( "\\begin{itemize}" ,@(filter string? elements) "\\end{itemize}"))]
- [else `(ul ,@elements)]))
- (define (li . elements)
- (case (current-poly-target)
- [(ltx pdf) (apply string-append `( "\\item " ,@elements))]
- [else `(li ,@elements)]))
- (define (strong . elements)
- (case (current-poly-target)
- [(ltx pdf) (apply string-append `( "\\textbf{" ,@(filter string? elements) "}"))]
- [else `(strong ,@elements)]))
- (define (em . elements)
- (case (current-poly-target)
- [(ltx pdf) (apply string-append `( "\\emph{" ,@(filter string? elements) "}"))]
- [else `(em ,@elements)]))
- (define (h1 . elements)
- (case (current-poly-target)
- [(ltx pdf) (apply string-append `( "\\title{" ,@(filter string? elements) "}"))]
- [else `(h1 ,@elements)]))
- (define (h2 . elements)
- (case (current-poly-target)
- [(ltx pdf) (apply string-append `( "\\section{" ,@(filter string? elements) "}"))]
- [else `(h2 ,@elements)]))
- (define (h3 . elements)
- (case (current-poly-target)
- [(ltx pdf) (apply string-append `( "\\subsection{" ,@(filter string? elements) "}"))]
- [else `(h3 ,@elements)]))
- (define (h4 . elements)
- (case (current-poly-target)
- [(ltx pdf) (apply string-append `( "\\subsubsection{" ,@(filter string? elements) "}"))]
- [else `(h4 ,@elements)]))
- (define (h5 . elements)
- (case (current-poly-target)
- [(ltx pdf) (apply string-append `( "\\paragraph{" ,@(filter string? elements) "}"))]
- [else `(h5 ,@elements)]))
- (define (h6 . elements)
- (case (current-poly-target)
- [(ltx pdf) (apply string-append `( "\\subparagraph{" ,@(filter string? elements) "}"))]
- [else `(h6 ,@elements)]))
- (define (a attrs . elements)
- (case (current-poly-target)
- [(ltx pdf) (apply string-append `( "\\href{" ,(assoc 'href attrs) "}{" ,@(filter string? elements) "}"))]
- [else `(a ,attrs ,@elements)]))
- (define (img attrs)
- (case (current-poly-target)
- [(ltx pdf) (apply string-append `( "\\includegraphics{" ,(assoc 'src attrs) "}"))]
- [else `(img ,attrs)]))
- (define (tabular-format rows)
- (define num-cols
- (apply max (map (lambda (row) (length (cdr row))) rows)))
- (string-append "{" (make-string num-cols #\l) "}"))
- (define (interleave lst1 lst2)
- (if (or (null? lst1) (null? lst2))
- '()
- (cons (car lst1) (cons (car lst2) (interleave (cdr lst1) (cdr lst2))))))
- (define (repeat x)
- (cons x (repeat x)))
- (define (table . rows)
- (case (current-poly-target)
- [(ltx pdf) (apply string-append `( "\\begin{tabular}{" ,(tabular-format rows) "}" ,@rows "\\end{tabular}"))]
- [else `(table ,@rows)]))
- (define (tr . cells)
- (case (current-poly-target)
- [(ltx pdf) (apply string-append `( ,(apply string-append (interleave cells (repeat "&"))) " \\\\"))]
- [else `(tr ,@cells)]))
- (define (td . elements)
- (case (current-poly-target)
- [(ltx pdf) (apply string-append `( ,@elements))]
- [else `(td ,@elements)]))
- (define (th . elements)
- (case (current-poly-target)
- [(ltx pdf) (apply string-append `( "\\textbf{" ,@(filter string? elements) "}"))]
- [else `(th ,@elements)]))
- (define (code . elements)
- (case (current-poly-target)
- [(ltx pdf) (apply string-append `( "\\texttt{" ,@(filter string? elements) "}"))]
- [else `(code ,@elements)]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement