From d6c4dcc0ee3f4349145302d1a64b4929d9716949 Mon Sep 17 00:00:00 2001 From: "Fletcher T. Penney" Date: Sun, 12 Feb 2017 15:12:06 -0500 Subject: [PATCH] ADDED: Add basic image support to LaTeX --- src/latex.c | 67 ++++++++++++++++--------------- tests/MMD6Tests/Figure Images.tex | 21 ++++++++++ tests/MMD6Tests/Inline Images.tex | 27 +++++++++++++ 3 files changed, 82 insertions(+), 33 deletions(-) create mode 100644 tests/MMD6Tests/Figure Images.tex create mode 100644 tests/MMD6Tests/Inline Images.tex diff --git a/src/latex.c b/src/latex.c index 1d04073..4c17458 100644 --- a/src/latex.c +++ b/src/latex.c @@ -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

markers - d_string_erase(out, out->currentStringLength - 3, 3); - print("

\n"); + print("\\begin{figure}[htbp]\n\\centering\n"); scratch->close_para = false; } - if (link->url) - printf("url); - else - print("\"");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
"); + print("\\caption{"); mmd_export_token_tree_latex(out, source, text->child, scratch); - print("
"); + print("}\n"); } - print("\n
"); + 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 index 0000000..497b7c2 --- /dev/null +++ b/tests/MMD6Tests/Figure Images.tex @@ -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 index 0000000..61f2a56 --- /dev/null +++ b/tests/MMD6Tests/Inline Images.tex @@ -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/}. -- 2.40.0