fletcher / MultiMarkdown-4

This project is now deprecated. Please use MultiMarkdown-6 instead!
https://github.com/fletcher/MultiMarkdown-5
Other
306 stars 59 forks source link

Added support for "acronym plurals", the "glossaries" LaTeX package, and a configurable acronym label creation. #115

Open rmrnc opened 9 years ago

rmrnc commented 9 years ago

Added support for "acronym plurals" Now an acronym defined as

\newacro{RFC}[RFC]{Request for Comment}

can be referenced in a text by

See RFC 1234 for more information. Multiple RFCs are covering security protocols. An RFC's number (simple genitive) can be addressed w/o confusion.

Producing

See \ac{RFC} for more information. Multiple \acp{RFC} are covering security protocols. Even an \ac{RFC}'s number (simple genitive) can be addressed w/o confusion.

In order to achieve this, find_abbreviations() [in writer.c] has to "partially" match an abbreviation and pass a detected plural along the corresponding node->key. Thus, a new node key type ABBRPLURAL has been introduced [in libMultiMarkdown.h] and propagated in all print_*_node() functions (though only an implementation for LaTeX has been provided).

As the partial abbreviation lookup would've necessitated frequent calls of strlen(), performance optimization dictated to extend the node structure by adding a len element. To avoid an irresponsible memory increase, an intentional small data type unsigned short int has been proposed. The chosen data type is (build) configurable by introducing an abstract NODE_LEN type and several typedef macros [in libMultiMarkdown.h] Repercussions are: an optimized strdup() replacement strdup_ext() providing a string's length, optimizations of the trim_*() functions, and alteration of all node creations and node copies.

Added support for the LaTeX glos­saries pack­age Glossaries package provided by Ni­cola Tal­bot (see http://www.ctan.org/pkg/glossaries).

For longer documents this package allows a better acronym and glossary management. Due to its preferred workflow, which requires a separate makeidx call, it seems impossible to avoid the introduced code changes by applying TeX's \renewcommand and substituting MMD's supported \ac and \newacro commands instead. By specifying the metadata key

LaTeX Acronym Package: [acronym | glossaries ]

the preferred acronym package can be selected. Omitting the "LaTeX Acronym Package" key selects, of course, MMD's default behavior, i.e., "acronym package" support. For this feature the METAKEY, ABBREVIATION, and ABBR switch-cases in print_latex_node() [in latex.c] and the scratch_pad struct [in parser.h] have been modified. An additional enum latex_acronym_package has been introduced. The additional scratch_pad element latex_acronym_config is stored in a compact way.

Added support for configuring an acronym's label creation

MMD current preference for creating labels is to avoid duplicate acronym keys by concatenating an acronym key with the acronym's text. This makes manual referencing of acronym labels very difficult. Unfortunately, manual acronym referencing in unavoidable, when longer documents are written, e.g., intentionally selecting the full acronym text after its first mentioning, using acronyms in "HTML comment escaped" LaTeX blocks like abstracts, etc.

By specifying the metadata key

LaTeX Acronym Label Style: [Abbreviation | Full]

the preferred acronym label creation style can be selected. Omitting the "LaTeX Acronym Label style" key selects, of course, MMD's default behavior, i.e., "full" label creation. For this feature the METAKEY, ABBREVIATION, and ABBR switch-cases in print_latex_node() [in latex.c] and the scratch_pad struct [in parser.h] have been modified. An additional enum latex_acronym_label_style has been introduced. The additional scratch_pad element latex_acronym_config is stored in a compact way.

rmrnc commented 9 years ago

Hi, Writing an extensive document in Scrivener using MMD/LaTeX, the default acronym and glossary management turned out to be insufficient. Specifically, the missing support for plurals in acronyms combined with a default label creation concatenating an acronym's key with its description (granted, that avoiding acronym collisions is a priority) required a substantial amount of manual HTML comment hacking, e.g., <!--\acp{rfcrequestforcomment}-->. As MMD's standard support of the acronym package was another limitation in dealing with acronyms and glossaries, I decided to include an optional support for the "glossaries" package as well.

As it affects the MMD's grammar, I haven't tackled another major obstacle: how to extend the acronym definition to accept additional parameters. Ideally, something like the tag=value attribute scheme used for images would be helpful, e.g.,

*[CA]: "Certification Authority" longplural={Certification Authorities}

creating an entry (for the glossaries package)

\newacronym[longplural={Certification Authorities}]{CA}{CA}{Certification Authority}

It would be also great to allow HTML-commented LaTeX commands in an acronym definition to be carried over, e.g.,

*[CA]: "Certification Authority, see " longplural={Certification Authorities}

\newacronym[longplural={Certification Authorities}]{CA}{CA}{Certification Authority, see \citep{abc}}

Any thoughts on that?

Cheers Remo

rmrnc commented 9 years ago

Oops. I involuntarily closed the the pull request.