forked from fletcher/MultiMarkdown-4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lyxbeamer.c
265 lines (243 loc) · 8.66 KB
/
lyxbeamer.c
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*
lyxbeamer.c -- Beamer add-on to LyX writer
(c) 2013 Charles R. Cowan
(c) 2013 Fletcher T. Penney (http://fletcherpenney.net/).
Derrived from MultiMarkdown by Fletcher T. Penney - added code to support the LYY format directly
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License or the MIT
license. See LICENSE for details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "lyxbeamer.h"
#include "lyx.h"
bool need_fragile; // if the frame needs to be fragile
/* print_beamer_node_tree -- convert node tree to LyX */
void print_lyxbeamer_node_tree(GString *out, node *list, scratch_pad *scratch, bool no_newline) {
while (list != NULL) {
print_lyxbeamer_node(out, list, scratch, no_newline);
list = list->next;
}
}
/* print_beamer_node -- convert given node to LyX and append */
void print_lyxbeamer_node(GString *out, node *n, scratch_pad *scratch, bool no_newline) {
int lev;
int i;
char *temp;
char *prefixed_label;
node *temp_node;
int old_type;
/* If we are forcing a complete document, and METADATA isn't the first thing,
we need to close <head> */
if ((scratch->extensions & EXT_COMPLETE)
&& !(scratch->extensions & EXT_HEAD_CLOSED) &&
!((n->key == FOOTER) || (n->key == METADATA))) {
scratch->extensions = scratch->extensions | EXT_HEAD_CLOSED;
}
switch (n->key) {
case FOOTER:
if (scratch->lyx_in_frame){ // have an open frame
g_string_append(out,"\n\\end_deeper");
// g_string_append(out,"\n\\end_layout");
g_string_append(out, "\n\\begin_layout Separator");
g_string_append(out, "\n\\end_layout");
}
scratch->lyx_in_frame = FALSE;
print_lyxbeamer_endnotes(out, scratch);
break;
case BULLETLIST:
case ORDEREDLIST:
scratch -> lyx_beamerbullet = TRUE;
case DEFLIST:
old_type = scratch->lyx_para_type;
scratch->lyx_para_type = n->key;
scratch->lyx_level++;
if (scratch->lyx_level > 1){
g_string_append(out,"\n\\begin_deeper\n");
}
print_lyxbeamer_node_tree(out, n->children, scratch, FALSE);
scratch->lyx_level--;
if (scratch->lyx_level > 0){
g_string_append(out,"\n\\end_deeper\n");
}
scratch->lyx_para_type = old_type;
if (scratch->lyx_definition_open){
g_string_append(out,"\n\\end_deeper\n");
scratch->lyx_definition_open = FALSE;
}
break;
case LISTITEM:
temp_node = n-> children; // should be a list node
if (temp_node->key != LIST){
fprintf(stderr,"\nUnanticipated List Item Format");
exit(EXIT_FAILURE);
} else {
temp_node = temp_node-> children; // process the list
i = 0;
while (temp_node != NULL){
i++;
if (i == 2){
g_string_append(out,"\n\\begin_deeper\n");
old_type = scratch->lyx_para_type;
scratch->lyx_para_type = PARA; // and make it a paragraph, not a list item
}
print_lyx_node(out, temp_node, scratch, no_newline);
temp_node = temp_node->next;
}
if (i>1){
scratch->lyx_para_type = old_type; // reset the paragraph type
g_string_append(out,"\n\\end_deeper\n");
}
}
break;
case HEADINGSECTION:
if (scratch->lyx_in_frame){ // have an open frame
g_string_append(out,"\n\\end_deeper");
// g_string_append(out,"\n\\end_layout");
g_string_append(out, "\n\\begin_layout Separator");
g_string_append(out, "\n\\end_layout");
}
scratch->lyx_in_frame = FALSE;
need_fragile = FALSE;
if (tree_contains_key(n->children,VERBATIM)) {
need_fragile = TRUE;
}
print_lyxbeamer_node_tree(out,n->children,scratch , FALSE);
break;
case H1: case H2: case H3: case H4: case H5: case H6:
lev = n->key - H1 + scratch->baseheaderlevel; /* assumes H1 ... H6 are in order */
switch (lev) {
case 1:
g_string_append(out, "\n\\begin_layout Part\n");
break;
case 2:
g_string_append(out, "\n\\begin_layout Section\n");
break;
case 3:
if (need_fragile) {
g_string_append(out, "\n\\begin_layout FragileFrame");
} else {
g_string_append(out, "\n\\begin_layout Frame");
};
g_string_append(out,"\n\\begin_inset Argument 4");
g_string_append(out,"\nstatus open\n");
g_string_append(out,"\n\\begin_layout Plain Layout\n");
scratch->lyx_in_frame = TRUE;
break;
case 4:
g_string_append(out,"\n\\begin_layout Standard");
g_string_append(out, "\n\\begin_inset Flex ArticleMode");
g_string_append(out, "\nstatus open\n\n");
g_string_append(out,"\n\\begin_layout Plain Layout\n");
break;
default:
g_string_append(out,"\n\\begin_layout Standard");
g_string_append(out, "\n\\emph on\n");
break;
}
/* Don't allow footnotes */
scratch->no_lyx_footnote = TRUE;
if (n->children->key == AUTOLABEL) {
/* use label for header since one was specified (MMD)*/
temp = label_from_string(n->children->str);
prefixed_label = prefix_label(heading_name[lev-1]->str,temp,FALSE);
print_lyx_node_tree(out, n->children->next, scratch , FALSE);
g_string_append(out,"\n\\begin_inset CommandInset label\n");
g_string_append(out,"LatexCommand label\n");
g_string_append_printf(out, "name \"%s\"",prefixed_label);
g_string_append(out,"\n\\end_inset\n");
free(prefixed_label);
free(temp);
} else {
/* generate a label by default for MMD */
temp = label_from_node_tree(n->children);
prefixed_label = prefix_label(heading_name[lev-1]->str,temp,FALSE);
print_lyx_node_tree(out, n->children, scratch, FALSE);
g_string_append(out,"\n\\begin_inset CommandInset label\n");
g_string_append(out,"LatexCommand label\n");
g_string_append_printf(out, "name \"%s\"",prefixed_label);
g_string_append(out,"\n\\end_inset\n");
free(prefixed_label);
free(temp);
}
scratch->no_lyx_footnote = FALSE;
switch(lev){
case 1: case 2:
g_string_append(out,"\n\\end_layout\n");
break;
case 3:
g_string_append(out,"\n\\end_layout\n");
g_string_append(out,"\n\\end_inset\n");
g_string_append(out,"\n\\end_layout\n");
g_string_append(out,"\n\\begin_deeper\n");
break;
case 4:
g_string_append(out,"\n\\end_layout");
g_string_append(out,"\n\\end_inset");
g_string_append(out,"\n\\end_layout");
break;
default:
g_string_append(out, "\n\\emph default\n");
g_string_append(out,"\n\\end_layout");
break;
}
break;
default:
/* most things are not changed for beamer output */
print_lyx_node(out, n, scratch,no_newline);
}
}
/* print_beamer_endnotes */
void print_lyxbeamer_endnotes(GString *out, scratch_pad *scratch) {
node *temp_node;
scratch->used_notes = reverse_list(scratch->used_notes);
node *note = scratch->used_notes;
// Handle Glossary
temp_node = note;
while (temp_node != NULL){
if(temp_node->key == GLOSSARYSOURCE){
g_string_append(out, "\n\\begin_layout BeginFrame\nGlossary\n");
g_string_append(out,"\n\\begin_layout Standard");
g_string_append(out,"\n\\begin_inset CommandInset nomencl_print");
g_string_append(out,"\nLatexCommand printnomenclature");
g_string_append(out,"\nset_width \"auto\"\n");
g_string_append(out,"\n\\end_inset\n");
g_string_append(out,"\n\\end_layout\n");
g_string_append(out, "\n\\end_layout\n");
g_string_append(out, "\n\\begin_layout EndFrame");
g_string_append(out, "\n\\end_layout");
break;
}
temp_node = temp_node->next;
}
if (note == NULL)
return;
note = scratch->used_notes;
if (tree_contains_key(note,CITATIONSOURCE)){
g_string_append(out, "\n\\begin_layout BeginFrame\nReferences\n");
g_string_append(out, "\n\\end_layout");
}
while ( note != NULL) {
if (note->key == KEY_COUNTER) {
note = note->next;
continue;
}
if (note->key == CITATIONSOURCE) {
g_string_append(out, "\n\\begin_layout Bibliography\n");
g_string_append(out,"\\begin_inset CommandInset bibitem\n");
g_string_append(out,"LatexCommand bibitem\n");
g_string_append_printf(out, "key \"%s\"\n", note->str);
g_string_append_printf(out, "label \"%s\"\n", note->str);
g_string_append(out,"\n\\end_inset\n");
print_lyx_node(out, note, scratch, FALSE);
g_string_append(out,"\n\\end_layout\n");
} else {
/* footnotes handled elsewhere */
}
note = note->next;
}
g_string_append(out, "\n\\begin_layout EndFrame"); // close last frame
g_string_append(out, "\n\\end_layout");
}