Recently I needed to put a list of acronyms to a LaTeX document. There is great acronym package for this purpose. With this package one can define the acronyms and refer to them from the text. The package ensures that the meaning of an acronym appears together with its first use. The package can also generate the list of acronyms however the list is not automatically sorted. When the list becomes long, a big amount of mental capacity is needed find the position where to add a new acronym.

Since I use Emacs to edit LaTeX documents, I’ve written a simple elisp macro (see below) to sort the acronyms. The macro is placed in LaTeX comment so it is not necessary to modify your .emacs.

With this macro adding an acronym is a lot easier:

  1. I add the acronym definition anywhere in the list.
  2. I press C-up to go to \begin{ and then left. This moves me at the end of the elisp expression.
  3. I press C-x C-e (eval-last-sexp) and the list is sorted!

You can try it with this example:

    % Sort acronyms: (let ((sort-fold-case t)) (sort-regexp-fields nil "^[[:space:]]*\\\\acro\{\\([^}]*\\)\}.*$" "\\1" (point-min) (point-max)))
    \begin{acronym}[XXXXX]
      \acro{AC}{Access Category}
      \acro{ACK}{Acknowledge}
      \acro{AIFS}{Arbitration Interframe Space}
      \acro{AIFSN}{Arbitration Interframe Space Number}
      \acro{AP}{Access Point}
      \acro{CSMA/CA}{Carrier Sense Multiple Access/Collision Avoidance}
      \acro{CTS}{Clear to Send}
      \acro{CW}{Contention Window}
      \acro{DIFS}{Distributed (Coordination Function) Interframe Space}
      \acro{EDCA}{Enhanced Distributed Channel Access}
      \acro{ERP}{Extended Rate PHYs}
      \acro{IP}{Internet Protocol}
      \acro{LAN}{Local Area Network}
      \acro{LLC}{Logical Link Control}
      \acro{MAC}{Medium Access Control}
      \acro{MTU}{Maximum Transmission Unit}
      \acro{PHY}{physical\acroextra{ (layer)}}
      \acro{PLCP}{Physical Layer Convergence Protocol}
      \acro{QoS}{Quality of Service}
      \acro{SIFS}{Short Inter-Frame Space}
      \acro{STA}{Station\acroextra{ in Wi-Fi network}}
      \acro{TOS}{Type of Service}
      \acro{UDP}{User Datagram Protocol}
    \end{acronym}