2

I am working on a document where I want to enforce the use of acronyms via the glossaries package. My intention is to ensure that each acronym is used properly with the \gls{} command so that I can keep the spelling consistent throughout the document. I want LaTeX (Overleaf) to throw warnings or errors if an acronym is used without the \gls command. Here is a minimal working example (MWE) to illustrate my goal:

\documentclass{article}

\usepackage[%
  acronym,         % Enable acronym functionality
  nomain,          % No main glossary
]{glossaries}

\newacronym{HTML}{HTML}{Hypertext Markup Language}
\makeglossaries

\begin{document}

\gls{HTML} should be valid whereas the pure usage of ``Hypertext Markup Language'' or ``HTML'' should throw warnings/errors as they are not used with \texttt{\gls\{HTML\}}

\end{document}

In this example, the usage of \gls{HTML} is correct and should compile without any issues. However, I want LaTeX to flag the instances of Hypertext Markup Language and HTML (without the \gls) as incorrect, and throw either warnings or errors to alert me of the misuse.

Is there a way to enforce this rule, possibly through glossaries-extra or a custom command? Any guidance on how to achieve this would be greatly appreciated. Thank you in advance for your help!

2
  • you can't do this in latex (other than luatex) but you could use an external search tool such as grep or perl (that you could call from overleaf) to search for things. But what do you want to search for, the most likely failure is using a term which is not defined at all, you could look for all caps eg HTML or XML and say they should be \gls but spotting arbitrary phrases that could be made in to acronyms seems hard. Oct 28, 2023 at 18:05
  • You could grep the definitions of the acronyms you do define and search for instances in the text of those.
    – cfr
    Oct 28, 2023 at 18:09

1 Answer 1

2

https://www.overleaf.com/read/pdnvqtykcmcs#ede4b2

You can grep (search) for the acronym and its expansion here leaving in grep.log which you can see from overleaf's other logs and files menu, It shows the line number and found text.

checking HTML
21:`HTML
21:`Hypertext Markup Language

from

\documentclass{article}

\usepackage[%
  acronym,         % Enable acronym functionality
  nomain,          % No main glossary
]{glossaries}
\NewCommandCopy\xnewaconym\newacronym
\makeatletter
\def\newacronym#1#2#3{%
\xnewaconym{#1}{#2}{#3}%
\immediate\write18{echo checking #1 >>grep.log}%
\immediate\write18{grep -on "[^{}]#2" *.tex >>grep.log}%
\immediate\write18{grep -on "[^{}]#3" *.tex >> grep.log}%
}
\makeatother
\newacronym{HTML}{HTML}{Hypertext Markup Language}
\makeglossaries

\begin{document}

\gls{HTML} should be valid whereas the pure usage of ``Hypertext Markup Language'' or ``HTML'' should throw warnings/errors as they are not used with \texttt{\gls{HTML}}

\end{document}

There is currently a live overleaf link to the project above, but I don't guarantee that will stay forever.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .