-
Notifications
You must be signed in to change notification settings - Fork 6
/
bibyfi-IEEETran.satyh
193 lines (173 loc) · 6.07 KB
/
bibyfi-IEEETran.satyh
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
@import: bibyfi
type bibyfi-ieee-tran-cfg = (|
name-shrink: bool;
et-al: bool;
journal-abbr : (string * string) list;
|)
module BiByFiIEEETran : sig
val theme : bibyfi-ieee-tran-cfg -> context -> int -> bibyfi-item -> block-boxes
end = struct
let font-ratio-latin = 1.
let book-title-font = (`Junicode-it`, font-ratio-latin, 0.)
let mk-index ctx index =
let s = `[` ^ arabic index ^ `] `# in
read-inline ctx (embed-string s)
let-inline ctx \book-title it =
let ctx = ctx
|> set-font Latin book-title-font
in
read-inline ctx it
let mk-pages (s, e) =
let it-s = embed-string s in
let it-e = embed-string e in
{pp. #it-s;–#it-e;}
let mk-year-month year month =
let it-year = embed-string year in
match month with
| None -> {#it-year;}
| Some(month) -> (
let it-month = embed-string month in
{#it-month;\ #it-year;}
)
let-inline ctx \space l =
inline-skip l
let endmarkers-en =
List.map string-explode [`.`; `?`; `!`]
let-rec head-match xs ys = match (xs, ys) with
| ([], []) -> true
| (x :: xs, y :: ys) -> x == y && head-match xs ys
| _ -> true
let tail-match xs ys =
head-match (List.reverse xs) (List.reverse ys)
let mk-title title sep =
let it-title = embed-string title in
let title = string-explode title in
let title-has-endmark =
endmarkers-en
|> List.map (fun pattern -> tail-match pattern title)
|> List.fold-left ( || ) false
in
if title-has-endmark
then {“#it-title;”}
else {“#it-title;#sep;”}
let mk-publisher addr publisher = match addr with
| Some(addr) -> (
let it-addr = embed-string addr in
let it-publisher = embed-string publisher in
{#it-addr;:\ #it-publisher;})
| None -> (
let it-publisher = embed-string publisher in
{#it-publisher;})
let mk-title-elem title =
Some(|
not-tail = fun sep -> mk-title title sep ;
tail = fun periodo -> mk-title title periodo;
|)
let mk-authors et-al shrinked authors =
let authors =
if shrinked
then authors |> List.map BiByFi.shrink-name
else authors
in
let authors =
if et-al
then (match authors with
| [] -> []
| [n] -> [n]
| [n1;n2] -> [n1;n2]
| n1 :: _ -> [n1 ^ #` et al.`])
else
authors
in
BiByFi.join-authors {\ and\ } {,\ } {and\ } (List.map embed-string authors)
let mk-journal abbrs journal =
let-rec search abbrs = match abbrs with
| [] -> journal
| (full, abbr) :: last -> if string-same full journal
then abbr
else search last
in
let it-journal = embed-string (search abbrs) in
{\book-title{#it-journal;}}
let mk-article cfg r =
let it-note = Option.map embed-string r#note in
let it-key = Option.map embed-string r#key in
BiByFi.join-elements {,} {.} {\ } [
BiByFi.lift-elem (mk-authors cfg#et-al cfg#name-shrink r#author);
mk-title-elem r#title;
BiByFi.lift-elem (mk-journal cfg#journal-abbr r#journal);
BiByFi.lift-elem (mk-pages r#pages);
BiByFi.map-elem (Option.map
(fun v -> (
let it-v = embed-string v
in {vol. #it-v;})) r#volume);
BiByFi.map-elem (Option.map
(fun n -> (
let it-n = embed-string n in
{no. #it-n;})) r#number);
BiByFi.lift-elem (mk-year-month r#year r#month);
BiByFi.map-elem it-note;
BiByFi.map-elem it-key;
]
let mk-inproceedings cfg r =
let it-authors = mk-authors cfg#et-al cfg#name-shrink r#author in
let it-booktitle = mk-journal cfg#journal-abbr r#booktitle in
let it-editors = r#editor
|> Option.map (fun editors -> mk-authors cfg#et-al cfg#name-shrink editors)
|> Option.map (fun it-editor -> {#it-editor;,\ Eds.}) in
let it-note = Option.map embed-string r#note in
let it-key = Option.map embed-string r#key in
let it-organization = Option.map embed-string r#organization in
let it-publisher = Option.map (mk-publisher r#address) r#publisher in
BiByFi.join-elements {,} {.} {\ } [
BiByFi.lift-elem it-authors;
mk-title-elem r#title;
BiByFi.lift-elem {in\ #it-booktitle;};
BiByFi.map-elem it-editors;
BiByFi.custom-sep {.} {.} (BiByFi.map-elem it-organization);
BiByFi.map-elem it-publisher;
BiByFi.lift-elem (mk-year-month r#year r#month);
BiByFi.map-elem (Option.map mk-pages r#pages);
BiByFi.map-elem it-note;
BiByFi.map-elem it-key;
]
let mk-book cfg r =
let it-authors = mk-authors cfg#et-al cfg#name-shrink r#author in
let it-edition = r#edition
|> Option.map embed-string
|> Option.map (fun it-edition -> {#it-edition;\ ed.})
in
let it-series = r#series
|> Option.map embed-string
|> Option.map (fun it-series -> {ser.\ #it-series;})
in
let it-publisher = mk-publisher r#address r#publisher in
let it-year-month = mk-year-month r#year r#month in
let it-volume = r#volume
|> Option.map embed-string
|> Option.map (fun it-volume -> {vol.\ #it-volume;})
in
let it-note = Option.map embed-string r#note in
BiByFi.join-elements {,} {.} {\ } [
BiByFi.lift-elem it-authors;
mk-title-elem r#title;
BiByFi.map-elem it-edition;
BiByFi.custom-sep {.} {.} (BiByFi.map-elem it-series);
BiByFi.lift-elem it-publisher;
BiByFi.lift-elem it-year-month;
BiByFi.map-elem it-volume;
BiByFi.map-elem it-note;
]
let theme cfg ctx index bib-item =
match bib-item with
| Article(r) ->
BiByFi.make-entry ctx (mk-index ctx index) (read-inline ctx (mk-article cfg r))
| InProceedings(r) ->
BiByFi.make-entry ctx (mk-index ctx index) (read-inline ctx (mk-inproceedings cfg r))
| Book(r) ->
BiByFi.make-entry ctx (mk-index ctx index) (read-inline ctx (mk-book cfg r))
| WildCard(it) ->
BiByFi.make-entry ctx (mk-index ctx index) (read-inline ctx it)
| _ ->
BiByFi.make-entry ctx (mk-index ctx index) (read-inline ctx {yet implemented})
end