]> granicus.if.org Git - multimarkdown/commitdiff
FIXED: Don't duplicate LaTeX glossary definitions
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Fri, 10 Mar 2017 23:43:19 +0000 (18:43 -0500)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Fri, 10 Mar 2017 23:43:19 +0000 (18:43 -0500)
Sources/libMultiMarkdown/latex.c
tests/MMD6Tests/Glossaries.tex

index 3161fcbfa5b397ff7e76a44fd34f44b68eb8e356..a3ec7b7fc8c18add619a0016df7ac47445a3837b 100644 (file)
@@ -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
index f88fb73134abd03715b1fcb830a73b9583459ce2..1e8c9c09caa76546faa23831b8ea7d963b1347b1 100644 (file)
@@ -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}{