rmultimarkdown 4.7.1.1 → 6.2.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +2 -2
  3. data/README.md +7 -9
  4. data/Rakefile +33 -18
  5. data/ext/Makefile +261 -0
  6. data/ext/extconf.rb +23 -3
  7. data/ext/mmd/aho-corasick.c +596 -0
  8. data/ext/mmd/aho-corasick.h +120 -0
  9. data/ext/mmd/beamer.c +344 -0
  10. data/ext/mmd/beamer.h +72 -0
  11. data/ext/mmd/char.c +156 -0
  12. data/ext/mmd/char.h +111 -0
  13. data/ext/mmd/char_lookup.c +212 -0
  14. data/ext/mmd/critic_markup.c +330 -0
  15. data/ext/mmd/critic_markup.h +94 -0
  16. data/ext/mmd/d_string.c +402 -0
  17. data/ext/mmd/epub.c +563 -0
  18. data/ext/mmd/epub.h +69 -0
  19. data/ext/mmd/fodt.c +2288 -0
  20. data/ext/mmd/fodt.h +81 -0
  21. data/ext/mmd/html.c +2460 -0
  22. data/ext/mmd/html.h +81 -0
  23. data/ext/mmd/i18n.h +170 -0
  24. data/ext/mmd/include/d_string.h +182 -0
  25. data/ext/mmd/include/libMultiMarkdown.h +548 -0
  26. data/ext/mmd/include/token.h +233 -0
  27. data/ext/mmd/latex.c +2435 -0
  28. data/ext/mmd/latex.h +83 -0
  29. data/ext/mmd/lexer.c +3001 -0
  30. data/ext/mmd/lexer.h +75 -0
  31. data/ext/mmd/memoir.c +138 -0
  32. data/ext/mmd/memoir.h +67 -0
  33. data/ext/mmd/miniz.c +7557 -0
  34. data/ext/mmd/miniz.h +1328 -0
  35. data/ext/mmd/mmd.c +2798 -0
  36. data/ext/mmd/mmd.h +120 -0
  37. data/ext/mmd/object_pool.c +141 -0
  38. data/ext/mmd/object_pool.h +101 -0
  39. data/ext/mmd/opendocument-content.c +2071 -0
  40. data/ext/mmd/opendocument-content.h +135 -0
  41. data/ext/mmd/opendocument.c +981 -0
  42. data/ext/mmd/opendocument.h +118 -0
  43. data/ext/mmd/parser.c +1760 -0
  44. data/ext/mmd/parser.h +39 -0
  45. data/{MultiMarkdown-4 → ext/mmd}/rng.c +90 -49
  46. data/ext/mmd/scanners.c +77512 -0
  47. data/ext/mmd/scanners.h +101 -0
  48. data/ext/mmd/stack.c +142 -0
  49. data/ext/mmd/stack.h +113 -0
  50. data/ext/mmd/textbundle.c +455 -0
  51. data/ext/mmd/textbundle.h +115 -0
  52. data/ext/mmd/token.c +773 -0
  53. data/ext/mmd/token_pairs.c +263 -0
  54. data/ext/mmd/token_pairs.h +123 -0
  55. data/ext/mmd/transclude.c +549 -0
  56. data/ext/mmd/transclude.h +87 -0
  57. data/ext/mmd/uthash.h +1074 -0
  58. data/ext/mmd/uuid.c +154 -0
  59. data/ext/mmd/uuid.h +77 -0
  60. data/ext/mmd/version.h +111 -0
  61. data/ext/mmd/writer.c +2652 -0
  62. data/ext/mmd/writer.h +260 -0
  63. data/ext/mmd/zip.c +210 -0
  64. data/ext/mmd/zip.h +120 -0
  65. data/ext/{multi_markdown.c → ruby_multi_markdown.c} +87 -18
  66. data/lib/multi_markdown.bundle +0 -0
  67. data/lib/multi_markdown.rb +5 -8
  68. data/lib/multi_markdown/version.rb +1 -1
  69. data/rmultimarkdown.gemspec +2 -2
  70. data/test/{extensions_test.rb.rb → extensions_test.rb} +10 -54
  71. data/test/multi_markdown_test.rb +13 -0
  72. metadata +67 -47
  73. data/MultiMarkdown-4/GLibFacade.c +0 -310
  74. data/MultiMarkdown-4/GLibFacade.h +0 -100
  75. data/MultiMarkdown-4/beamer.c +0 -182
  76. data/MultiMarkdown-4/beamer.h +0 -11
  77. data/MultiMarkdown-4/critic.c +0 -111
  78. data/MultiMarkdown-4/critic.h +0 -15
  79. data/MultiMarkdown-4/glib.h +0 -11
  80. data/MultiMarkdown-4/html.c +0 -1117
  81. data/MultiMarkdown-4/html.h +0 -14
  82. data/MultiMarkdown-4/latex.c +0 -1217
  83. data/MultiMarkdown-4/latex.h +0 -16
  84. data/MultiMarkdown-4/libMultiMarkdown.h +0 -177
  85. data/MultiMarkdown-4/lyx.c +0 -2265
  86. data/MultiMarkdown-4/lyx.h +0 -37
  87. data/MultiMarkdown-4/lyxbeamer.c +0 -265
  88. data/MultiMarkdown-4/lyxbeamer.h +0 -11
  89. data/MultiMarkdown-4/memoir.c +0 -80
  90. data/MultiMarkdown-4/memoir.h +0 -10
  91. data/MultiMarkdown-4/multimarkdown.c +0 -518
  92. data/MultiMarkdown-4/odf.c +0 -1222
  93. data/MultiMarkdown-4/odf.h +0 -18
  94. data/MultiMarkdown-4/opml.c +0 -189
  95. data/MultiMarkdown-4/opml.h +0 -15
  96. data/MultiMarkdown-4/parse_utilities.c +0 -884
  97. data/MultiMarkdown-4/parser.c +0 -16656
  98. data/MultiMarkdown-4/parser.h +0 -188
  99. data/MultiMarkdown-4/rtf.c +0 -665
  100. data/MultiMarkdown-4/rtf.h +0 -17
  101. data/MultiMarkdown-4/strtok.c +0 -56
  102. data/MultiMarkdown-4/strtok.h +0 -9
  103. data/MultiMarkdown-4/text.c +0 -53
  104. data/MultiMarkdown-4/text.h +0 -11
  105. data/MultiMarkdown-4/toc.c +0 -142
  106. data/MultiMarkdown-4/toc.h +0 -15
  107. data/MultiMarkdown-4/transclude.c +0 -307
  108. data/MultiMarkdown-4/transclude.h +0 -28
  109. data/MultiMarkdown-4/writer.c +0 -731
  110. data/MultiMarkdown-4/writer.h +0 -38
@@ -1,14 +0,0 @@
1
- #ifndef HTML_PARSER_H
2
- #define HTML_PARSER_H
3
-
4
- #include "parser.h"
5
- #include "writer.h"
6
-
7
-
8
- void print_html_node_tree(GString *out, node *list, scratch_pad *scratch);
9
- void print_html_node(GString *out, node *n, scratch_pad *scratch);
10
- void print_html_localized_typography(GString *out, int character, scratch_pad *scratch);
11
- void print_html_string(GString *out, char *str, scratch_pad *scratch);
12
- void print_html_endnotes(GString *out, scratch_pad *scratch);
13
-
14
- #endif
@@ -1,1217 +0,0 @@
1
- /*
2
-
3
- latex.c -- LaTeX writer
4
-
5
- (c) 2013-2015 Fletcher T. Penney (http://fletcherpenney.net/).
6
-
7
- Derived from peg-multimarkdown, which was forked from peg-markdown,
8
- which is (c) 2008 John MacFarlane (jgm at berkeley dot edu), and
9
- licensed under GNU GPL or MIT.
10
-
11
- This program is free software; you can redistribute it and/or modify
12
- it under the terms of the GNU General Public License or the MIT
13
- license. See LICENSE for details.
14
-
15
- This program is distributed in the hope that it will be useful,
16
- but WITHOUT ANY WARRANTY; without even the implied warranty of
17
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
- GNU General Public License for more details.
19
-
20
- */
21
-
22
- #include "latex.h"
23
-
24
- bool is_latex_complete_doc(node *meta);
25
-
26
- /* find_latex_mode -- check for metadata to switch to beamer/memoir */
27
- int find_latex_mode(int format, node *n) {
28
- node *latex_mode;
29
- char *key;
30
- char *label;
31
-
32
- if (format != LATEX_FORMAT)
33
- return format;
34
-
35
- if (tree_contains_key(n, METAKEY)) {
36
- latex_mode = metadata_for_key("latexmode",n);
37
- if (latex_mode != NULL) {
38
- key = metavalue_for_key("latexmode",n);
39
- label = label_from_string(key);
40
- if (strcmp(label, "beamer") == 0) {
41
- format = BEAMER_FORMAT;
42
- } else if (strcmp(label, "memoir") == 0) {
43
- format = MEMOIR_FORMAT;
44
- }
45
- free(label);
46
- free(key);
47
- }
48
- }
49
-
50
- return format;
51
- }
52
-
53
-
54
- /* print_latex_node_tree -- convert node tree to LaTeX */
55
- void print_latex_node_tree(GString *out, node *list, scratch_pad *scratch) {
56
- while (list != NULL) {
57
- print_latex_node(out, list, scratch);
58
- list = list->next;
59
- }
60
- }
61
-
62
- /* print_latex_node -- convert given node to LaTeX and append */
63
- void print_latex_node(GString *out, node *n, scratch_pad *scratch) {
64
- node *temp_node;
65
- char *temp;
66
- int lev;
67
- char *width = NULL;
68
- char *height = NULL;
69
- GString *temp_str;
70
- GString *raw_str;
71
- int i;
72
- double temp_float;
73
-
74
- if (n == NULL)
75
- return;
76
-
77
- /* debugging statement */
78
- #ifdef DEBUG_ON
79
- fprintf(stderr, "print_latex_node: %d\n",n->key);
80
- #endif
81
-
82
- /* If we are forcing a complete document, and METADATA isn't the first thing,
83
- we need to close <head> */
84
- if ((scratch->extensions & EXT_COMPLETE)
85
- && !(scratch->extensions & EXT_HEAD_CLOSED) &&
86
- !((n->key == FOOTER) || (n->key == METADATA))) {
87
- pad(out, 2, scratch);
88
- scratch->extensions = scratch->extensions | EXT_HEAD_CLOSED;
89
- }
90
- switch (n->key) {
91
- case NO_TYPE:
92
- break;
93
- case LIST:
94
- print_latex_node_tree(out,n->children,scratch);
95
- break;
96
- case STR:
97
- print_latex_string(out,n->str, scratch);
98
- break;
99
- case ABBREVIATION:
100
- /* We combine the short and full names, since stripping non-ascii characters may result
101
- in a conflict otherwise. This at least makes it less likely. */
102
- width = ascii_label_from_node(n->children);
103
- temp = ascii_label_from_string(n->str);
104
- g_string_append_printf(out, "\\newacro{%s%s}[",width,temp);
105
- print_latex_node_tree(out, n->children, scratch);
106
- g_string_append_printf(out, "]{");
107
- trim_trailing_whitespace(n->str);
108
- print_latex_string(out, n->str, scratch);
109
- g_string_append_printf(out, "}\n");
110
- free(temp);
111
- free(width);
112
- break;
113
- case ABBRSTART:
114
- /* Strip out nodes that are being replaced with the abbreviation */
115
- temp_node = n->next;
116
- while (temp_node->key != ABBRSTOP) {
117
- n->next = temp_node->next;
118
- temp_node->next = NULL;
119
- free_node(temp_node);
120
- temp_node = n->next;
121
- }
122
- n->next = temp_node->next;
123
- temp_node->next = NULL;
124
- free_node(temp_node);
125
- case ABBR:
126
- /* In either case, now we call on the abbreviation */
127
- width = ascii_label_from_node(n->children->children);
128
- temp = ascii_label_from_string(n->children->str);
129
- g_string_append_printf(out, "\\ac{%s%s}", width, temp);
130
- free(temp);
131
- free(width);
132
- break;
133
- case ABBRSTOP:
134
- break;
135
- case SPACE:
136
- g_string_append_printf(out,"%s",n->str);
137
- break;
138
- case PLAIN:
139
- pad(out,1, scratch);
140
- print_latex_node_tree(out,n->children, scratch);
141
- scratch->padded = 0;
142
- break;
143
- case PARA:
144
- pad(out, 2, scratch);
145
- print_latex_node_tree(out,n->children,scratch);
146
- scratch->padded = 0;
147
- break;
148
- case HRULE:
149
- pad(out, 2, scratch);
150
- g_string_append_printf(out, "\\begin{center}\\rule{3in}{0.4pt}\\end{center}\n");
151
- scratch->padded = 0;
152
- break;
153
- case HTMLBLOCK:
154
- /* don't print HTML block */
155
- /* but do print HTML comments for raw LaTeX */
156
- if (strncmp(n->str,"<!--",4) == 0) {
157
- pad(out, 2, scratch);
158
- /* trim "-->" from end */
159
- n->str[strlen(n->str)-3] = '\0';
160
- g_string_append_printf(out, "%s", &n->str[4]);
161
- scratch->padded = 0;
162
- }
163
- break;
164
- case VERBATIM:
165
- case VERBATIMFENCE:
166
- pad(out, 2, scratch);
167
- if ((n->children != NULL) && (n->children->key == VERBATIMTYPE)) {
168
- trim_trailing_whitespace(n->children->str);
169
- if (strlen(n->children->str) > 0) {
170
- g_string_append_printf(out, "\\begin{lstlisting}[language=%s]\n%s\\end{lstlisting}", n->children->str,n->str);
171
- scratch->padded = 0;
172
- break;
173
- }
174
- }
175
- g_string_append_printf(out, "\\begin{verbatim}\n%s\\end{verbatim}",n->str);
176
- scratch->padded = 0;
177
- break;
178
- case BULLETLIST:
179
- pad(out, 2, scratch);
180
- g_string_append_printf(out, "\\begin{itemize}");
181
- scratch->padded = 0;
182
- print_latex_node_tree(out, n->children, scratch);
183
- pad(out, 1, scratch);
184
- g_string_append_printf(out, "\\end{itemize}");
185
- scratch->padded = 0;
186
- break;
187
- case ORDEREDLIST:
188
- pad(out, 2, scratch);
189
- g_string_append_printf(out, "\\begin{enumerate}");
190
- scratch->padded = 0;
191
- print_latex_node_tree(out, n->children, scratch);
192
- pad(out, 1, scratch);
193
- g_string_append_printf(out, "\\end{enumerate}");
194
- scratch->padded = 0;
195
- break;
196
- case LISTITEM:
197
- pad(out, 1, scratch);
198
- g_string_append_printf(out, "\\item ");
199
- scratch->padded = 2;
200
- print_latex_node_tree(out, n->children, scratch);
201
- g_string_append_printf(out, "\n");
202
- scratch->padded = 0;
203
- break;
204
- case METADATA:
205
- /* print the metadata */
206
- print_latex_node_tree(out,n->children, scratch);
207
- if (!(scratch->extensions & EXT_SNIPPET) && (is_latex_complete_doc(n))) {
208
- scratch->extensions = scratch->extensions | EXT_COMPLETE;
209
- }
210
- /* print acronym definitions */
211
- print_latex_node_tree(out, scratch->abbreviations, scratch);
212
- break;
213
- case METAKEY:
214
- /* reformat the key */
215
- temp = n->str;
216
- n->str = label_from_string(temp);
217
- free(temp);
218
-
219
- if (strcmp(n->str, "baseheaderlevel") == 0) {
220
- scratch->baseheaderlevel = atoi(n->children->str);
221
- break;
222
- } else if (strcmp(n->str, "latexheaderlevel") == 0) {
223
- scratch->baseheaderlevel = atoi(n->children->str);
224
- break;
225
- } else if (strcmp(n->str, "quoteslanguage") == 0) {
226
- temp = label_from_node_tree(n->children);
227
- if ((strcmp(temp, "nl") == 0) || (strcmp(temp, "dutch") == 0)) { scratch->language = DUTCH; } else
228
- if ((strcmp(temp, "de") == 0) || (strcmp(temp, "german") == 0)) { scratch->language = GERMAN; } else
229
- if (strcmp(temp, "germanguillemets") == 0) { scratch->language = GERMANGUILL; } else
230
- if ((strcmp(temp, "fr") == 0) || (strcmp(temp, "french") == 0)) { scratch->language = FRENCH; } else
231
- if ((strcmp(temp, "sv") == 0) || (strcmp(temp, "swedish") == 0)) { scratch->language = SWEDISH; }
232
- break;
233
- }
234
-
235
- /* Don't handle remaining metadata if we're snippet only */
236
-
237
- if (scratch->extensions & EXT_SNIPPET)
238
- break;
239
-
240
- if (strcmp(n->str, "title") == 0) {
241
- g_string_append_printf(out, "\\def\\mytitle{");
242
- print_latex_node(out, n->children, scratch);
243
- g_string_append_printf(out, "}\n");
244
- } else if (strcmp(n->str, "latextitle") == 0) {
245
- g_string_append_printf(out, "\\def\\mytitle{%s}\n",n->children->str);
246
- } else if (strcmp(n->str, "author") == 0) {
247
- g_string_append_printf(out, "\\def\\myauthor{");
248
- print_latex_node(out, n->children, scratch);
249
- g_string_append_printf(out, "}\n");
250
- } else if (strcmp(n->str, "latexauthor") == 0) {
251
- g_string_append_printf(out, "\\def\\myauthor{%s}\n",n->children->str);
252
- } else if (strcmp(n->str, "date") == 0) {
253
- g_string_append_printf(out, "\\def\\mydate{");
254
- print_latex_node(out, n->children, scratch);
255
- g_string_append_printf(out, "}\n");
256
- } else if (strcmp(n->str, "copyright") == 0) {
257
- g_string_append_printf(out, "\\def\\mycopyright{");
258
- print_latex_node(out, n->children, scratch);
259
- g_string_append_printf(out, "}\n");
260
- } else if (strcmp(n->str, "css") == 0) {
261
- } else if (strcmp(n->str, "xhtmlheader") == 0) {
262
- } else if (strcmp(n->str, "htmlheader") == 0) {
263
- } else if (strcmp(n->str, "mmdfooter") == 0) {
264
- } else if (strcmp(n->str, "latexinput") == 0) {
265
- trim_trailing_whitespace(n->children->str);
266
- g_string_append_printf(out, "\\input{%s}\n", n->children->str);
267
- } else if (strcmp(n->str, "latexfooter") == 0) {
268
- trim_trailing_whitespace(n->children->str);
269
- scratch->latex_footer = strdup(n->children->str);
270
- } else if (strcmp(n->str, "bibtex") == 0) {
271
- trim_trailing_whitespace(n->children->str);
272
- g_string_append_printf(out, "\\def\\bibliocommand{\\bibliography{%s}}\n",n->children->str);
273
- } else {
274
- g_string_append_printf(out, "\\def\\");
275
- print_latex_string(out, n->str, scratch);
276
- g_string_append_printf(out, "{");
277
- print_latex_node_tree(out, n->children, scratch);
278
- g_string_append_printf(out, "}\n");
279
- }
280
- break;
281
- case METAVALUE:
282
- trim_trailing_whitespace(n->str);
283
- print_latex_string(out,n->str, scratch);
284
- break;
285
- case FOOTER:
286
- print_latex_endnotes(out, scratch);
287
- if (scratch->latex_footer != NULL) {
288
- pad(out, 2, scratch);
289
- g_string_append_printf(out,"\\input{%s}\n", scratch->latex_footer);
290
- }
291
- if (scratch->extensions & EXT_COMPLETE) {
292
- g_string_append_printf(out, "\n\\end{document}");
293
- }
294
- break;
295
- case HEADINGSECTION:
296
- print_latex_node_tree(out,n->children,scratch);
297
- break;
298
- case H1: case H2: case H3: case H4: case H5: case H6:
299
- lev = n->key - H1 + scratch->baseheaderlevel; /* assumes H1 ... H6 are in order */
300
- if (lev > 7)
301
- lev = 7; /* Max at level 7 */
302
- pad(out, 2, scratch);
303
- switch (lev) {
304
- case 1:
305
- g_string_append_printf(out, "\\part{");
306
- break;
307
- case 2:
308
- g_string_append_printf(out, "\\chapter{");
309
- break;
310
- case 3:
311
- g_string_append_printf(out, "\\section{");
312
- break;
313
- case 4:
314
- g_string_append_printf(out, "\\subsection{");
315
- break;
316
- case 5:
317
- g_string_append_printf(out, "\\subsubsection{");
318
- break;
319
- case 6:
320
- g_string_append_printf(out, "\\paragraph{");
321
- break;
322
- case 7:
323
- g_string_append_printf(out, "\\subparagraph{");
324
- break;
325
- }
326
- /* Don't allow footnotes */
327
- scratch->no_latex_footnote = TRUE;
328
- if (n->children->key == AUTOLABEL) {
329
- /* use label for header since one was specified (MMD)*/
330
- temp = label_from_string(n->children->str);
331
- print_latex_node_tree(out, n->children->next, scratch);
332
- g_string_append_printf(out, "}\n\\label{%s}",temp);
333
- free(temp);
334
- } else {
335
- /* generate a label by default for MMD */
336
- temp = label_from_node_tree(n->children);
337
- print_latex_node_tree(out, n->children, scratch);
338
- g_string_append_printf(out, "}\n\\label{%s}",temp);
339
- free(temp);
340
- }
341
- scratch->no_latex_footnote = FALSE;
342
- scratch->padded = 0;
343
- break;
344
- case APOSTROPHE:
345
- print_latex_localized_typography(out, APOS, scratch);
346
- break;
347
- case ELLIPSIS:
348
- print_latex_localized_typography(out, ELLIP, scratch);
349
- break;
350
- case EMDASH:
351
- print_latex_localized_typography(out, MDASH, scratch);
352
- break;
353
- case ENDASH:
354
- print_latex_localized_typography(out, NDASH, scratch);
355
- break;
356
- case SINGLEQUOTED:
357
- print_latex_localized_typography(out, LSQUOTE, scratch);
358
- print_latex_node_tree(out, n->children, scratch);
359
- print_latex_localized_typography(out, RSQUOTE, scratch);
360
- break;
361
- case DOUBLEQUOTED:
362
- print_latex_localized_typography(out, LDQUOTE, scratch);
363
- print_latex_node_tree(out, n->children, scratch);
364
- print_latex_localized_typography(out, RDQUOTE, scratch);
365
- break;
366
- case LINEBREAK:
367
- g_string_append_printf(out, "\\\\\n");
368
- break;
369
- case MATHSPAN:
370
- temp = strdup(n->str);
371
- if (temp[0] == '$') {
372
- if (temp[1] == '$') {
373
- if (strncmp(&temp[2],"\\begin",5) == 0) {
374
- temp[strlen(temp)-2] = '\0';
375
- g_string_append_printf(out, "%s",&temp[1]);
376
- } else {
377
- g_string_append_printf(out, "%s",temp);
378
- }
379
- } else {
380
- if (strncmp(&temp[1],"\\begin",5) == 0) {
381
- temp[strlen(temp)-1] = '\0';
382
- g_string_append_printf(out, "%s",&temp[1]);
383
- } else {
384
- g_string_append_printf(out, "%s",temp);
385
- }
386
- }
387
- } else if (strncmp(&temp[2],"\\begin",5) == 0) {
388
- /* trim */
389
- temp[strlen(temp)-3] = '\0';
390
- g_string_append_printf(out, "%s", &temp[2]);
391
- } else {
392
- if (temp[strlen(temp)-1] == ']') {
393
- temp[strlen(temp)-3] = '\0';
394
- g_string_append_printf(out, "%s\\]", temp);
395
- } else {
396
- temp[strlen(temp)-3] = '\0';
397
- g_string_append_printf(out, "$%s$", &temp[2]);
398
- }
399
- }
400
- free(temp);
401
- break;
402
- case STRONG:
403
- g_string_append_printf(out, "\\textbf{");
404
- print_latex_node_tree(out,n->children,scratch);
405
- g_string_append_printf(out, "}");
406
- break;
407
- case EMPH:
408
- g_string_append_printf(out, "\\emph{");
409
- print_latex_node_tree(out,n->children,scratch);
410
- g_string_append_printf(out, "}");
411
- break;
412
- case LINKREFERENCE:
413
- break;
414
- case LINK:
415
- #ifdef DEBUG_ON
416
- fprintf(stderr, "print LaTeX link: '%s'\n",n->str);
417
- #endif
418
- /* Do we have proper info? */
419
-
420
- if (n->link_data == NULL) {
421
- /* NULL link_data could occur if we parsed this link before and it didn't
422
- match anything */
423
- n->link_data = mk_link_data(NULL, NULL, NULL, NULL);
424
- }
425
-
426
- if ((n->link_data->label == NULL) &&
427
- (n->link_data->source == NULL)) {
428
- #ifdef DEBUG_ON
429
- fprintf(stderr, "print latex link: '%s'\n",n->str);
430
- #endif
431
- /* we seem to be a [foo][] style link */
432
- /* so load a label */
433
- temp_str = g_string_new("");
434
- print_raw_node_tree(temp_str, n->children);
435
- free(n->link_data->label);
436
- n->link_data->label = temp_str->str;
437
- g_string_free(temp_str, FALSE);
438
- }
439
- #ifdef DEBUG_ON
440
- fprintf(stderr, "look for reference data for latex link: '%s'\n",n->str);
441
- #endif
442
- /* Load reference data */
443
- if (n->link_data->label != NULL) {
444
- #ifdef DEBUG_ON
445
- fprintf(stderr, "have label for latex link: '%s'\n",n->str);
446
- #endif
447
- temp = strdup(n->link_data->label);
448
- free_link_data(n->link_data);
449
- n->link_data = extract_link_data(temp, scratch);
450
- if (n->link_data == NULL) {
451
- /* replace original text since no definition found */
452
- g_string_append_printf(out, "[");
453
- print_latex_node(out, n->children, scratch);
454
- g_string_append_printf(out,"]");
455
- if (n->children->next != NULL) {
456
- g_string_append_printf(out, "[");
457
- print_latex_node_tree(out, n->children->next, scratch);
458
- g_string_append_printf(out,"]");
459
- } else if (n->str != NULL) {
460
- /* no title label, so see if we stashed str*/
461
- g_string_append_printf(out, "%s", n->str);
462
- } else {
463
- g_string_append_printf(out, "[%s]",temp);
464
- }
465
- free(temp);
466
- break;
467
- }
468
- free(temp);
469
- }
470
- temp_str = g_string_new("");
471
- print_latex_node_tree(temp_str, n->children, scratch);
472
- raw_str = g_string_new("");
473
- print_raw_node_tree(raw_str, n->children);
474
-
475
- if ((n->link_data->source != NULL) && (n->link_data->source[0] == '#' )) {
476
- /* link to anchor within the document */
477
- if (strlen(temp_str->str) > 0) {
478
- /* We have text before the link */
479
- g_string_append_printf(out, "%s (", temp_str->str);
480
- }
481
-
482
- if (n->link_data->label == NULL) {
483
- if ((n->link_data->source != NULL) && (strncmp(n->link_data->source,"#",1) == 0)) {
484
- /* This link was specified as [](#bar) */
485
- g_string_append_printf(out, "\\autoref{%s}", n->link_data->source + 1);
486
- } else {
487
- g_string_append_printf(out, "\\href{%s}{}", n->link_data->source);
488
- }
489
- } else {
490
- g_string_append_printf(out, "\\autoref{%s}", n->link_data->label);
491
- }
492
- if (strlen(temp_str->str) > 0) {
493
- g_string_append_printf(out, ")", temp_str->str);
494
- }
495
- } else if (strcmp(raw_str->str, n->link_data->source) == 0){
496
- /* This is a <link> */
497
- g_string_append_printf(out, "\\href{%s}{%s}", n->link_data->source, temp_str->str);
498
- } else if ((strlen(n->link_data->source) > 7) &&
499
- (strcmp(raw_str->str,&n->link_data->source[7]) == 0)) {
500
- /*This is a <mailto> */
501
- g_string_append_printf(out, "\\href{%s}{%s}", n->link_data->source, temp_str->str);
502
- } else {
503
- /* this is a [text](link) */
504
- g_string_append_printf(out, "\\href{%s}{", n->link_data->source);
505
- print_latex_node_tree(out, n->children, scratch);
506
- g_string_append_printf(out, "}");
507
- if (scratch->no_latex_footnote == FALSE) {
508
- g_string_append_printf(out, "\\footnote{\\href{");
509
- print_latex_url(out, n->link_data->source, scratch);
510
- g_string_append_printf(out, "}{", n->link_data->source);
511
- print_latex_string(out, n->link_data->source, scratch);
512
- g_string_append_printf(out, "}}");
513
- }
514
- }
515
- g_string_free(temp_str, true);
516
- g_string_free(raw_str, true);
517
- n->link_data->attr = NULL;
518
- break;
519
- case ATTRKEY:
520
- g_string_append_printf(out, " %s=\"%s\"", n->str,
521
- n->children->str);
522
- break;
523
- case REFNAME:
524
- case SOURCE:
525
- case TITLE:
526
- break;
527
- case IMAGEBLOCK:
528
- pad(out,2, scratch);
529
- case IMAGE:
530
- #ifdef DEBUG_ON
531
- fprintf(stderr, "print image\n");
532
- #endif
533
- /* Do we have proper info? */
534
- if ((n->link_data->label == NULL) &&
535
- (n->link_data->source == NULL)) {
536
- /* we seem to be a [foo][] style link */
537
- /* so load a label */
538
- temp_str = g_string_new("");
539
- print_raw_node_tree(temp_str, n->children);
540
- n->link_data->label = temp_str->str;
541
- g_string_free(temp_str, FALSE);
542
- }
543
- /* Load reference data */
544
- if (n->link_data->label != NULL) {
545
- temp = strdup(n->link_data->label);
546
- free_link_data(n->link_data);
547
- n->link_data = extract_link_data(temp, scratch);
548
- if (n->link_data == NULL) {
549
- /* replace original text since no definition found */
550
- g_string_append_printf(out, "![");
551
- print_latex_node(out, n->children, scratch);
552
- g_string_append_printf(out,"]");
553
- if (n->children->next != NULL) {
554
- g_string_append_printf(out, "[");
555
- print_latex_node_tree(out, n->children->next, scratch);
556
- g_string_append_printf(out,"]");
557
- } else if (n->str != NULL) {
558
- /* no title label, so see if we stashed str*/
559
- g_string_append_printf(out, "%s", n->str);
560
- } else {
561
- g_string_append_printf(out, "[%s]",temp);
562
- }
563
- free(temp);
564
- break;
565
- }
566
- free(temp);
567
- }
568
-
569
- if (n->key == IMAGEBLOCK)
570
- g_string_append_printf(out, "\\begin{figure}[htbp]\n\\centering\n");
571
-
572
- g_string_append_printf(out, "\\includegraphics[");
573
-
574
- #ifdef DEBUG_ON
575
- fprintf(stderr, "attributes\n");
576
- #endif
577
-
578
- if (n->link_data->attr != NULL) {
579
- temp_node = node_for_attribute("height",n->link_data->attr);
580
- if (temp_node != NULL)
581
- height = correct_dimension_units(temp_node->children->str);
582
- temp_node = node_for_attribute("width",n->link_data->attr);
583
- if (temp_node != NULL)
584
- width = correct_dimension_units(temp_node->children->str);
585
- }
586
-
587
- if ((height == NULL) && (width == NULL)) {
588
- /* No dimensions used */
589
- g_string_append_printf(out, "keepaspectratio,width=\\textwidth,height=0.75\\textheight");
590
- } else {
591
- /* At least one dimension given */
592
- if (!((height != NULL) && (width != NULL))) {
593
- /* we only have one */
594
- g_string_append_printf(out, "keepaspectratio,");
595
- }
596
-
597
- if (width != NULL) {
598
- if (width[strlen(width)-1] == '%') {
599
- width[strlen(width)-1] = '\0';
600
- temp_float = strtod(width, NULL);
601
- temp_float = temp_float/100;
602
- g_string_append_printf(out, "width=%.4f\\textwidth,", temp_float);
603
- } else {
604
- g_string_append_printf(out, "width=%s,",width);
605
- }
606
- } else {
607
- g_string_append_printf(out, "width=\\textwidth,");
608
- }
609
-
610
- if (height != NULL) {
611
- if (height[strlen(height)-1] == '%') {
612
- height[strlen(height)-1] = '\0';
613
- temp_float = strtod(height, NULL);
614
- temp_float = temp_float/100;
615
- g_string_append_printf(out, "height=%.4f\\textheight", temp_float);
616
- } else {
617
- g_string_append_printf(out, "height=%s",height);
618
- }
619
- } else {
620
- g_string_append_printf(out, "height=0.75\\textheight");
621
- }
622
- }
623
-
624
- g_string_append_printf(out, "]{%s}",n->link_data->source);
625
-
626
- if (n->key == IMAGEBLOCK) {
627
- if (n->children != NULL) {
628
- temp_str = g_string_new("");
629
- print_latex_node_tree(temp_str,n->children,scratch);
630
- if (temp_str->currentStringLength > 0) {
631
- g_string_append_printf(out, "\n\\caption{");
632
- g_string_append(out, temp_str->str);
633
- g_string_append_printf(out, "}");
634
- }
635
- g_string_free(temp_str, true);
636
- }
637
-
638
- if (n->link_data->label != NULL) {
639
- temp = label_from_string(n->link_data->label);
640
- g_string_append_printf(out, "\n\\label{%s}",temp);
641
- free(temp);
642
- }
643
- g_string_append_printf(out, "\n\\end{figure}");
644
- scratch->padded = 0;
645
- }
646
-
647
- free(height);
648
- free(width);
649
- n->link_data->attr = NULL; /* We'll delete these elsewhere */
650
- break;
651
- #ifdef DEBUG_ON
652
- fprintf(stderr, "finish image\n");
653
- #endif
654
- case NOTEREFERENCE:
655
- lev = note_number_for_node(n, scratch);
656
- temp_node = node_for_count(scratch->used_notes, lev);
657
- scratch->padded = 2;
658
- if (temp_node->key == GLOSSARYSOURCE) {
659
- g_string_append_printf(out, "\\newglossaryentry{%s}{",temp_node->children->children->str);
660
- print_latex_node_tree(out, temp_node->children, scratch);
661
- g_string_append_printf(out, "}}\\glsadd{%s}",temp_node->children->children->str);
662
- } else {
663
- g_string_append_printf(out, "\\footnote{");
664
- print_latex_node_tree(out, temp_node->children, scratch);
665
- g_string_append_printf(out, "}");
666
- }
667
- scratch->padded = 0;
668
- break;
669
- case NOCITATION:
670
- case CITATION:
671
- #ifdef DEBUG_ON
672
- fprintf(stderr, "\nprint cite\n");
673
- #endif
674
- if ((n->link_data != NULL) && (strncmp(n->link_data->label,"[#",2) == 0)) {
675
- /* external citation (e.g. BibTeX) */
676
- n->link_data->label[strlen(n->link_data->label)-1] = '\0';
677
- if (n->key == NOCITATION) {
678
- g_string_append_printf(out, "~\\nocite{%s}",&n->str[2]);
679
- } else {
680
- g_string_append_printf(out, "<FAKE span class=\"externalcitation\">");
681
- g_string_append_printf(out, "</span>");
682
- }
683
- } else {
684
- #ifdef DEBUG_ON
685
- fprintf(stderr, "internal cite\n");
686
- #endif
687
- /* MMD citation, so output as footnote */
688
- /* TODO: create separate stream from footnotes */
689
- lev = note_number_for_label(n->link_data->label, scratch);
690
- if (lev != 0) {
691
- #ifdef DEBUG_ON
692
- fprintf(stderr, "matching cite found\n");
693
- #endif
694
- temp_node = node_for_count(scratch->used_notes, lev);
695
- /* flag that this is used as a citation */
696
- temp_node->key = CITATIONSOURCE;
697
- if (lev > scratch->max_footnote_num) {
698
- scratch->max_footnote_num = lev;
699
- }
700
- if (n->key == NOCITATION) {
701
- g_string_append_printf(out, "~\\nocite{%s}", n->link_data->label);
702
- } else {
703
- if (n->children != NULL) {
704
- g_string_append_printf(out, "~\\citep[");
705
- print_latex_node(out, n->children, scratch);
706
- g_string_append_printf(out,"]{%s}",n->link_data->label);
707
- } else {
708
- g_string_append_printf(out, "~\\citep{%s}", n->link_data->label);
709
- }
710
- }
711
- } else {
712
- /* not located -- this is external cite */
713
- #ifdef DEBUG_ON
714
- fprintf(stderr, "no match for cite: '%s'\n",n->link_data->label);
715
- #endif
716
- temp = n->link_data->label;
717
- if (n->key == NOCITATION) {
718
- g_string_append_printf(out, "~\\nocite{%s}",n->link_data->label);
719
- } else {
720
- if (n->children != NULL) {
721
- #ifdef DEBUG_ON
722
- fprintf(stderr, "cite with children\n");
723
- #endif
724
- if (strcmp(&temp[strlen(temp) - 1],";") == 0) {
725
- g_string_append_printf(out, " \\citet[");
726
- temp[strlen(temp) - 1] = '\0';
727
- } else {
728
- g_string_append_printf(out, "~\\citep[");
729
- }
730
- print_latex_node(out, n->children, scratch);
731
- g_string_append_printf(out, "]{%s}",temp);
732
- } else {
733
- #ifdef DEBUG_ON
734
- fprintf(stderr, "cite without children. locat:'%s'\n",n->str);
735
- #endif
736
- if (strcmp(&temp[strlen(temp) - 1],";") == 0) {
737
- temp[strlen(temp) - 1] = '\0';
738
- g_string_append_printf(out, " \\citet{%s}",temp);
739
- } else {
740
- g_string_append_printf(out, "~\\citep{%s}",temp);
741
- }
742
- }
743
- }
744
- }
745
- }
746
- #ifdef DEBUG_ON
747
- fprintf(stderr, "finish cite\n");
748
- #endif
749
- break;
750
- case VARIABLE:
751
- temp = metavalue_for_key(n->str,scratch->result_tree);
752
- if (temp == NULL) {
753
- g_string_append_printf(out, "[%%%s]",n->str);
754
- } else {
755
- g_string_append_printf(out, temp);
756
- free(temp);
757
- }
758
- break;
759
- case GLOSSARYTERM:
760
- if ((n->next != NULL) && (n->next->key == GLOSSARYSORTKEY) ) {
761
- g_string_append_printf(out, "sort={");
762
- print_latex_string(out, n->next->str, scratch);
763
- g_string_append_printf(out, "},");
764
- }
765
- g_string_append_printf(out,"name={");
766
- print_latex_string(out, n->children->str, scratch);
767
- g_string_append_printf(out, "},description={");
768
- break;
769
- case GLOSSARYSORTKEY:
770
- break;
771
- case CODE:
772
- g_string_append_printf(out, "\\texttt{");
773
- print_latex_string(out, n->str, scratch);
774
- g_string_append_printf(out, "}");
775
- break;
776
- case BLOCKQUOTEMARKER:
777
- print_latex_node_tree(out, n->children, scratch);
778
- break;
779
- case BLOCKQUOTE:
780
- pad(out,2, scratch);
781
- g_string_append_printf(out, "\\begin{quote}");
782
- scratch->padded = 0;
783
- print_latex_node_tree(out, n->children, scratch);
784
- pad(out,1, scratch);
785
- g_string_append_printf(out, "\\end{quote}");
786
- scratch->padded = 0;
787
- break;
788
- case RAW:
789
- /* This shouldn't happen */
790
- g_string_append_printf(out, "RAW:");
791
- g_string_append_printf(out,"%s",n->str);
792
- break;
793
- case HTML:
794
- /* don't print HTML block */
795
- /* but do print HTML comments for raw LaTeX */
796
- if (strncmp(n->str,"<!--",4) == 0) {
797
- /* trim "-->" from end */
798
- n->str[strlen(n->str)-3] = '\0';
799
- g_string_append_printf(out, "%s", &n->str[4]);
800
- scratch->padded = 0;
801
- }
802
- break;
803
- case DEFLIST:
804
- pad(out,2, scratch);
805
- g_string_append_printf(out, "\\begin{description}");
806
- scratch->padded = 0;
807
- print_latex_node_tree(out, n->children, scratch);
808
- pad(out, 1, scratch);
809
- g_string_append_printf(out, "\\end{description}");
810
- scratch->padded = 0;
811
- break;
812
- case TERM:
813
- pad(out,2, scratch);
814
- g_string_append_printf(out, "\\item[");
815
- print_latex_node_tree(out, n->children, scratch);
816
- g_string_append_printf(out, "]");
817
- scratch->padded = 0;
818
- break;
819
- case DEFINITION:
820
- pad(out, 2, scratch);
821
- scratch->padded = 2;
822
- print_latex_node_tree(out, n->children, scratch);
823
- scratch->padded = 0;
824
- break;
825
- case TABLE:
826
- pad(out, 2, scratch);
827
- g_string_append_printf(out, "\\begin{table}[htbp]\n\\begin{minipage}{\\linewidth}\n\\setlength{\\tymax}{0.5\\linewidth}\n\\centering\n\\small\n");
828
- print_latex_node_tree(out, n->children, scratch);
829
- g_string_append_printf(out, "\n\\end{tabulary}\n\\end{minipage}\n\\end{table}");
830
- scratch->padded = 0;
831
- break;
832
- case TABLESEPARATOR:
833
- temp_str = g_string_new("");
834
- for (i = 0; n->str[i]; i++) {
835
- if (n->str[i] != 'h')
836
- g_string_append_printf(temp_str,"%c",toupper(n->str[i]));
837
- }
838
- g_string_append_printf(out, "\\begin{tabulary}{\\textwidth}{@{}%s@{}} \\toprule\n", temp_str->str);
839
-
840
- if (scratch->table_alignment != NULL)
841
- free(scratch->table_alignment);
842
-
843
- scratch->table_alignment = temp_str->str;
844
- g_string_free(temp_str, false);
845
- break;
846
- case TABLECAPTION:
847
- if ((n->children != NULL) && (n->children->key == TABLELABEL)) {
848
- temp = label_from_string(n->children->str);
849
- } else {
850
- temp = label_from_node_tree(n->children);
851
- }
852
- g_string_append_printf(out, "\\caption{");
853
- print_latex_node_tree(out, n->children, scratch);
854
- g_string_append_printf(out, "}\n\\label{%s}\n", temp);
855
- free(temp);
856
- break;
857
- case TABLELABEL:
858
- break;
859
- case TABLEHEAD:
860
- print_latex_node_tree(out, n->children, scratch);
861
- g_string_append_printf(out, "\\midrule\n");
862
- break;
863
- case TABLEBODY:
864
- print_latex_node_tree(out, n->children, scratch);
865
- if ((n->next != NULL) && (n->next->key == TABLEBODY)) {
866
- g_string_append_printf(out, "\n\\midrule\n");
867
- } else {
868
- g_string_append_printf(out, "\n\\bottomrule\n");
869
- }
870
- break;
871
- case TABLEROW:
872
- print_latex_node_tree(out, n->children, scratch);
873
- g_string_append_printf(out, "\\\\\n");
874
- scratch->table_column = 0;
875
- break;
876
- case TABLECELL:
877
- scratch->padded = 2;
878
- temp = scratch->table_alignment;
879
- if ((n->children != NULL) && (n->children->key == CELLSPAN)) {
880
- g_string_append_printf(out, "\\multicolumn{%d}{%c}{",
881
- (int)strlen(n->children->str)+1,tolower(temp[scratch->table_column]));
882
- }
883
- print_latex_node_tree(out, n->children, scratch);
884
- if ((n->children != NULL) && (n->children->key == CELLSPAN)) {
885
- g_string_append_printf(out, "}");
886
- }
887
- if (n->next != NULL)
888
- g_string_append_printf(out, "&");
889
- if ((n->children != NULL) && (n->children->key == CELLSPAN)) {
890
- scratch->table_column += (int)strlen(n->children->str);
891
- }
892
- scratch->table_column++;
893
- break;
894
- case CELLSPAN:
895
- break;
896
- case GLOSSARYSOURCE:
897
- if (scratch->printing_notes)
898
- print_latex_node_tree(out, n->children, scratch);
899
- break;
900
- case CITATIONSOURCE:
901
- case NOTESOURCE:
902
- if (scratch->printing_notes)
903
- print_latex_node(out, n->children, scratch);
904
- break;
905
- case SOURCEBRANCH:
906
- fprintf(stderr,"SOURCEBRANCH\n");
907
- break;
908
- case NOTELABEL:
909
- case GLOSSARYLABEL:
910
- break;
911
- case SUPERSCRIPT:
912
- g_string_append_printf(out, "\\textsuperscript{%s}",n->str);
913
- break;
914
- case SUBSCRIPT:
915
- g_string_append_printf(out, "\\textsubscript{%s}",n->str);
916
- break;
917
- case KEY_COUNTER:
918
- break;
919
- case TOC:
920
- print_latex_node_tree(out,n->children, scratch);
921
- break;
922
- default:
923
- fprintf(stderr, "print_latex_node encountered unknown node key = %d\n",n->key);
924
- exit(EXIT_FAILURE);
925
- }
926
- }
927
-
928
- /* print_latex_endnotes */
929
- void print_latex_endnotes(GString *out, scratch_pad *scratch) {
930
- scratch->used_notes = reverse_list(scratch->used_notes);
931
- scratch->printing_notes = 1;
932
-
933
- node *note = scratch->used_notes;
934
- #ifdef DEBUG_ON
935
- fprintf(stderr, "start endnotes\n");
936
- #endif
937
-
938
- if ((note == NULL) || ((note->key == KEY_COUNTER) && (note->next == NULL)))
939
- return;
940
- while (note != NULL) {
941
- if (note->key == CITATIONSOURCE)
942
- break;
943
- note = note->next;
944
- }
945
-
946
- if (note == NULL)
947
- return;
948
-
949
- note = scratch->used_notes;
950
-
951
- /* TODO: need CITATIONSOURCE to print bibliography */
952
- #ifdef DEBUG_ON
953
- fprintf(stderr, "there are endnotes to print\n");
954
- #endif
955
-
956
- pad(out, 2, scratch);
957
- g_string_append_printf(out, "\\begin{thebibliography}{0}");
958
- while ( note != NULL) {
959
- if (note->key == KEY_COUNTER) {
960
- note = note->next;
961
- continue;
962
- }
963
-
964
- pad(out, 1, scratch);
965
-
966
- if (note->key == CITATIONSOURCE) {
967
- g_string_append_printf(out, "\\bibitem{%s}\n", note->str);
968
- scratch->padded = 2;
969
-
970
- print_latex_node(out, note, scratch);
971
- pad(out, 1, scratch);
972
- scratch->padded = 1;
973
- } else {
974
- /* footnotes handled elsewhere */
975
- }
976
-
977
- note = note->next;
978
- }
979
- pad(out,2, scratch);
980
- g_string_append_printf(out, "\\end{thebibliography}");
981
- scratch->padded = 0;
982
- #ifdef DEBUG_ON
983
- fprintf(stderr, "finish endnotes\n");
984
- #endif
985
- }
986
-
987
- /* Check metadata keys and determine if we need a complete document */
988
- /* We also preconvert metadata keys to proper formatting -- lowercase with no spaces */
989
- bool is_latex_complete_doc(node *meta) {
990
- node *step;
991
- char *temp;
992
- step = meta->children;
993
-
994
- while (step != NULL) {
995
- /* process key to proper label */
996
- temp = step->str; /* store pointer to original str */
997
- step->str = label_from_string(step->str);
998
- free(temp); /* free original since we don't need it */
999
- step = step->next;
1000
- }
1001
-
1002
- step = meta->children;
1003
- while (step != NULL) {
1004
- /* the following types of metadata do not require a complete document */
1005
- if ((strcmp(step->str, "baseheaderlevel") != 0) &&
1006
- (strcmp(step->str, "xhtmlheaderlevel") != 0) &&
1007
- (strcmp(step->str, "htmlheaderlevel") != 0) &&
1008
- (strcmp(step->str, "latexheaderlevel") != 0) &&
1009
- (strcmp(step->str, "odfheaderlevel") != 0) &&
1010
- (strcmp(step->str, "xhtmlheader") != 0) &&
1011
- (strcmp(step->str, "htmlheader") != 0) &&
1012
- (strcmp(step->str, "quoteslanguage") != 0))
1013
- { return TRUE;}
1014
- step = step->next;
1015
- }
1016
-
1017
- return FALSE;
1018
- }
1019
-
1020
- /* print_latex_localized_typography -- convert to "smart" typography */
1021
- void print_latex_localized_typography(GString *out, int character, scratch_pad *scratch) {
1022
- if (!extension(EXT_SMART, scratch->extensions)) {
1023
- g_string_append_c(out, character);
1024
- return;
1025
- }
1026
- switch (character) {
1027
- case LSQUOTE:
1028
- switch (scratch->language) {
1029
- case SWEDISH:
1030
- g_string_append_printf(out, "'");
1031
- break;
1032
- case FRENCH:
1033
- g_string_append_printf(out,"'");
1034
- break;
1035
- case GERMAN:
1036
- g_string_append_printf(out,"‚");
1037
- break;
1038
- case GERMANGUILL:
1039
- g_string_append_printf(out,"›");
1040
- break;
1041
- default:
1042
- g_string_append_printf(out,"`");
1043
- }
1044
- break;
1045
- case RSQUOTE:
1046
- switch (scratch->language) {
1047
- case GERMAN:
1048
- g_string_append_printf(out,"`");
1049
- break;
1050
- case GERMANGUILL:
1051
- g_string_append_printf(out,"‹");
1052
- break;
1053
- default:
1054
- g_string_append_printf(out,"'");
1055
- }
1056
- break;
1057
- case APOS:
1058
- g_string_append_printf(out,"'");
1059
- break;
1060
- case LDQUOTE:
1061
- switch (scratch->language) {
1062
- case DUTCH:
1063
- case GERMAN:
1064
- g_string_append_printf(out,"„");
1065
- break;
1066
- case GERMANGUILL:
1067
- g_string_append_printf(out,"»");
1068
- break;
1069
- case FRENCH:
1070
- g_string_append_printf(out,"«");
1071
- break;
1072
- case SWEDISH:
1073
- g_string_append_printf(out, "''");
1074
- break;
1075
- default:
1076
- g_string_append_printf(out,"``");
1077
- }
1078
- break;
1079
- case RDQUOTE:
1080
- switch (scratch->language) {
1081
- case SWEDISH:
1082
- case DUTCH:
1083
- g_string_append_printf(out,"''");
1084
- break;
1085
- case GERMAN:
1086
- g_string_append_printf(out,"``");
1087
- break;
1088
- case GERMANGUILL:
1089
- g_string_append_printf(out,"«");
1090
- break;
1091
- case FRENCH:
1092
- g_string_append_printf(out,"»");
1093
- break;
1094
- default:
1095
- g_string_append_printf(out,"''");
1096
- }
1097
- break;
1098
- case NDASH:
1099
- g_string_append_printf(out,"--");
1100
- break;
1101
- case MDASH:
1102
- g_string_append_printf(out,"---");
1103
- break;
1104
- case ELLIP:
1105
- g_string_append_printf(out,"{\\ldots}");
1106
- break;
1107
- default:;
1108
- }
1109
- }
1110
-
1111
- /* print_latex_string - print string, escaping for LaTeX */
1112
- void print_latex_string(GString *out, char *str, scratch_pad *scratch) {
1113
- char *tmp;
1114
- char *start;
1115
- if (str == NULL)
1116
- return;
1117
- start = str; /* Store start of string */
1118
- while (*str != '\0') {
1119
- switch (*str) {
1120
- case '{': case '}': case '$': case '%':
1121
- case '&': case '_': case '#':
1122
- g_string_append_printf(out, "\\%c", *str);
1123
- break;
1124
- case '^':
1125
- g_string_append_printf(out, "\\^{}");
1126
- break;
1127
- case '\\':
1128
- g_string_append_printf(out, "\\textbackslash{}");
1129
- break;
1130
- case '~':
1131
- g_string_append_printf(out, "\\ensuremath{\\sim}");
1132
- break;
1133
- case '|':
1134
- g_string_append_printf(out, "\\textbar{}");
1135
- break;
1136
- case '<':
1137
- g_string_append_printf(out, "$<$");
1138
- break;
1139
- case '>':
1140
- g_string_append_printf(out, "$>$");
1141
- break;
1142
- case '/':
1143
- str++;
1144
- while (*str == '/') {
1145
- g_string_append_printf(out, "/");
1146
- str++;
1147
- }
1148
- g_string_append_printf(out, "\\slash ");
1149
- str--;
1150
- break;
1151
- case '\n':
1152
- tmp = str;
1153
- tmp--;
1154
- if ((tmp > start) && (*tmp == ' ')) {
1155
- tmp--;
1156
- if (*tmp == ' ') {
1157
- g_string_append_printf(out, "\\\\\n");
1158
- } else {
1159
- g_string_append_printf(out, "\n");
1160
- }
1161
- } else {
1162
- g_string_append_printf(out, "\n");
1163
- }
1164
- break;
1165
- case '-':
1166
- str++;
1167
- if (*str == '-') {
1168
- g_string_append_printf(out, "-{}");
1169
- str--;
1170
- } else {
1171
- str--;
1172
- g_string_append_c(out,*str);
1173
- }
1174
- break;
1175
- default:
1176
- g_string_append_c(out, *str);
1177
- }
1178
- str++;
1179
- }
1180
- }
1181
-
1182
- /* print_latex_url - print url, escaping for LaTeX */
1183
- void print_latex_url(GString *out, char *str, scratch_pad *scratch) {
1184
- if (str == NULL)
1185
- return;
1186
- while (*str != '\0') {
1187
- switch (*str) {
1188
- case '$': case '%': case '!':
1189
- case '&': case '_': case '#':
1190
- g_string_append_printf(out, "\\%c", *str);
1191
- break;
1192
- case '^':
1193
- g_string_append_printf(out, "\\^{}");
1194
- break;
1195
- default:
1196
- g_string_append_c(out, *str);
1197
- }
1198
- str++;
1199
- }
1200
- }
1201
-
1202
- char * correct_dimension_units(char *original) {
1203
- char *result;
1204
- int i;
1205
-
1206
- result = strdup(original);
1207
-
1208
- for (i = 0; result[i]; i++)
1209
- result[i] = tolower(result[i]);
1210
-
1211
- if (strstr(&result[strlen(result)-2],"px")) {
1212
- result[strlen(result)-2] = '\0';
1213
- strcat(result, "pt");
1214
- }
1215
-
1216
- return result;
1217
- }