-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpollen.rkt
72 lines (62 loc) · 2.45 KB
/
pollen.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#lang pollen/mode racket
(require pollen/setup pollen/decode txexpr)
(require "utils.rkt")
(module setup racket/base
(provide (all-defined-out))
;; add custom list of files to watch (i.e. submodules)
(require syntax/modresolve)
(define cache-watchlist (map resolve-module-path '("classes.rkt"
"styles.rkt"
"utils.rkt")))
(define poly-targets '(html ltx pdf)))
(provide (all-defined-out))
(define/contract (tex-C++ str)
(string? . -> . string?)
(case (current-poly-target)
[(html) str]
[(pdf ltx)
(string-replace str "C++"
(string-append "C\\kern-0.2ex "
"\\raise .1ex \\hbox{+\\kern-0.4ex +}"))]))
(define (root . items)
(decode (txexpr-ext 'body '() items)
#:txexpr-elements-proc (lambda (x)
(case (current-poly-target)
[(html) (decode-paragraphs x)]
[else x]))
#:string-proc (lambda (x)
(case (current-poly-target)
[(html) ((compose1 smart-quotes smart-dashes) x)]
[else (tex-C++ x)]))))
(define (->LaTeX x)
(cond
[(txexpr? x)
(let* ((tag (get-tag x))
;; ignore attributes
(elements (get-elements x))
;; need to filter, e.g. with (txt txt "spam")
(content (apply string-append
(filter string? (map ->LaTeX elements)))))
(case tag
[(body root txt) (~a content)] ;; ignore "service" tags
[else (format "\\~a{~a}" tag content)]))]
[else x]))
(define (make-latex-source doc)
◊string-append{
\documentclass[a4paper, 12pt]{letter}
\usepackage[top=3cm,
bottom=3cm,
left=3cm,
right=3cm]{geometry}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{charter}
\usepackage[hidelinks]{hyperref}
\usepackage{enumitem}
\usepackage{graphicx}
\pagenumbering{gobble}
\begin{document}
◊(->LaTeX doc)
\end{document}
})