mmd-ruby 5.2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +78 -0
  3. data/MultiMarkdown-5/src/GLibFacade.c +310 -0
  4. data/MultiMarkdown-5/src/GLibFacade.h +100 -0
  5. data/MultiMarkdown-5/src/beamer.c +182 -0
  6. data/MultiMarkdown-5/src/beamer.h +11 -0
  7. data/MultiMarkdown-5/src/critic.c +117 -0
  8. data/MultiMarkdown-5/src/critic.h +15 -0
  9. data/MultiMarkdown-5/src/glib.h +11 -0
  10. data/MultiMarkdown-5/src/html.c +1171 -0
  11. data/MultiMarkdown-5/src/html.h +14 -0
  12. data/MultiMarkdown-5/src/latex.c +1234 -0
  13. data/MultiMarkdown-5/src/latex.h +16 -0
  14. data/MultiMarkdown-5/src/libMultiMarkdown.h +257 -0
  15. data/MultiMarkdown-5/src/lyx.c +2269 -0
  16. data/MultiMarkdown-5/src/lyx.h +37 -0
  17. data/MultiMarkdown-5/src/lyxbeamer.c +265 -0
  18. data/MultiMarkdown-5/src/lyxbeamer.h +11 -0
  19. data/MultiMarkdown-5/src/memoir.c +80 -0
  20. data/MultiMarkdown-5/src/memoir.h +10 -0
  21. data/MultiMarkdown-5/src/multimarkdown.c +559 -0
  22. data/MultiMarkdown-5/src/odf.c +1241 -0
  23. data/MultiMarkdown-5/src/odf.h +18 -0
  24. data/MultiMarkdown-5/src/opml.c +189 -0
  25. data/MultiMarkdown-5/src/opml.h +15 -0
  26. data/MultiMarkdown-5/src/parse_utilities.c +912 -0
  27. data/MultiMarkdown-5/src/parser.c +17341 -0
  28. data/MultiMarkdown-5/src/parser.h +190 -0
  29. data/MultiMarkdown-5/src/rng.c +117 -0
  30. data/MultiMarkdown-5/src/rtf.c +665 -0
  31. data/MultiMarkdown-5/src/rtf.h +17 -0
  32. data/MultiMarkdown-5/src/strtok.c +56 -0
  33. data/MultiMarkdown-5/src/strtok.h +9 -0
  34. data/MultiMarkdown-5/src/text.c +56 -0
  35. data/MultiMarkdown-5/src/text.h +11 -0
  36. data/MultiMarkdown-5/src/toc.c +157 -0
  37. data/MultiMarkdown-5/src/toc.h +15 -0
  38. data/MultiMarkdown-5/src/transclude.c +335 -0
  39. data/MultiMarkdown-5/src/transclude.h +28 -0
  40. data/MultiMarkdown-5/src/version.h +59 -0
  41. data/MultiMarkdown-5/src/writer.c +767 -0
  42. data/MultiMarkdown-5/src/writer.h +38 -0
  43. data/README.md +77 -0
  44. data/Rakefile +88 -0
  45. data/bin/mmd-ruby +123 -0
  46. data/ext/extconf.h +3 -0
  47. data/ext/extconf.rb +10 -0
  48. data/ext/multimarkdown.c +133 -0
  49. data/lib/mmd-jekyll.rb +19 -0
  50. data/lib/mmd-ruby.rb +1 -0
  51. data/lib/mmd.rb +1 -0
  52. data/lib/multimarkdown-ruby.rb +1 -0
  53. data/lib/multimarkdown.bundle +0 -0
  54. data/lib/multimarkdown.rb +69 -0
  55. data/lib/multimarkdown/version.rb +6 -0
  56. data/mmd-ruby.gemspec +37 -0
  57. data/test/extensions_test.rb +174 -0
  58. data/test/multimarkdown_test.rb +77 -0
  59. metadata +120 -0
@@ -0,0 +1,14 @@
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
@@ -0,0 +1,1234 @@
1
+ /*
2
+
3
+ latex.c -- LaTeX writer
4
+
5
+ (c) 2013-2016 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, "htmlfooter") == 0) {
264
+ } else if (strcmp(n->str, "mmdfooter") == 0) {
265
+ } else if (strcmp(n->str, "mmdheader") == 0) {
266
+ } else if (strcmp(n->str, "lang") == 0) {
267
+ } else if (strcmp(n->str, "latexinput") == 0) {
268
+ trim_trailing_whitespace(n->children->str);
269
+ g_string_append_printf(out, "\\input{%s}\n", n->children->str);
270
+ } else if (strcmp(n->str, "latexfooter") == 0) {
271
+ trim_trailing_whitespace(n->children->str);
272
+ scratch->latex_footer = strdup(n->children->str);
273
+ } else if (strcmp(n->str, "bibtex") == 0) {
274
+ trim_trailing_whitespace(n->children->str);
275
+ g_string_append_printf(out, "\\def\\bibliocommand{\\bibliography{%s}}\n",n->children->str);
276
+ } else {
277
+ g_string_append_printf(out, "\\def\\");
278
+ print_latex_string(out, n->str, scratch);
279
+ g_string_append_printf(out, "{");
280
+ print_latex_node_tree(out, n->children, scratch);
281
+ g_string_append_printf(out, "}\n");
282
+ }
283
+ break;
284
+ case METAVALUE:
285
+ trim_trailing_whitespace(n->str);
286
+ print_latex_string(out,n->str, scratch);
287
+ break;
288
+ case FOOTER:
289
+ print_latex_endnotes(out, scratch);
290
+ if (scratch->latex_footer != NULL) {
291
+ pad(out, 2, scratch);
292
+ g_string_append_printf(out,"\\input{%s}\n", scratch->latex_footer);
293
+ }
294
+ if (scratch->extensions & EXT_COMPLETE) {
295
+ g_string_append_printf(out, "\n\\end{document}");
296
+ }
297
+ break;
298
+ case HEADINGSECTION:
299
+ print_latex_node_tree(out,n->children,scratch);
300
+ break;
301
+ case H1: case H2: case H3: case H4: case H5: case H6:
302
+ lev = n->key - H1 + scratch->baseheaderlevel; /* assumes H1 ... H6 are in order */
303
+ if (lev > 7)
304
+ lev = 7; /* Max at level 7 */
305
+ pad(out, 2, scratch);
306
+ switch (lev) {
307
+ case 1:
308
+ g_string_append_printf(out, "\\part{");
309
+ break;
310
+ case 2:
311
+ g_string_append_printf(out, "\\chapter{");
312
+ break;
313
+ case 3:
314
+ g_string_append_printf(out, "\\section{");
315
+ break;
316
+ case 4:
317
+ g_string_append_printf(out, "\\subsection{");
318
+ break;
319
+ case 5:
320
+ g_string_append_printf(out, "\\subsubsection{");
321
+ break;
322
+ case 6:
323
+ g_string_append_printf(out, "\\paragraph{");
324
+ break;
325
+ case 7:
326
+ g_string_append_printf(out, "\\subparagraph{");
327
+ break;
328
+ }
329
+ /* Don't allow footnotes */
330
+ scratch->no_latex_footnote = TRUE;
331
+ if (n->children->key == AUTOLABEL) {
332
+ /* use label for header since one was specified (MMD)*/
333
+ temp = label_from_string(n->children->str);
334
+ print_latex_node_tree(out, n->children->next, scratch);
335
+ g_string_append_printf(out, "}\n\\label{%s}",temp);
336
+ free(temp);
337
+ } else {
338
+ /* generate a label by default for MMD */
339
+ temp = label_from_node_tree(n->children);
340
+ print_latex_node_tree(out, n->children, scratch);
341
+ g_string_append_printf(out, "}\n\\label{%s}",temp);
342
+ free(temp);
343
+ }
344
+ scratch->no_latex_footnote = FALSE;
345
+ scratch->padded = 0;
346
+ break;
347
+ case APOSTROPHE:
348
+ print_latex_localized_typography(out, APOS, scratch);
349
+ break;
350
+ case ELLIPSIS:
351
+ print_latex_localized_typography(out, ELLIP, scratch);
352
+ break;
353
+ case EMDASH:
354
+ print_latex_localized_typography(out, MDASH, scratch);
355
+ break;
356
+ case ENDASH:
357
+ print_latex_localized_typography(out, NDASH, scratch);
358
+ break;
359
+ case SINGLEQUOTED:
360
+ print_latex_localized_typography(out, LSQUOTE, scratch);
361
+ print_latex_node_tree(out, n->children, scratch);
362
+ print_latex_localized_typography(out, RSQUOTE, scratch);
363
+ break;
364
+ case DOUBLEQUOTED:
365
+ print_latex_localized_typography(out, LDQUOTE, scratch);
366
+ print_latex_node_tree(out, n->children, scratch);
367
+ print_latex_localized_typography(out, RDQUOTE, scratch);
368
+ break;
369
+ case LINEBREAK:
370
+ g_string_append_printf(out, "\\\\\n");
371
+ break;
372
+ case MATHSPAN:
373
+ temp = strdup(n->str);
374
+ if (temp[0] == '$') {
375
+ if (temp[1] == '$') {
376
+ if (strncmp(&temp[2],"\\begin",5) == 0) {
377
+ temp[strlen(temp)-2] = '\0';
378
+ g_string_append_printf(out, "%s",&temp[2]);
379
+ } else {
380
+ g_string_append_printf(out, "%s",temp);
381
+ }
382
+ } else {
383
+ if (strncmp(&temp[1],"\\begin",5) == 0) {
384
+ temp[strlen(temp)-1] = '\0';
385
+ g_string_append_printf(out, "%s",&temp[1]);
386
+ } else {
387
+ g_string_append_printf(out, "%s",temp);
388
+ }
389
+ }
390
+ } else if (strncmp(&temp[2],"\\begin",5) == 0) {
391
+ /* trim */
392
+ temp[strlen(temp)-3] = '\0';
393
+ g_string_append_printf(out, "%s", &temp[2]);
394
+ } else {
395
+ if (temp[strlen(temp)-1] == ']') {
396
+ temp[strlen(temp)-3] = '\0';
397
+ g_string_append_printf(out, "%s\\]", temp);
398
+ } else {
399
+ temp[strlen(temp)-3] = '\0';
400
+ g_string_append_printf(out, "$%s$", &temp[2]);
401
+ }
402
+ }
403
+ free(temp);
404
+ break;
405
+ case STRONG:
406
+ g_string_append_printf(out, "\\textbf{");
407
+ print_latex_node_tree(out,n->children,scratch);
408
+ g_string_append_printf(out, "}");
409
+ break;
410
+ case EMPH:
411
+ g_string_append_printf(out, "\\emph{");
412
+ print_latex_node_tree(out,n->children,scratch);
413
+ g_string_append_printf(out, "}");
414
+ break;
415
+ case LINKREFERENCE:
416
+ break;
417
+ case LINK:
418
+ #ifdef DEBUG_ON
419
+ fprintf(stderr, "print LaTeX link: '%s'\n",n->str);
420
+ #endif
421
+ /* Do we have proper info? */
422
+
423
+ if (n->link_data == NULL) {
424
+ /* NULL link_data could occur if we parsed this link before and it didn't
425
+ match anything */
426
+ n->link_data = mk_link_data(NULL, NULL, NULL, NULL);
427
+ }
428
+
429
+ if ((n->link_data->label == NULL) &&
430
+ (n->link_data->source == NULL)) {
431
+ #ifdef DEBUG_ON
432
+ fprintf(stderr, "print latex link: '%s'\n",n->str);
433
+ #endif
434
+ /* we seem to be a [foo][] style link */
435
+ /* so load a label */
436
+ temp_str = g_string_new("");
437
+ print_raw_node_tree(temp_str, n->children);
438
+ free(n->link_data->label);
439
+ n->link_data->label = temp_str->str;
440
+ g_string_free(temp_str, FALSE);
441
+ }
442
+ #ifdef DEBUG_ON
443
+ fprintf(stderr, "look for reference data for latex link: '%s'\n",n->str);
444
+ #endif
445
+ /* Load reference data */
446
+ if (n->link_data->label != NULL) {
447
+ #ifdef DEBUG_ON
448
+ fprintf(stderr, "have label for latex link: '%s'\n",n->str);
449
+ #endif
450
+ temp = strdup(n->link_data->label);
451
+ free_link_data(n->link_data);
452
+ n->link_data = extract_link_data(temp, scratch);
453
+ if (n->link_data == NULL) {
454
+ /* replace original text since no definition found */
455
+ g_string_append_printf(out, "[");
456
+ print_latex_node(out, n->children, scratch);
457
+ g_string_append_printf(out,"]");
458
+ if (n->children->next != NULL) {
459
+ g_string_append_printf(out, "[");
460
+ print_latex_node_tree(out, n->children->next, scratch);
461
+ g_string_append_printf(out,"]");
462
+ } else if (n->str != NULL) {
463
+ /* no title label, so see if we stashed str*/
464
+ g_string_append_printf(out, "%s", n->str);
465
+ } else {
466
+ g_string_append_printf(out, "[%s]",temp);
467
+ }
468
+ free(temp);
469
+ break;
470
+ }
471
+ free(temp);
472
+ }
473
+ temp_str = g_string_new("");
474
+ print_latex_node_tree(temp_str, n->children, scratch);
475
+ raw_str = g_string_new("");
476
+ print_raw_node_tree(raw_str, n->children);
477
+
478
+ if ((n->link_data->source != NULL) && (n->link_data->source[0] == '#' )) {
479
+ /* link to anchor within the document */
480
+ if (strlen(temp_str->str) > 0) {
481
+ /* We have text before the link */
482
+ g_string_append_printf(out, "%s (", temp_str->str);
483
+ }
484
+
485
+ if (n->link_data->label == NULL) {
486
+ if ((n->link_data->source != NULL) && (strncmp(n->link_data->source,"#",1) == 0)) {
487
+ /* This link was specified as [](#bar) */
488
+ g_string_append_printf(out, "\\autoref{%s}", n->link_data->source + 1);
489
+ } else {
490
+ g_string_append_printf(out, "\\href{%s}{}", n->link_data->source);
491
+ }
492
+ } else {
493
+ g_string_append_printf(out, "\\autoref{%s}", n->link_data->label);
494
+ }
495
+ if (strlen(temp_str->str) > 0) {
496
+ g_string_append_printf(out, ")", temp_str->str);
497
+ }
498
+ } else if (strcmp(raw_str->str, n->link_data->source) == 0){
499
+ /* This is a <link> */
500
+ g_string_append_printf(out, "\\href{%s}{%s}", n->link_data->source, temp_str->str);
501
+ } else if ((strlen(n->link_data->source) > 7) &&
502
+ (strcmp(raw_str->str,&n->link_data->source[7]) == 0)) {
503
+ /*This is a <mailto> */
504
+ g_string_append_printf(out, "\\href{%s}{%s}", n->link_data->source, temp_str->str);
505
+ } else {
506
+ /* this is a [text](link) */
507
+ g_string_append_printf(out, "\\href{%s}{", n->link_data->source);
508
+ print_latex_node_tree(out, n->children, scratch);
509
+ g_string_append_printf(out, "}");
510
+ if (scratch->no_latex_footnote == FALSE) {
511
+ g_string_append_printf(out, "\\footnote{\\href{");
512
+ print_latex_url(out, n->link_data->source, scratch);
513
+ g_string_append_printf(out, "}{", n->link_data->source);
514
+ print_latex_string(out, n->link_data->source, scratch);
515
+ g_string_append_printf(out, "}}");
516
+ }
517
+ }
518
+ g_string_free(temp_str, true);
519
+ g_string_free(raw_str, true);
520
+ n->link_data->attr = NULL;
521
+ break;
522
+ case ATTRKEY:
523
+ g_string_append_printf(out, " %s=\"%s\"", n->str,
524
+ n->children->str);
525
+ break;
526
+ case REFNAME:
527
+ case SOURCE:
528
+ case TITLE:
529
+ break;
530
+ case IMAGEBLOCK:
531
+ pad(out,2, scratch);
532
+ case IMAGE:
533
+ #ifdef DEBUG_ON
534
+ fprintf(stderr, "print image\n");
535
+ #endif
536
+ /* Do we have proper info? */
537
+ if ((n->link_data->label == NULL) &&
538
+ (n->link_data->source == NULL)) {
539
+ /* we seem to be a [foo][] style link */
540
+ /* so load a label */
541
+ temp_str = g_string_new("");
542
+ print_raw_node_tree(temp_str, n->children);
543
+ n->link_data->label = temp_str->str;
544
+ g_string_free(temp_str, FALSE);
545
+ }
546
+ /* Load reference data */
547
+ if (n->link_data->label != NULL) {
548
+ temp = strdup(n->link_data->label);
549
+ free_link_data(n->link_data);
550
+ n->link_data = extract_link_data(temp, scratch);
551
+ if (n->link_data == NULL) {
552
+ /* replace original text since no definition found */
553
+ g_string_append_printf(out, "![");
554
+ print_latex_node(out, n->children, scratch);
555
+ g_string_append_printf(out,"]");
556
+ if (n->children->next != NULL) {
557
+ g_string_append_printf(out, "[");
558
+ print_latex_node_tree(out, n->children->next, scratch);
559
+ g_string_append_printf(out,"]");
560
+ } else if (n->str != NULL) {
561
+ /* no title label, so see if we stashed str*/
562
+ g_string_append_printf(out, "%s", n->str);
563
+ } else {
564
+ g_string_append_printf(out, "[%s]",temp);
565
+ }
566
+ free(temp);
567
+ break;
568
+ }
569
+ free(temp);
570
+ }
571
+
572
+ if (n->key == IMAGEBLOCK)
573
+ g_string_append_printf(out, "\\begin{figure}[htbp]\n\\centering\n");
574
+
575
+ g_string_append_printf(out, "\\includegraphics[");
576
+
577
+ #ifdef DEBUG_ON
578
+ fprintf(stderr, "attributes\n");
579
+ #endif
580
+
581
+ if (n->link_data->attr != NULL) {
582
+ temp_node = node_for_attribute("height",n->link_data->attr);
583
+ if (temp_node != NULL)
584
+ height = correct_dimension_units(temp_node->children->str);
585
+ temp_node = node_for_attribute("width",n->link_data->attr);
586
+ if (temp_node != NULL)
587
+ width = correct_dimension_units(temp_node->children->str);
588
+ }
589
+
590
+ if ((height == NULL) && (width == NULL)) {
591
+ /* No dimensions used */
592
+ g_string_append_printf(out, "keepaspectratio,width=\\textwidth,height=0.75\\textheight");
593
+ } else {
594
+ /* At least one dimension given */
595
+ if (!((height != NULL) && (width != NULL))) {
596
+ /* we only have one */
597
+ g_string_append_printf(out, "keepaspectratio,");
598
+ }
599
+
600
+ if (width != NULL) {
601
+ if (width[strlen(width)-1] == '%') {
602
+ width[strlen(width)-1] = '\0';
603
+ temp_float = strtod(width, NULL);
604
+ temp_float = temp_float/100;
605
+ g_string_append_printf(out, "width=%.4f\\textwidth,", temp_float);
606
+ } else {
607
+ g_string_append_printf(out, "width=%s,",width);
608
+ }
609
+ } else {
610
+ g_string_append_printf(out, "width=\\textwidth,");
611
+ }
612
+
613
+ if (height != NULL) {
614
+ if (height[strlen(height)-1] == '%') {
615
+ height[strlen(height)-1] = '\0';
616
+ temp_float = strtod(height, NULL);
617
+ temp_float = temp_float/100;
618
+ g_string_append_printf(out, "height=%.4f\\textheight", temp_float);
619
+ } else {
620
+ g_string_append_printf(out, "height=%s",height);
621
+ }
622
+ } else {
623
+ g_string_append_printf(out, "height=0.75\\textheight");
624
+ }
625
+ }
626
+
627
+ g_string_append_printf(out, "]{%s}",n->link_data->source);
628
+
629
+ if (n->key == IMAGEBLOCK) {
630
+ if (n->children != NULL) {
631
+ temp_str = g_string_new("");
632
+ print_latex_node_tree(temp_str,n->children,scratch);
633
+ if (temp_str->currentStringLength > 0) {
634
+ g_string_append_printf(out, "\n\\caption{");
635
+ g_string_append(out, temp_str->str);
636
+ g_string_append_printf(out, "}");
637
+ }
638
+ g_string_free(temp_str, true);
639
+ }
640
+
641
+ if (n->link_data->label != NULL) {
642
+ temp = label_from_string(n->link_data->label);
643
+ g_string_append_printf(out, "\n\\label{%s}",temp);
644
+ free(temp);
645
+ }
646
+ g_string_append_printf(out, "\n\\end{figure}");
647
+ scratch->padded = 0;
648
+ }
649
+
650
+ free(height);
651
+ free(width);
652
+ n->link_data->attr = NULL; /* We'll delete these elsewhere */
653
+ break;
654
+ #ifdef DEBUG_ON
655
+ fprintf(stderr, "finish image\n");
656
+ #endif
657
+ case NOTEREFERENCE:
658
+ lev = note_number_for_node(n, scratch);
659
+ temp_node = node_for_count(scratch->used_notes, lev);
660
+ scratch->padded = 2;
661
+ if (temp_node->key == GLOSSARYSOURCE) {
662
+ g_string_append_printf(out, "\\newglossaryentry{%s}{",temp_node->children->children->str);
663
+ print_latex_node_tree(out, temp_node->children, scratch);
664
+ g_string_append_printf(out, "}}\\glsadd{%s}",temp_node->children->children->str);
665
+ } else {
666
+ g_string_append_printf(out, "\\footnote{");
667
+ scratch->inside_footnote = true;
668
+ print_latex_node_tree(out, temp_node->children, scratch);
669
+ scratch->inside_footnote = false;
670
+ g_string_append_printf(out, "}");
671
+ }
672
+ scratch->padded = 0;
673
+ break;
674
+ case NOCITATION:
675
+ case CITATION:
676
+ #ifdef DEBUG_ON
677
+ fprintf(stderr, "\nprint cite\n");
678
+ #endif
679
+ if ((n->link_data != NULL) && (strncmp(n->link_data->label,"[#",2) == 0)) {
680
+ /* external citation (e.g. BibTeX) */
681
+ n->link_data->label[strlen(n->link_data->label)-1] = '\0';
682
+ if (n->key == NOCITATION) {
683
+ g_string_append_printf(out, "~\\nocite{%s}",&n->str[2]);
684
+ } else {
685
+ g_string_append_printf(out, "<FAKE span class=\"externalcitation\">");
686
+ g_string_append_printf(out, "</span>");
687
+ }
688
+ } else {
689
+ #ifdef DEBUG_ON
690
+ fprintf(stderr, "internal cite\n");
691
+ #endif
692
+ /* MMD citation, so output as footnote */
693
+ /* TODO: create separate stream from footnotes */
694
+ lev = note_number_for_label(n->link_data->label, scratch);
695
+ if (lev != 0) {
696
+ #ifdef DEBUG_ON
697
+ fprintf(stderr, "matching cite found\n");
698
+ #endif
699
+ temp_node = node_for_count(scratch->used_notes, lev);
700
+ /* flag that this is used as a citation */
701
+ temp_node->key = CITATIONSOURCE;
702
+ if (lev > scratch->max_footnote_num) {
703
+ scratch->max_footnote_num = lev;
704
+ }
705
+ if (n->key == NOCITATION) {
706
+ g_string_append_printf(out, "~\\nocite{%s}", n->link_data->label);
707
+ } else {
708
+ if (n->children != NULL) {
709
+ g_string_append_printf(out, "~\\citep[");
710
+ print_latex_node(out, n->children, scratch);
711
+ g_string_append_printf(out,"]{%s}",n->link_data->label);
712
+ } else {
713
+ g_string_append_printf(out, "~\\citep{%s}", n->link_data->label);
714
+ }
715
+ }
716
+ } else {
717
+ /* not located -- this is external cite */
718
+ #ifdef DEBUG_ON
719
+ fprintf(stderr, "no match for cite: '%s'\n",n->link_data->label);
720
+ #endif
721
+ temp = n->link_data->label;
722
+ if (n->key == NOCITATION) {
723
+ g_string_append_printf(out, "~\\nocite{%s}",n->link_data->label);
724
+ } else {
725
+ if (n->children != NULL) {
726
+ #ifdef DEBUG_ON
727
+ fprintf(stderr, "cite with children\n");
728
+ #endif
729
+ if (strcmp(&temp[strlen(temp) - 1],";") == 0) {
730
+ g_string_append_printf(out, " \\citet[");
731
+ temp[strlen(temp) - 1] = '\0';
732
+ } else {
733
+ g_string_append_printf(out, "~\\citep[");
734
+ }
735
+ print_latex_node(out, n->children, scratch);
736
+ g_string_append_printf(out, "]{%s}",temp);
737
+ } else {
738
+ #ifdef DEBUG_ON
739
+ fprintf(stderr, "cite without children. locat:'%s'\n",n->str);
740
+ #endif
741
+ if (strcmp(&temp[strlen(temp) - 1],";") == 0) {
742
+ temp[strlen(temp) - 1] = '\0';
743
+ g_string_append_printf(out, " \\citet{%s}",temp);
744
+ } else {
745
+ g_string_append_printf(out, "~\\citep{%s}",temp);
746
+ }
747
+ }
748
+ }
749
+ }
750
+ }
751
+ #ifdef DEBUG_ON
752
+ fprintf(stderr, "finish cite\n");
753
+ #endif
754
+ break;
755
+ case VARIABLE:
756
+ temp = metavalue_for_key(n->str,scratch->result_tree);
757
+ if (temp == NULL) {
758
+ g_string_append_printf(out, "[%%%s]",n->str);
759
+ } else {
760
+ print_latex_string(out, temp, scratch);
761
+ free(temp);
762
+ }
763
+ break;
764
+ case GLOSSARYTERM:
765
+ if ((n->next != NULL) && (n->next->key == GLOSSARYSORTKEY) ) {
766
+ g_string_append_printf(out, "sort={");
767
+ print_latex_string(out, n->next->str, scratch);
768
+ g_string_append_printf(out, "},");
769
+ }
770
+ g_string_append_printf(out,"name={");
771
+ print_latex_string(out, n->children->str, scratch);
772
+ g_string_append_printf(out, "},description={");
773
+ break;
774
+ case GLOSSARYSORTKEY:
775
+ break;
776
+ case CODE:
777
+ g_string_append_printf(out, "\\texttt{");
778
+ print_latex_string(out, n->str, scratch);
779
+ g_string_append_printf(out, "}");
780
+ break;
781
+ case BLOCKQUOTEMARKER:
782
+ print_latex_node_tree(out, n->children, scratch);
783
+ break;
784
+ case BLOCKQUOTE:
785
+ pad(out,2, scratch);
786
+ g_string_append_printf(out, "\\begin{quote}");
787
+ scratch->padded = 0;
788
+ print_latex_node_tree(out, n->children, scratch);
789
+ pad(out,1, scratch);
790
+ g_string_append_printf(out, "\\end{quote}");
791
+ scratch->padded = 0;
792
+ break;
793
+ case RAW:
794
+ /* This shouldn't happen */
795
+ g_string_append_printf(out, "RAW:");
796
+ g_string_append_printf(out,"%s",n->str);
797
+ break;
798
+ case HTML:
799
+ /* don't print HTML block */
800
+ /* but do print HTML comments for raw LaTeX */
801
+ if (strncmp(n->str,"<!--",4) == 0) {
802
+ /* trim "-->" from end */
803
+ n->str[strlen(n->str)-3] = '\0';
804
+ g_string_append_printf(out, "%s", &n->str[4]);
805
+ scratch->padded = 0;
806
+ }
807
+ break;
808
+ case DEFLIST:
809
+ pad(out,2, scratch);
810
+ g_string_append_printf(out, "\\begin{description}");
811
+ scratch->padded = 0;
812
+ print_latex_node_tree(out, n->children, scratch);
813
+ pad(out, 1, scratch);
814
+ g_string_append_printf(out, "\\end{description}");
815
+ scratch->padded = 0;
816
+ break;
817
+ case TERM:
818
+ pad(out,2, scratch);
819
+ g_string_append_printf(out, "\\item[");
820
+ print_latex_node_tree(out, n->children, scratch);
821
+ g_string_append_printf(out, "]");
822
+ scratch->padded = 0;
823
+ break;
824
+ case DEFINITION:
825
+ pad(out, 2, scratch);
826
+ scratch->padded = 2;
827
+ print_latex_node_tree(out, n->children, scratch);
828
+ scratch->padded = 0;
829
+ break;
830
+ case TABLE:
831
+ pad(out, 2, scratch);
832
+
833
+ if (!scratch->inside_footnote)
834
+ g_string_append_printf(out, "\\begin{table}[htbp]\n");
835
+
836
+ g_string_append_printf(out,"\\begin{minipage}{\\linewidth}\n\\setlength{\\tymax}{0.5\\linewidth}\n\\centering\n\\small\n");
837
+ print_latex_node_tree(out, n->children, scratch);
838
+
839
+ g_string_append_printf(out, "\n\\end{tabulary}\n\\end{minipage}");
840
+
841
+ if (!scratch->inside_footnote)
842
+ g_string_append_printf(out, "\n\\end{table}");
843
+
844
+ scratch->padded = 0;
845
+ break;
846
+ case TABLESEPARATOR:
847
+ temp_str = g_string_new("");
848
+ for (i = 0; n->str[i]; i++) {
849
+ if ((n->str[i] == 'N') || (n->str[i] == 'n')) {
850
+ g_string_append_printf(temp_str,"L");
851
+ } else if (n->str[i] != 'h') {
852
+ g_string_append_printf(temp_str,"%c",toupper(n->str[i]));
853
+ }
854
+ }
855
+ g_string_append_printf(out, "\\begin{tabulary}{\\textwidth}{@{}%s@{}} \\toprule\n", temp_str->str);
856
+
857
+ if (scratch->table_alignment != NULL)
858
+ free(scratch->table_alignment);
859
+
860
+ scratch->table_alignment = temp_str->str;
861
+ g_string_free(temp_str, false);
862
+ break;
863
+ case TABLECAPTION:
864
+ if ((n->children != NULL) && (n->children->key == TABLELABEL)) {
865
+ temp = label_from_string(n->children->str);
866
+ } else {
867
+ temp = label_from_node_tree(n->children);
868
+ }
869
+ g_string_append_printf(out, "\\caption{");
870
+ print_latex_node_tree(out, n->children, scratch);
871
+ g_string_append_printf(out, "}\n\\label{%s}\n", temp);
872
+ free(temp);
873
+ break;
874
+ case TABLELABEL:
875
+ break;
876
+ case TABLEHEAD:
877
+ print_latex_node_tree(out, n->children, scratch);
878
+ g_string_append_printf(out, "\\midrule\n");
879
+ break;
880
+ case TABLEBODY:
881
+ print_latex_node_tree(out, n->children, scratch);
882
+ if ((n->next != NULL) && (n->next->key == TABLEBODY)) {
883
+ g_string_append_printf(out, "\n\\midrule\n");
884
+ } else {
885
+ g_string_append_printf(out, "\n\\bottomrule\n");
886
+ }
887
+ break;
888
+ case TABLEROW:
889
+ print_latex_node_tree(out, n->children, scratch);
890
+ g_string_append_printf(out, "\\\\\n");
891
+ scratch->table_column = 0;
892
+ break;
893
+ case TABLECELL:
894
+ scratch->padded = 2;
895
+ temp = scratch->table_alignment;
896
+ if ((n->children != NULL) && (n->children->key == CELLSPAN)) {
897
+ g_string_append_printf(out, "\\multicolumn{%d}{%c}{",
898
+ (int)strlen(n->children->str)+1,tolower(temp[scratch->table_column]));
899
+ }
900
+ print_latex_node_tree(out, n->children, scratch);
901
+ if ((n->children != NULL) && (n->children->key == CELLSPAN)) {
902
+ g_string_append_printf(out, "}");
903
+ }
904
+ if (n->next != NULL)
905
+ g_string_append_printf(out, "&");
906
+ if ((n->children != NULL) && (n->children->key == CELLSPAN)) {
907
+ scratch->table_column += (int)strlen(n->children->str);
908
+ }
909
+ scratch->table_column++;
910
+ break;
911
+ case CELLSPAN:
912
+ break;
913
+ case GLOSSARYSOURCE:
914
+ if (scratch->printing_notes)
915
+ print_latex_node_tree(out, n->children, scratch);
916
+ break;
917
+ case CITATIONSOURCE:
918
+ case NOTESOURCE:
919
+ if (scratch->printing_notes)
920
+ print_latex_node(out, n->children, scratch);
921
+ break;
922
+ case SOURCEBRANCH:
923
+ fprintf(stderr,"SOURCEBRANCH\n");
924
+ break;
925
+ case NOTELABEL:
926
+ case GLOSSARYLABEL:
927
+ break;
928
+ case SUPERSCRIPT:
929
+ g_string_append_printf(out, "\\textsuperscript{%s}",n->str);
930
+ break;
931
+ case SUBSCRIPT:
932
+ g_string_append_printf(out, "\\textsubscript{%s}",n->str);
933
+ break;
934
+ case KEY_COUNTER:
935
+ break;
936
+ case TOC:
937
+ print_latex_node_tree(out,n->children, scratch);
938
+ break;
939
+ default:
940
+ fprintf(stderr, "print_latex_node encountered unknown node key = %d\n",n->key);
941
+ exit(EXIT_FAILURE);
942
+ }
943
+ }
944
+
945
+ /* print_latex_endnotes */
946
+ void print_latex_endnotes(GString *out, scratch_pad *scratch) {
947
+ scratch->used_notes = reverse_list(scratch->used_notes);
948
+ scratch->printing_notes = 1;
949
+
950
+ node *note = scratch->used_notes;
951
+ #ifdef DEBUG_ON
952
+ fprintf(stderr, "start endnotes\n");
953
+ #endif
954
+
955
+ if ((note == NULL) || ((note->key == KEY_COUNTER) && (note->next == NULL)))
956
+ return;
957
+ while (note != NULL) {
958
+ if (note->key == CITATIONSOURCE)
959
+ break;
960
+ note = note->next;
961
+ }
962
+
963
+ if (note == NULL)
964
+ return;
965
+
966
+ note = scratch->used_notes;
967
+
968
+ /* TODO: need CITATIONSOURCE to print bibliography */
969
+ #ifdef DEBUG_ON
970
+ fprintf(stderr, "there are endnotes to print\n");
971
+ #endif
972
+
973
+ pad(out, 2, scratch);
974
+ g_string_append_printf(out, "\\begin{thebibliography}{0}");
975
+ while ( note != NULL) {
976
+ if (note->key == KEY_COUNTER) {
977
+ note = note->next;
978
+ continue;
979
+ }
980
+
981
+ pad(out, 1, scratch);
982
+
983
+ if (note->key == CITATIONSOURCE) {
984
+ g_string_append_printf(out, "\\bibitem{%s}\n", note->str);
985
+ scratch->padded = 2;
986
+
987
+ print_latex_node(out, note, scratch);
988
+ pad(out, 1, scratch);
989
+ scratch->padded = 1;
990
+ } else {
991
+ /* footnotes handled elsewhere */
992
+ }
993
+
994
+ note = note->next;
995
+ }
996
+ pad(out,2, scratch);
997
+ g_string_append_printf(out, "\\end{thebibliography}");
998
+ scratch->padded = 0;
999
+ #ifdef DEBUG_ON
1000
+ fprintf(stderr, "finish endnotes\n");
1001
+ #endif
1002
+ }
1003
+
1004
+ /* Check metadata keys and determine if we need a complete document */
1005
+ /* We also preconvert metadata keys to proper formatting -- lowercase with no spaces */
1006
+ bool is_latex_complete_doc(node *meta) {
1007
+ node *step;
1008
+ char *temp;
1009
+ step = meta->children;
1010
+
1011
+ while (step != NULL) {
1012
+ /* process key to proper label */
1013
+ temp = step->str; /* store pointer to original str */
1014
+ step->str = label_from_string(step->str);
1015
+ free(temp); /* free original since we don't need it */
1016
+ step = step->next;
1017
+ }
1018
+
1019
+ step = meta->children;
1020
+ while (step != NULL) {
1021
+ /* the following types of metadata do not require a complete document */
1022
+ if ((strcmp(step->str, "baseheaderlevel") != 0) &&
1023
+ (strcmp(step->str, "xhtmlheaderlevel") != 0) &&
1024
+ (strcmp(step->str, "htmlheaderlevel") != 0) &&
1025
+ (strcmp(step->str, "latexheaderlevel") != 0) &&
1026
+ (strcmp(step->str, "odfheaderlevel") != 0) &&
1027
+ (strcmp(step->str, "xhtmlheader") != 0) &&
1028
+ (strcmp(step->str, "htmlheader") != 0) &&
1029
+ (strcmp(step->str, "quoteslanguage") != 0))
1030
+ { return TRUE;}
1031
+ step = step->next;
1032
+ }
1033
+
1034
+ return FALSE;
1035
+ }
1036
+
1037
+ /* print_latex_localized_typography -- convert to "smart" typography */
1038
+ void print_latex_localized_typography(GString *out, int character, scratch_pad *scratch) {
1039
+ if (!extension(EXT_SMART, scratch->extensions)) {
1040
+ g_string_append_c(out, character);
1041
+ return;
1042
+ }
1043
+ switch (character) {
1044
+ case LSQUOTE:
1045
+ switch (scratch->language) {
1046
+ case SWEDISH:
1047
+ g_string_append_printf(out, "'");
1048
+ break;
1049
+ case FRENCH:
1050
+ g_string_append_printf(out,"'");
1051
+ break;
1052
+ case GERMAN:
1053
+ g_string_append_printf(out,"‚");
1054
+ break;
1055
+ case GERMANGUILL:
1056
+ g_string_append_printf(out,"›");
1057
+ break;
1058
+ default:
1059
+ g_string_append_printf(out,"`");
1060
+ }
1061
+ break;
1062
+ case RSQUOTE:
1063
+ switch (scratch->language) {
1064
+ case GERMAN:
1065
+ g_string_append_printf(out,"`");
1066
+ break;
1067
+ case GERMANGUILL:
1068
+ g_string_append_printf(out,"‹");
1069
+ break;
1070
+ default:
1071
+ g_string_append_printf(out,"'");
1072
+ }
1073
+ break;
1074
+ case APOS:
1075
+ g_string_append_printf(out,"'");
1076
+ break;
1077
+ case LDQUOTE:
1078
+ switch (scratch->language) {
1079
+ case DUTCH:
1080
+ case GERMAN:
1081
+ g_string_append_printf(out,"„");
1082
+ break;
1083
+ case GERMANGUILL:
1084
+ g_string_append_printf(out,"»");
1085
+ break;
1086
+ case FRENCH:
1087
+ g_string_append_printf(out,"«");
1088
+ break;
1089
+ case SWEDISH:
1090
+ g_string_append_printf(out, "''");
1091
+ break;
1092
+ default:
1093
+ g_string_append_printf(out,"``");
1094
+ }
1095
+ break;
1096
+ case RDQUOTE:
1097
+ switch (scratch->language) {
1098
+ case SWEDISH:
1099
+ case DUTCH:
1100
+ g_string_append_printf(out,"''");
1101
+ break;
1102
+ case GERMAN:
1103
+ g_string_append_printf(out,"``");
1104
+ break;
1105
+ case GERMANGUILL:
1106
+ g_string_append_printf(out,"«");
1107
+ break;
1108
+ case FRENCH:
1109
+ g_string_append_printf(out,"»");
1110
+ break;
1111
+ default:
1112
+ g_string_append_printf(out,"''");
1113
+ }
1114
+ break;
1115
+ case NDASH:
1116
+ g_string_append_printf(out,"--");
1117
+ break;
1118
+ case MDASH:
1119
+ g_string_append_printf(out,"---");
1120
+ break;
1121
+ case ELLIP:
1122
+ g_string_append_printf(out,"{\\ldots}");
1123
+ break;
1124
+ default:;
1125
+ }
1126
+ }
1127
+
1128
+ /* print_latex_string - print string, escaping for LaTeX */
1129
+ void print_latex_string(GString *out, char *str, scratch_pad *scratch) {
1130
+ char *tmp;
1131
+ char *start;
1132
+ if (str == NULL)
1133
+ return;
1134
+ start = str; /* Store start of string */
1135
+ while (*str != '\0') {
1136
+ switch (*str) {
1137
+ case '{': case '}': case '$': case '%':
1138
+ case '&': case '_': case '#':
1139
+ g_string_append_printf(out, "\\%c", *str);
1140
+ break;
1141
+ case '^':
1142
+ g_string_append_printf(out, "\\^{}");
1143
+ break;
1144
+ case '\\':
1145
+ g_string_append_printf(out, "\\textbackslash{}");
1146
+ break;
1147
+ case '~':
1148
+ g_string_append_printf(out, "\\ensuremath{\\sim}");
1149
+ break;
1150
+ case '|':
1151
+ g_string_append_printf(out, "\\textbar{}");
1152
+ break;
1153
+ case '<':
1154
+ g_string_append_printf(out, "$<$");
1155
+ break;
1156
+ case '>':
1157
+ g_string_append_printf(out, "$>$");
1158
+ break;
1159
+ case '/':
1160
+ str++;
1161
+ while (*str == '/') {
1162
+ g_string_append_printf(out, "/");
1163
+ str++;
1164
+ }
1165
+ g_string_append_printf(out, "\\slash ");
1166
+ str--;
1167
+ break;
1168
+ case '\n':
1169
+ tmp = str;
1170
+ tmp--;
1171
+ if ((tmp > start) && (*tmp == ' ')) {
1172
+ tmp--;
1173
+ if (*tmp == ' ') {
1174
+ g_string_append_printf(out, "\\\\\n");
1175
+ } else {
1176
+ g_string_append_printf(out, "\n");
1177
+ }
1178
+ } else {
1179
+ g_string_append_printf(out, "\n");
1180
+ }
1181
+ break;
1182
+ case '-':
1183
+ str++;
1184
+ if (*str == '-') {
1185
+ g_string_append_printf(out, "-{}");
1186
+ str--;
1187
+ } else {
1188
+ str--;
1189
+ g_string_append_c(out,*str);
1190
+ }
1191
+ break;
1192
+ default:
1193
+ g_string_append_c(out, *str);
1194
+ }
1195
+ str++;
1196
+ }
1197
+ }
1198
+
1199
+ /* print_latex_url - print url, escaping for LaTeX */
1200
+ void print_latex_url(GString *out, char *str, scratch_pad *scratch) {
1201
+ if (str == NULL)
1202
+ return;
1203
+ while (*str != '\0') {
1204
+ switch (*str) {
1205
+ case '$': case '%': case '!':
1206
+ case '&': case '_': case '#':
1207
+ g_string_append_printf(out, "\\%c", *str);
1208
+ break;
1209
+ case '^':
1210
+ g_string_append_printf(out, "\\^{}");
1211
+ break;
1212
+ default:
1213
+ g_string_append_c(out, *str);
1214
+ }
1215
+ str++;
1216
+ }
1217
+ }
1218
+
1219
+ char * correct_dimension_units(char *original) {
1220
+ char *result;
1221
+ int i;
1222
+
1223
+ result = strdup(original);
1224
+
1225
+ for (i = 0; result[i]; i++)
1226
+ result[i] = tolower(result[i]);
1227
+
1228
+ if (strstr(&result[strlen(result)-2],"px")) {
1229
+ result[strlen(result)-2] = '\0';
1230
+ strcat(result, "pt");
1231
+ }
1232
+
1233
+ return result;
1234
+ }