forked from fletcher/MultiMarkdown-4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
beamer.c
179 lines (160 loc) · 5.25 KB
/
beamer.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
/*
beamer.c -- Beamer add-on to LaTeX writer
(c) 2013 Fletcher T. Penney (http://fletcherpenney.net/).
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 "beamer.h"
/* print_beamer_node_tree -- convert node tree to LaTeX */
void print_beamer_node_tree(GString *out, node *list, scratch_pad *scratch) {
while (list != NULL) {
print_beamer_node(out, list, scratch);
list = list->next;
}
}
/* print_beamer_node -- convert given node to LaTeX and append */
void print_beamer_node(GString *out, node *n, scratch_pad *scratch) {
int lev;
char *temp;
/* 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))) {
pad(out, 2, scratch);
scratch->extensions = scratch->extensions | EXT_HEAD_CLOSED;
}
switch (n->key) {
case FOOTER:
print_beamer_endnotes(out, scratch);
g_string_append_printf(out, "\\mode<all>\n");
if (scratch->latex_footer != NULL) {
pad(out, 2, scratch);
g_string_append_printf(out,"\\input{%s}\n", scratch->latex_footer);
}
if (scratch->extensions & EXT_COMPLETE) {
g_string_append_printf(out, "\n\\end{document}");
}
g_string_append_printf(out, "\\mode*\n");
break;
case LISTITEM:
pad(out, 1, scratch);
g_string_append_printf(out, "\\item<+-> ");
scratch->padded = 2;
print_latex_node_tree(out, n->children, scratch);
g_string_append_printf(out, "\n");
break;
case HEADINGSECTION:
if (n->children->key -H1 + scratch->baseheaderlevel == 3) {
pad(out, 2, scratch);
g_string_append_printf(out, "\\begin{frame}");
/* TODO: Fix this */
if (tree_contains_key(n->children,VERBATIM)) {
g_string_append_printf(out, "[fragile]");
}
scratch->padded = 0;
print_beamer_node_tree(out, n->children, scratch);
g_string_append_printf(out, "\n\n\\end{frame}\n\n");
scratch->padded = 2;
} else if (n->children->key -H1 + scratch->baseheaderlevel == 4) {
pad(out, 1, scratch);
g_string_append_printf(out, "\\mode<article>{\n");
scratch->padded = 0;
print_beamer_node_tree(out, n->children->next, scratch);
g_string_append_printf(out, "\n\n}\n\n");
scratch->padded = 2;
} else {
print_beamer_node_tree(out, n->children, scratch);
}
break;
case H1: case H2: case H3: case H4: case H5: case H6:
pad(out, 2, scratch);
lev = n->key - H1 + scratch->baseheaderlevel; /* assumes H1 ... H6 are in order */
switch (lev) {
case 1:
g_string_append_printf(out, "\\part{");
break;
case 2:
g_string_append_printf(out, "\\section{");
break;
case 3:
g_string_append_printf(out, "\\frametitle{");
break;
default:
g_string_append_printf(out, "\\emph{");
break;
}
/* generate a label for each header (MMD);
don't allow footnotes since invalid here */
scratch->no_latex_footnote = TRUE;
if (n->children->key == AUTOLABEL) {
temp = label_from_string(n->children->str);
print_latex_node_tree(out, n->children->next, scratch);
g_string_append_printf(out, "}\n\\label{%s}", temp);
free(temp);
} else {
print_latex_node_tree(out, n->children, scratch);
temp = label_from_node_tree(n->children);
g_string_append_printf(out, "}\n\\label{%s}", temp);
free(temp);
}
scratch->no_latex_footnote = FALSE;
scratch->padded = 0;
break;
default:
/* most things are not changed for memoir output */
print_latex_node(out, n, scratch);
}
}
/* print_beamer_endnotes */
void print_beamer_endnotes(GString *out, scratch_pad *scratch) {
scratch->used_notes = reverse_list(scratch->used_notes);
node *note = scratch->used_notes;
#ifdef DEBUG_ON
fprintf(stderr, "start endnotes\n");
#endif
if ((note == NULL) || ((note->key == KEY_COUNTER) && (note->next == NULL)))
return;
while (note != NULL) {
if (note->key == CITATIONSOURCE)
break;
note = note->next;
}
if (note == NULL)
return;
note = scratch->used_notes;
/* TODO: need CITATIONSOURCE to print bibliography */
#ifdef DEBUG_ON
fprintf(stderr, "there are endnotes to print\n");
#endif
pad(out, 2, scratch);
g_string_append_printf(out, "\\part{Bibliography}\n\\begin{frame}[allowframebreaks]\n\\frametitle{Bibliography}\n\\def\\newblock{}\n\\begin{thebibliography}{0}\n");
while ( note != NULL) {
if (note->key == KEY_COUNTER) {
note = note->next;
continue;
}
pad(out, 1, scratch);
if (note->key == CITATIONSOURCE) {
g_string_append_printf(out, "\\bibitem{%s}\n", note->str);
scratch->padded = 2;
print_latex_node(out, note, scratch);
pad(out, 1, scratch);
scratch->padded = 1;
} else {
/* footnotes handled elsewhere */
}
note = note->next;
}
pad(out,2, scratch);
g_string_append_printf(out, "\\end{thebibliography}\n\\end{frame}\n\n");
scratch->padded = 0;
#ifdef DEBUG_ON
fprintf(stderr, "finish endnotes\n");
#endif
}