From: Fletcher T. Penney Date: Fri, 10 Mar 2017 23:43:19 +0000 (-0500) Subject: FIXED: Don't duplicate LaTeX glossary definitions X-Git-Tag: 6.0.0-b2~1^2~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=accdca6d30d54bdbc6dd1c875bec1f228bb2dea2;p=multimarkdown FIXED: Don't duplicate LaTeX glossary definitions --- diff --git a/Sources/libMultiMarkdown/latex.c b/Sources/libMultiMarkdown/latex.c index 3161fcb..a3ec7b7 100644 --- a/Sources/libMultiMarkdown/latex.c +++ b/Sources/libMultiMarkdown/latex.c @@ -1707,22 +1707,35 @@ void mmd_export_token_tree_latex_tt(DString * out, const char * source, token * } } +int clean_text_sort(fn_holder * a, fn_holder * b) { + return strcmp(a->note->clean_text, b->note->clean_text); +} + + void mmd_define_glossaries_latex(DString * out, const char * source, scratch_pad * scratch) { // Iterate through glossary definitions fn_holder * f, * f_tmp; + // Sort glossary entries + HASH_SORT(scratch->glossary_hash, clean_text_sort); + + char * last_key = NULL; + HASH_ITER(hh, scratch->glossary_hash, f, f_tmp) { - // Add this glossary definition - print_const("\\longnewglossaryentry{"); - print(f->note->clean_text); + if (!last_key || strcmp(last_key, f->note->clean_text) != 0) { + // Add this glossary definition + print_const("\\longnewglossaryentry{"); + print(f->note->clean_text); - print_const("}{name="); - print(f->note->clean_text); - print_const("}{"); + print_const("}{name="); + print(f->note->clean_text); + print_const("}{"); - mmd_export_token_tree_latex(out, source, f->note->content, scratch); - print_const("}\n\n"); + mmd_export_token_tree_latex(out, source, f->note->content, scratch); + print_const("}\n\n"); + } + last_key = f->note->clean_text; } // And abbreviations diff --git a/tests/MMD6Tests/Glossaries.tex b/tests/MMD6Tests/Glossaries.tex index f88fb73..1e8c9c0 100644 --- a/tests/MMD6Tests/Glossaries.tex +++ b/tests/MMD6Tests/Glossaries.tex @@ -1,42 +1,42 @@ \input{mmd6-article-leader} \def\mytitle{Glossaries} -\longnewglossaryentry{foo}{name=foo}{FOO} +\longnewglossaryentry{b a r}{name=b a r}{B A R} -\longnewglossaryentry{f.o.o.}{name=f.o.o.}{ - -F.O.O.} - -\longnewglossaryentry{f-o-o}{name=f-o-o}{ +\longnewglossaryentry{b-a-r}{name=b-a-r}{ -F--O--O} +B--A--R} -\longnewglossaryentry{f o o}{name=f o o}{ +\longnewglossaryentry{b.a.r.}{name=b.a.r.}{ -F O O} +B.A.R.} -\longnewglossaryentry{fo'o}{name=fo'o}{ +\longnewglossaryentry{ba'r}{name=ba'r}{ -FO'O} +BA'R} \longnewglossaryentry{bar}{name=bar}{ BAR} -\longnewglossaryentry{b.a.r.}{name=b.a.r.}{ +\longnewglossaryentry{f o o}{name=f o o}{ -B.A.R.} +F O O} -\longnewglossaryentry{b-a-r}{name=b-a-r}{ +\longnewglossaryentry{f-o-o}{name=f-o-o}{ -B--A--R} +F--O--O} -\longnewglossaryentry{b a r}{name=b a r}{ +\longnewglossaryentry{f.o.o.}{name=f.o.o.}{ -B A R} +F.O.O.} -\longnewglossaryentry{ba'r}{name=ba'r}{ +\longnewglossaryentry{fo'o}{name=fo'o}{ -BA'R} +FO'O} + +\longnewglossaryentry{foo}{name=foo}{ + +FOO} \longnewglossaryentry{foo bar}{name=foo bar}{