If you’re writing a long technical document you’ll probably use a lot of acronyms. To keep track of them in LaTeX I use the acro package. This wonderful package manages the short, long, plural, possessive and other versions of an acronym. Typing \ac{osn}
(having previously defined the acronym) will print out Online Social Network (OSN) the first time then OSN from then on.
If you’re a lazy person like me you’ll spend hours going out of your way to shave seconds off of common tasks. One such task is the hastle of typing \ac{osn}
. If you’re using lots of acronyms it can interrupt your flow to have to type out the full command and acronym name. Wouldn’t it be easier if you could just type \osn
? Well now you can!
\ExplSyntaxOn
\acro_begin:
\acro_for_all_acronyms_do:n{
\global\expandafter\def\csname ##1\endcsname{\ac{##1}}%
}
\acro_end:
\ExplSyntaxOff
This code, placed in the head of your document, registers a new command using the ID of every acronym. Here’s the code in action:
\documentclass{article}
\usepackage{acro}
\DeclareAcronym{osn}{
short = OSN,
long = Online Social Network
}
\ExplSyntaxOn
\acro_begin:
\acro_for_all_acronyms_do:n{
\global\expandafter\def\csname ##1\endcsname{\ac{##1}}%
}
\acro_end:
\ExplSyntaxOff
\begin{document}
Facebook is an \osn. Twitter is also an \osn.
\end{document}
And the result:
To take this further, you might want to consider only generating custom commands for acronyms with a certain property. You could use the \acro_get_property:nnTF
command to specify the name of an acronym’s custom command. Good luck!