citation_from_bracket(source, scratch, t, &temp_short);
if (temp_bool) {
- if (temp_short < scratch->used_citations->size) {
- // Re-using previous citation
- printf("<a href=\"#cn:%d\" title=\"%s\" class=\"citation\">[%s%s%d]</a>",
- temp_short, LC("see citation"), temp_char, temp_char2, temp_short);
- } else {
- // This is a new citation
- printf("<a href=\"#cn:%d\" id=\"cnref:%d\" title=\"%s\" class=\"citation\">[%s%s%d]</a>",
- temp_short, temp_short, LC("see citation"), temp_char, temp_char2, temp_short);
- }
+ // This is a new citation
+ temp_short = scratch->used_citations->size;
+ printf("<a href=\"#cn:%d\" id=\"cnref:%d\" title=\"%s\" class=\"citation\">[%s%s%d]</a>",
+ temp_short, temp_short, LC("see citation"), temp_char, temp_char2, temp_short);
}
if (t->prev && (t->prev->type == PAIR_BRACKET)) {
break;
case PAIR_BRACKET_CITATION:
parse_citation:
- temp_bool = true;
-
- if (t->type == PAIR_BRACKET) {
- // This is a locator for subsequent citation
- temp_char = text_inside_pair(source, t);
- temp_char2 = label_from_string(temp_char);
-
- if (strcmp(temp_char2, "notcited") == 0) {
- free(temp_char2);
- free(temp_char);
- temp_char = strdup("");
- temp_bool = false;
- }
-
- if (temp_char[0] == '\0')
- temp_char2 = strdup("");
- else
- temp_char2 = strdup(", ");
-
-
- // Process the actual citation
- t = t->next;
- } else {
- temp_char = strdup("");
- temp_char2 = strdup("");
- }
-
- if (scratch->extensions & EXT_NOTES) {
+ temp_bool = true; // Track whether this is a 'not cited'
+ temp_token = t; // Remember whether we need to skip ahead
+
+ if (scratch->extensions & EXT_NOTES) {
+ if (t->type == PAIR_BRACKET) {
+ // This is a locator for subsequent citation (e.g. `[foo][#bar]`
+ temp_char = text_inside_pair(source, t);
+ temp_char2 = label_from_string(temp_char);
+
+ if (strcmp(temp_char2, "notcited") == 0) {
+ free(temp_char);
+ temp_char = strdup("");
+ temp_bool = false;
+ }
+
+ free(temp_char2);
+
+ // Process the actual citation
+ t = t->next;
+ } else {
+ // This is just a citation (e.g. `[#foo]`)
+ temp_char = strdup("");
+ }
+
+ // See if we're a citep or cite
+ temp_char2 = clean_inside_pair(source, t, false);
+
citation_from_bracket(source, scratch, t, &temp_short);
- if (temp_bool) {
- if (temp_short < scratch->used_citations->size) {
- // Re-using previous citation
- printf("\\citation{reuse");
+ temp_note = stack_peek_index(scratch->used_citations, temp_short - 1);
- printf("}");
+ if (temp_bool) {
+ // This is not a "not cited"
+ if (temp_char[0] == '\0') {
+ if (temp_char2[strlen(temp_char2) - 1] == ';') {
+ print("\\citet");
+ } else {
+ print("~\\citep");
+ }
} else {
- // This is a new citation
- printf("\\citation{");
-
- printf("}");
+ if (temp_char2[strlen(temp_char2) - 1] == ';') {
+ printf("\\citet[%s]", temp_char);
+ } else {
+ printf("~\\citep[%s]", temp_char);
+ }
}
+
+ printf("{%s}", temp_note->label_text);
+ } else {
+ // This is a "nocite"
+ printf("~\\nocite{%s}",temp_note->label_text);
}
- if (t->prev && (t->prev->type == PAIR_BRACKET)) {
+ if (temp_token != t) {
// Skip citation on next pass
scratch->skip_token = 1;
}
}
+void mmd_export_citation_list_latex(DString * out, const char * source, scratch_pad * scratch) {
+ if (scratch->used_citations->size > 0) {
+ footnote * note;
+ token * content;
+
+ pad(out, 2, scratch);
+ print("\\begin{thebibliography}{0}");
+ scratch->padded = 0;
+
+ for (int i = 0; i < scratch->used_citations->size; ++i)
+ {
+ // Export footnote
+ pad(out, 2, scratch);
+
+ note = stack_peek_index(scratch->used_citations, i);
+ content = note->content;
+
+ printf("\\bibitem{%s}\n", note->label_text);
+ scratch->padded = 6;
+
+ scratch->footnote_para_counter = 0;
+
+ content = note->content;
+ scratch->citation_being_printed = i + 1;
+
+ mmd_export_token_tree_latex(out, source, content, scratch);
+ }
+
+ pad(out, 1, scratch);
+ print("\\end{thebibliography}");
+ scratch->padded = 0;
+ scratch->citation_being_printed = 0;
+ }
+}
void mmd_start_complete_latex(DString * out, const char * source, scratch_pad * scratch);
void mmd_end_complete_latex(DString * out, const char * source, scratch_pad * scratch);
+void mmd_export_citation_list_latex(DString * out, const char * source, scratch_pad * scratch);
+
#endif
mmd_start_complete_latex(out, e->dstr->str, scratch);
mmd_export_token_tree_latex(out, e->dstr->str, e->root, scratch);
+ mmd_export_citation_list_latex(out, e->dstr->str, scratch);
if (scratch->extensions & EXT_COMPLETE)
mmd_end_complete_latex(out, e->dstr->str, scratch);
free(text);
if (citation_id == -1) {
- // No match, this is an inline footnote -- create a new one
+ // No match, this is an inline citation -- create a new one
t->child->type = TEXT_EMPTY;
t->child->mate->type = TEXT_EMPTY;
- // Create footnote
- footnote * temp = footnote_new(source, NULL, t->child);
+ // Create citation
+ footnote * temp = footnote_new(source, t, t->child);
// Store as used
stack_push(scratch->used_citations, temp);
link * extract_link_from_stack(scratch_pad * scratch, const char * target);
char * text_inside_pair(const char * source, token * pair);
+char * clean_inside_pair(const char * source, token * t, bool lowercase);
void link_free(link * l);
void footnote_free(footnote * f);
+<h1 id="citep">citep </h1>
+
<p><a href="#cn:1" id="cnref:1" title="see citation" class="citation">[1]</a></p>
-<p><a href="#cn:1" id="cnref:1" title="see citation" class="citation">[p. 123, 1]</a></p>
+<p><a href="#cn:1" title="see citation" class="citation">[1]</a>[]</p>
-<p><a href="#cn:1" id="cnref:1" title="see citation" class="citation">[1]</a></p>
+<p><a href="#cn:1" title="see citation" class="citation">[p. 123, 1]</a></p>
+
+<p><a href="#cn:1" title="see citation" class="citation">[1]</a></p>
+
+<p><a href="#cn:1" title="see citation" class="citation">[foo\]\[bar, 1]</a></p>
+
+<p><a href="#cn:1" title="see citation" class="citation">[1]</a><a href="#cn:2" id="cnref:2" title="see citation" class="citation">[2]</a></p>
+
+<h1 id="citet">citet </h1>
+
+<p><a href="#cn:1" title="see citation" class="citation">[1]</a></p>
+
+<p><a href="#cn:1" title="see citation" class="citation">[1]</a>[]</p>
+
+<p><a href="#cn:1" title="see citation" class="citation">[p. 123, 1]</a></p>
+
+<p><a href="#cn:1" title="see citation" class="citation">[1]</a></p>
+
+<p><a href="#cn:1" title="see citation" class="citation">[foo\]\[bar, 1]</a></p>
+
+<p><a href="#cn:1" title="see citation" class="citation">[1]</a><a href="#cn:2" title="see citation" class="citation">[2]</a></p>
<p></p>
+<h1>citep </h1>
+
<p>[#foo1]</p>
+<p>[#foo1][]</p>
+
<p>[p. 123][#foo1]</p>
<p>[][#foo1]</p>
+<p>[foo][bar][#foo1]</p>
+
+<p>[#foo1][#foo2]</p>
+
+<h1>citet </h1>
+
+<p>[#foo1;]</p>
+
+<p>[#foo1;][]</p>
+
+<p>[p. 123][#foo1;]</p>
+
+<p>[][#foo1;]</p>
+
+<p>[foo][bar][#foo1;]</p>
+
+<p>[#foo1;][#foo2;]</p>
+
<p>[Not Cited][#foo2]</p>
<p>[#foo1]: John Doe. <em>A Totally Fake Book</em>. Vanity Press, 2006.</p>
--- /dev/null
+\part{citep }
+\label{citep}
+
+~\citep{foo1}
+
+~\citep{foo1}
+
+~\citep[p. 123]{foo1}
+
+~\citep{foo1}
+
+~\citep[foo][bar]{foo1}
+
+~\citep{foo1}~\citep{foo2}
+
+\part{citet }
+\label{citet}
+
+\citet{foo1}
+
+\citet{foo1}
+
+\citet[p. 123]{foo1}
+
+\citet{foo1}
+
+\citet[foo][bar]{foo1}
+
+\citet{foo1}\citet{foo2}
+
+~\nocite{foo2}
+
+\begin{thebibliography}{0}
+
+\bibitem{foo1}
+John Doe. \emph{A Totally Fake Book}. Vanity Press, 2006.
+
+\bibitem{foo2}
+John Doe. \emph{A Totally Fake Book}. Vanity Press, 2006.
+
+\end{thebibliography}
+# citep #
+
[#foo1]
+[#foo1][]
+
[p. 123][#foo1]
[][#foo1]
+[foo\]\[bar][#foo1]
+
+[#foo1][#foo2]
+
+
+# citet #
+
+[#foo1;]
+
+[#foo1;][]
+
+[p. 123][#foo1;]
+
+[][#foo1;]
+
+[foo\]\[bar][#foo1;]
+
+[#foo1;][#foo2;]
+
+
[Not Cited][#foo2]
[#foo1]: John Doe. *A Totally Fake Book*. Vanity Press, 2006.
<ol>
<li id="cn:1">
-<p>bar <a href="#cnref:1" title="return to body" class="reversecitation"> ↩</a></p>
+<p>foo <a href="#cnref:1" title="return to body" class="reversecitation"> ↩</a></p>
</li>
</ol>
<p>[^foo]</p>
-<p>[#bar]</p>
+<p><a href="foo">#bar</a></p>
--- /dev/null
+`foo'
+
+„foo''
+
+foo's
+
+foo --- bar
+
+foo -- bar
+
+5
+
+foo{\ldots}
+
+\footnote{foo}
+
+~\citep{bar}
+
+\begin{thebibliography}{0}
+
+\bibitem{bar}
+foo
+\end{thebibliography}
[^foo]
[#bar]
+
+[#bar]: foo
<ol>
<li id="cn:1">
-<p>bar <a href="#cnref:1" title="return to body" class="reversecitation"> ↩</a></p>
+<p>foo <a href="#cnref:1" title="return to body" class="reversecitation"> ↩</a></p>
</li>
</ol>
<p>[^foo]</p>
-<p>[#bar]</p>
+<p><a href="foo">#bar</a></p>
--- /dev/null
+`foo'
+
+``foo''
+
+foo's
+
+foo --- bar
+
+foo -- bar
+
+5
+
+foo{\ldots}
+
+\footnote{foo}
+
+~\citep{bar}
+
+\begin{thebibliography}{0}
+
+\bibitem{bar}
+foo
+\end{thebibliography}
[^foo]
[#bar]
+
+[#bar]: foo
<ol>
<li id="cn:1">
-<p>bar <a href="#cnref:1" title="return to body" class="reversecitation"> ↩</a></p>
+<p>foo <a href="#cnref:1" title="return to body" class="reversecitation"> ↩</a></p>
</li>
</ol>
<p>[^foo]</p>
-<p>[#bar]</p>
+<p><a href="foo">#bar</a></p>
--- /dev/null
+'foo'
+
+«foo»
+
+foo's
+
+foo --- bar
+
+foo -- bar
+
+5
+
+foo{\ldots}
+
+\footnote{foo}
+
+~\citep{bar}
+
+\begin{thebibliography}{0}
+
+\bibitem{bar}
+foo
+\end{thebibliography}
[^foo]
[#bar]
+
+[#bar]: foo
<p>foo…</p>
-<p><a href="#fn:1" id="fnref:1" title="siehe Fußnote" class="footnote">[1]</a></p>
+<p><a href="#fn:1" id="fnref:1" title="see footnote" class="footnote">[1]</a></p>
-<p><a href="#cn:1" id="cnref:1" title="siehe Zitat" class="citation">[1]</a></p>
+<p><a href="#cn:1" id="cnref:1" title="see citation" class="citation">[1]</a></p>
<div class="footnotes">
<hr />
<ol>
<li id="fn:1">
-<p>foo <a href="#fnref:1" title="zum Haupttext" class="reversefootnote"> ↩</a></p>
+<p>foo <a href="#fnref:1" title="return to body" class="reversefootnote"> ↩</a></p>
</li>
</ol>
<ol>
<li id="cn:1">
-<p>bar <a href="#cnref:1" title="zum Haupttext" class="reversecitation"> ↩</a></p>
+<p>foo <a href="#cnref:1" title="return to body" class="reversecitation"> ↩</a></p>
</li>
</ol>
<p>[^foo]</p>
-<p>[#bar]</p>
+<p><a href="foo">#bar</a></p>
--- /dev/null
+›foo‹
+
+»foo«
+
+foo's
+
+foo --- bar
+
+foo -- bar
+
+5
+
+foo{\ldots}
+
+\footnote{foo}
+
+~\citep{bar}
+
+\begin{thebibliography}{0}
+
+\bibitem{bar}
+foo
+\end{thebibliography}
[^foo]
[#bar]
+
+[#bar]: foo
<p>foo…</p>
-<p><a href="#fn:1" id="fnref:1" title="siehe Fußnote" class="footnote">[1]</a></p>
+<p><a href="#fn:1" id="fnref:1" title="see footnote" class="footnote">[1]</a></p>
-<p><a href="#cn:1" id="cnref:1" title="siehe Zitat" class="citation">[1]</a></p>
+<p><a href="#cn:1" id="cnref:1" title="see citation" class="citation">[1]</a></p>
<div class="footnotes">
<hr />
<ol>
<li id="fn:1">
-<p>foo <a href="#fnref:1" title="zum Haupttext" class="reversefootnote"> ↩</a></p>
+<p>foo <a href="#fnref:1" title="return to body" class="reversefootnote"> ↩</a></p>
</li>
</ol>
<ol>
<li id="cn:1">
-<p>bar <a href="#cnref:1" title="zum Haupttext" class="reversecitation"> ↩</a></p>
+<p>foo <a href="#cnref:1" title="return to body" class="reversecitation"> ↩</a></p>
</li>
</ol>
<p>[^foo]</p>
-<p>[#bar]</p>
+<p><a href="foo">#bar</a></p>
--- /dev/null
+‚foo`
+
+„foo``
+
+foo's
+
+foo --- bar
+
+foo -- bar
+
+5
+
+foo{\ldots}
+
+\footnote{foo}
+
+~\citep{bar}
+
+\begin{thebibliography}{0}
+
+\bibitem{bar}
+foo
+\end{thebibliography}
[^foo]
[#bar]
+
+[#bar]: foo
<p>Cite.<a href="#cn:1" id="cnref:1" title="see citation" class="citation">[1]</a></p>
+<p>Cite.<a href="#cn:2" id="cnref:2" title="see citation" class="citation">[2]</a></p>
+
<h1 id="linksandimages">Links and Images </h1>
<p><a href="http://foo.net/">link</a> and <a href="http://bar.net" title="title" class="custom">link</a></p>
<p>Inline Citation <a href="#cnref:1" title="return to body" class="reversecitation"> ↩</a></p>
</li>
+<li id="cn:2">
+<p>bar
+ <a href="#cnref:2" title="return to body" class="reversecitation"> ↩</a></p>
+</li>
+
</ol>
</div>
<p>Cite.[#Inline Citation]</p>
+<p>Cite.<a href="bar">#foo</a></p>
+
<h1>Links and Images </h1>
<p><a href="http://foo.net/">link</a> and [link]</p>
Bar.\footnote{And a reference footnote.}
-Cite.\citesyntax TBD
+Cite.~\citep{inlinecitation}
+
+Cite.~\citep{foo}
\part{Links and Images }
\label{linksandimages}
-\href{http://foo.net/}{link}\footnote{\href{http://foo.net/}{http:/\slash foo.net\slash }} and \href{http://bar.net}{link}\footnote{\href{http://bar.net}{http:/\slash bar.net}}
+\href{http://foo.net/}{link}\footnote{\href{http://foo.net/}{http:\slash \slash foo.net\slash }} and \href{http://bar.net}{link}\footnote{\href{http://bar.net}{http:\slash \slash bar.net}}
\begin{figure}[htbp]
\centering
\label{horizontalrules}
\begin{center}\rule{3in}{0.4pt}\end{center}
+
+\begin{thebibliography}{0}
+
+\bibitem{inlinecitation}
+Inline Citation
+
+\bibitem{foo}
+bar
+
+\end{thebibliography}
Cite.[#Inline Citation]
+Cite.[#foo]
+
+[#foo]: bar
+
# Links and Images #
<ol>
<li id="cn:1">
-<p>bar <a href="#cnref:1" title="return to body" class="reversecitation"> ↩</a></p>
+<p>foo <a href="#cnref:1" title="return to body" class="reversecitation"> ↩</a></p>
</li>
</ol>
<p>[^foo]</p>
-<p>[#bar]</p>
+<p><a href="foo">#bar</a></p>
\ No newline at end of file
--- /dev/null
+'foo'
+
+''foo''
+
+foo's
+
+foo --- bar
+
+foo -- bar
+
+5
+
+foo{\ldots}
+
+\footnote{foo}
+
+~\citep{bar}
+
+\begin{thebibliography}{0}
+
+\bibitem{bar}
+foo
+\end{thebibliography}
[^foo]
[#bar]
+
+[#bar]: foo