2

I would like to get a warning if I define an acronym using the acronym package and then use the long or short form of the acronym without using the acronym package's facilities. For example, in this document:

\documentclass{article}

\usepackage{acronym}

\begin{document}
\acrodef{FAQ}{frequently asked question}

Using \ac{FAQ} is fine.
I want to be warned if I use bare ``FAQ'', though.
I also want to be warned if I use ``frequently asked question''.

\end{document}

I would like output of the form:

warning: line 10: "FAQ" used instead of "\ac{FAQ}"
warning: line 11: "frequently asked question" used instead of "\ac{FAQ}"

Would be happy with a solution that uses any combination of LaTeX macros, LuaLaTeX Lua code, or post-processing. Right now I use two crude shell/Perl one-liners that are probably not very robust.

3
  • 4
    latex macros can't really help, they have no access to the paragraph text. You could use luatex input buffer filter but that's really no different to your perl. I'd use perl. Jun 11, 2021 at 21:30
  • Thanks for the information. I figured I could at least instrument the acronym-defining macros so that they write machine-readable information to a file. Maybe then I could convert this into UserWarnRegex patterns in a chktex local rcfile so at least I get some head start on processing TeX files. Jun 12, 2021 at 1:50
  • 2
    The macros already write to a file, your perl can start with the equivalent of grep newacro filename.aux to get a list of all the acronyms defined. Jun 12, 2021 at 9:20

1 Answer 1

1

I have added this capability to the texlint script in my allmytexs repository.

It works similarly to the below hacky previous script that converts acronyms in the aux file to patterns to search in a chktexrc file, and runs chktex.

#!/usr/bin/env bash

set -o nounset -o pipefail -o errexit

if [[ $# != 1 || "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
    echo usage: "$0" TEXNAME
    exit 2
fi

proc_acros () {
    sort | uniq | paste -s -d '|' | sed -e 's/ /! /g'
}

texname="$1"
if [[ $texname != *.tex ]]; then
    texname="${texname}.tex"
fi

pdfname="${texname%.tex}.pdf"
auxname="${texname%.tex}.aux"

chktexrc=acronym.chktexrc

latexmk "$texname" || true

rm --force "$chktexrc" 2>&1 || true

short_acros="$(perl -ne 'print if s/^\\newacro{([^}]+)}\[([^\]]+)\]{.+}$/\1\n\2/' "$auxname" | proc_acros)"
long_acros="$(perl -ne 'print if s/^\\newacro{[^}]+}\[[^\]]+\]{(.+)}$/\1/' "$auxname" | proc_acros)"

cat >"$chktexrc" <<EOF
WipeArg
{
    \acro:{}[]{}
    \acrodef:{}[]{}
    \acrodefused:{}[]{}
    \newacro:{}[]{}
    \acroindefinite:{}[]{}
    \newacroindefinite:{}[]{}
    \acrodefindefinite:{}[]{}
    \DeclareSIUnit:{}{}
    \ac:[]{} \Ac:[]{} \acp:[]{} \Acp:[]{}
    \acf:[]{} \Acf:[]{} \acfp:[]{} \Acfp:[]{}
    \acs:[]{} \Acs:[]{} \acsp:[]{} \Acsp:[]{}
    \acl:[]{} \Acl:[]{} \aclp:[]{} \Aclp:[]{}
    \url:{}
}

UserWarnRegEx
{
    (?!#-101:Short! version! of! acronym! found)(?<!!\\\\)(?:$short_acros)
    (?!#-102:Long! version! of! acronym! found)(?<!!\\\\)(?:$long_acros)
}
EOF

chktex --localrc "$chktexrc" "$texname" 2>&1 || true

\acrodefused is a LaTeX command I use to make acronyms that are considered defined from the start:

\newcommand*{\acrodefused}[2]{\acrodef{#1}{#2}\acused{#1}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.