]> granicus.if.org Git - multimarkdown/commitdiff
ADDED: Add basic image support to LaTeX
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Sun, 12 Feb 2017 20:12:06 +0000 (15:12 -0500)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Sun, 12 Feb 2017 20:12:06 +0000 (15:12 -0500)
src/latex.c
tests/MMD6Tests/Figure Images.tex [new file with mode: 0644]
tests/MMD6Tests/Inline Images.tex [new file with mode: 0644]

index 1d04073eec095e1af524c3b0367cd1ed2397dc97..4c17458dae25fefcd971a0eff9f2be4f1ba1ea0f 100644 (file)
@@ -251,51 +251,52 @@ void mmd_export_image_latex(DString * out, const char * source, token * text, li
                is_figure = false;
 
        if (is_figure) {
-               // Remove wrapping <p> markers
-               d_string_erase(out, out->currentStringLength - 3, 3);
-               print("<figure>\n");
+               print("\\begin{figure}[htbp]\n\\centering\n");
                scratch->close_para = false;
        }
 
-       if (link->url)
-               printf("<img src=\"%s\"", link->url);
-       else
-               print("<img src=\"\"");
+       print("\\includegraphics[keepaspectratio");
 
-       if (text) {
-               print(" alt=\"");
-               print_token_tree_raw(out, source, text->child);
-               print("\"");
-       }
-
-       if (link->label && !(scratch->extensions & EXT_COMPATIBILITY)) {
-               // \todo: Need to decide on approach to id's
-               char * label = label_from_token(source, link->label);
-               printf(" id=\"%s\"", label);
-               free(label);
-       }
+//     if (text) {
+//             print(" alt=\"");
+//             print_token_tree_raw(out, source, text->child);
+//             print("\"");
+//     }
+//
+//     if (link->title && link->title[0] != '\0')
+//             printf(" title=\"%s\"", link->title);
+//
+//     while (a) {
+//             print(" ");
+//             print(a->key);
+//             print("=\"");
+//             print(a->value);
+//             print("\"");
+//             a = a->next;
+//     }
 
-       if (link->title && link->title[0] != '\0')
-               printf(" title=\"%s\"", link->title);
 
-       while (a) {
-               print(" ");
-               print(a->key);
-               print("=\"");
-               print(a->value);
-               print("\"");
-               a = a->next;
-       }
+       if (link->url)
+               printf("]{%s}", link->url);
+       else
+               print("]{}");
 
-       print(" />");
 
        if (is_figure) {
+               print("\n");
                if (text) {
-                       print("\n<figcaption>");
+                       print("\\caption{");
                        mmd_export_token_tree_latex(out, source, text->child, scratch);
-                       print("</figcaption>");
+                       print("}\n");
                }
-               print("\n</figure>");
+               if (link->label) {
+                       // \todo: Need to decide on approach to id's
+                       char * label = label_from_token(source, link->label);
+                       printf("\\label{%s}\n", label);
+                       free(label);
+               }
+
+               print("\\end{figure}");
        }
 }
 
diff --git a/tests/MMD6Tests/Figure Images.tex b/tests/MMD6Tests/Figure Images.tex
new file mode 100644 (file)
index 0000000..497b7c2
--- /dev/null
@@ -0,0 +1,21 @@
+\begin{figure}[htbp]
+\centering
+\includegraphics[keepaspectratio,width=40pt,height=0.75\textheight]{http://foo.bar/}
+\caption{foo}
+\label{foo}
+\end{figure}
+
+\begin{figure}[htbp]
+\centering
+\includegraphics[keepaspectratio,width=40pt,height=0.75\textheight]{http://foo.bar/}
+\caption{\emph{bar}}
+\label{foo}
+\end{figure}
+
+\includegraphics[keepaspectratio,width=40pt,height=0.75\textheight]{http://foo.bar/} bar
+
+\begin{figure}[htbp]
+\centering
+\includegraphics[keepaspectratio,width=\textwidth,height=0.75\textheight]{http://foo.bar/}
+\caption{\emph{foo}}
+\end{figure}
diff --git a/tests/MMD6Tests/Inline Images.tex b/tests/MMD6Tests/Inline Images.tex
new file mode 100644 (file)
index 0000000..61f2a56
--- /dev/null
@@ -0,0 +1,27 @@
+Just a \includegraphics[keepaspectratio,width=\textwidth,height=0.75\textheight]{/url/}.
+
+\includegraphics[keepaspectratio,width=\textwidth,height=0.75\textheight]{/url/}.
+
+\includegraphics[keepaspectratio,width=\textwidth,height=0.75\textheight]{/url/}.
+
+\includegraphics[keepaspectratio,width=\textwidth,height=0.75\textheight]{/url/}.
+
+\includegraphics[keepaspectratio,width=\textwidth,height=0.75\textheight]{/url/}.
+
+5
+
+\href{}{Empty}\footnote{\href{}{}}.
+
+\includegraphics[keepaspectratio,width=\textwidth,height=0.75\textheight]{/url/}.
+
+\includegraphics[keepaspectratio,width=\textwidth,height=0.75\textheight]{/url/}.
+
+\includegraphics[keepaspectratio,width=\textwidth,height=0.75\textheight]{/url/}.
+
+\includegraphics[keepaspectratio,width=\textwidth,height=0.75\textheight]{/url/}.
+
+10
+
+\includegraphics[keepaspectratio,width=\textwidth,height=0.75\textheight]{/url/}.
+
+\includegraphics[keepaspectratio,width=\textwidth,height=0.75\textheight]{/url/}.