]> granicus.if.org Git - multimarkdown/commitdiff
ADDED: Support metadata in LaTeX
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Mon, 13 Feb 2017 20:20:07 +0000 (15:20 -0500)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Mon, 13 Feb 2017 20:20:07 +0000 (15:20 -0500)
src/latex.c
tests/MMD6Tests/Metadata.tex [new file with mode: 0644]
tests/MMD6Tests/Variables.tex [new file with mode: 0644]

index 7d8e02de1108cf18dfd64f40f208a08d1b36ac87..39e27d72c74a3babfdafd3c5e873a941290a7a62 100644 (file)
@@ -1361,12 +1361,67 @@ void mmd_export_token_tree_latex_tt(DString * out, const char * source, token *
 
 
 void mmd_start_complete_latex(DString * out, const char * source, scratch_pad * scratch) {
-
+       // Iterate over metadata keys
+       meta * m;
+
+       for (m = scratch->meta_hash; m != NULL; m = m->hh.next) {
+               if (strcmp(m->key, "baseheaderlevel") == 0) {
+               } else if (strcmp(m->key, "bibtex") == 0) {
+               } else if (strcmp(m->key, "css") == 0) {
+               } else if (strcmp(m->key, "htmlfooter") == 0) {
+               } else if (strcmp(m->key, "htmlheader") == 0) {
+               } else if (strcmp(m->key, "htmlheaderlevel") == 0) {
+               } else if (strcmp(m->key, "lang") == 0) {
+               } else if (strcmp(m->key, "latexheader") == 0) {
+                       print(m->value);
+                       print_char('\n');
+               } else if (strcmp(m->key, "latexfooter") == 0) {
+               } else if (strcmp(m->key, "latexinput") == 0) {
+               } else if (strcmp(m->key, "latexmode") == 0) {
+               } else if (strcmp(m->key, "mmdfooter") == 0) {
+               } else if (strcmp(m->key, "mmdheader") == 0) {
+               } else if (strcmp(m->key, "quoteslanguage") == 0) {
+               } else if ((strcmp(m->key, "title") == 0) ||
+                       (strcmp(m->key, "latextitle") == 0)) {
+                       print("\\def\\mytitle{");
+                       mmd_print_string_latex(out, m->value);
+                       print("}\n");
+               } else if ((strcmp(m->key, "author") == 0) ||
+                       (strcmp(m->key, "latexauthor") == 0)) {
+                       print("\\def\\myauthor{");
+                       mmd_print_string_latex(out, m->value);
+                       print("}\n");
+               } else if (strcmp(m->key, "date") == 0) {
+                       print("\\def\\mydate{");
+                       mmd_print_string_latex(out, m->value);
+                       print("}\n");
+               } else if (strcmp(m->key, "copyright") == 0) {
+                       print("\\def\\mycopyright{");
+                       mmd_print_string_latex(out, m->value);
+                       print("}\n");
+               } else if (strcmp(m->key, "bibtex") == 0) {
+                       print("\\def\\bibliocommand{\\bibliography{");
+                       mmd_print_string_latex(out, m->value);
+                       print("}}\n");
+               } else if (strcmp(m->key, "transcludebase") == 0) {
+               } else if (strcmp(m->key, "xhtmlheader") == 0) {
+               } else if (strcmp(m->key, "xhtmlheaderlevel") == 0) {
+               } else {
+                       print("\\def\\");
+                       mmd_print_string_latex(out, m->key);
+                       print("{");
+                       mmd_print_string_latex(out, m->value);
+                       print("}\n");
+               }
+       }
+       scratch->padded = 1;
 }
 
 
 void mmd_end_complete_latex(DString * out, const char * source, scratch_pad * scratch) {
-
+       pad(out, 2, scratch);
+       print("\\end{document}");
+       scratch->padded = 0;
 }
 
 void mmd_export_citation_list_latex(DString * out, const char * source, scratch_pad * scratch) {
diff --git a/tests/MMD6Tests/Metadata.tex b/tests/MMD6Tests/Metadata.tex
new file mode 100644 (file)
index 0000000..25a16f5
--- /dev/null
@@ -0,0 +1,9 @@
+\def\mytitle{*foo* "bar"}
+\def\foo{bar foo bar foo bar}
+
+foo:   bar
+
+\section{foo }
+\label{foo}
+
+\end{document}
diff --git a/tests/MMD6Tests/Variables.tex b/tests/MMD6Tests/Variables.tex
new file mode 100644 (file)
index 0000000..373ae5b
--- /dev/null
@@ -0,0 +1,12 @@
+\def\foo{bar foo bar foo bar}
+\def\bat{**foo**}
+
+foo:   bar
+
+bar foo bar foo bar
+
+[%bar]
+
+**foo**
+
+\end{document}