4

I'm writing my thesis using Latex. And I'm wondering if there is an automatic or an easy way to write my acronyms. I did that before in Microsoft Word where I search for all words that are upper case then add them to my acronyms and sort them alphabetically?

Tak
  • 2,346
  • 4
  • 20
  • 33
  • 2
    @Rmano I don't see how this is a similar question. – Tak May 04 '15 at 11:42
  • 2
    @Rmano: That's a completely different problem. The OP is after automation, not for the basic usage of acronyms –  May 04 '15 at 12:24
  • You could use grep to search for all uppercase characters and generate the TeX commands. – Uwe Ziegenhagen May 04 '15 at 13:21
  • Just to add to the question: and sort them alphabetically – latex fan May 04 '15 at 14:04
  • @latexfan Done :) – Tak May 04 '15 at 14:05
  • What about packages glossaries or acro? – cgnieder May 04 '15 at 17:18
  • My guess is that the answer is no. This said, it is easy to do this from the command line using tools like sed. For example, sed -i .bak "s@[[:<:]][A-Z][A-Z][A-Z]*[[:>:]]@\\\ac{&}@g" file.tex does what you want on my system. This will replace any "word" in the file file.tex that consists of 2 or more capital letters with \ac{<word>}. The original file is saved as file.tex.bak just to be safe. –  May 04 '15 at 23:09
  • @Andrew How about U.S. and cdROM? Not easy to use regex to identify acronyms and abbreviatons, although you can probably catch about95%. – yannisl Jun 03 '15 at 15:51
  • @YiannisLazarides The question says, well suggests, that they are all upper case. Allowing .s in the regular expression would be easy enough, but I agree it's unlikely to be complete accurate. As for cdROM, surely it would be CD or CDROM:) –  Jun 03 '15 at 21:10

2 Answers2

3

enter image description here

\documentclass{article}
\usepackage{luacode}

\begin{luacode}
function FindAcronyms ( file )
    local param
    local Table = {}

    local f = assert(io.open(file, "r"))
    local t = f:read("*all")
    f:close()
    for param in t:gmatch ("[^%l]%s?(%u+)%p?%s")
    do
    table.insert(Table, param)
    end

    table.sort(Table)
    tex.print("\\bigskip")
    for i,acronym in ipairs (Table)
        do
        tex.print (i.." : "..acronym.."\\\\")
        end
end

\end{luacode}

\newcommand{\FindAcronyms}{%
    \directlua{FindAcronyms("\jobname.tex")}
}


\begin{document}

CCC! SomeThing ELSe AAA, CABA enD BAA 


\FindAcronyms


\end{document}
Tarass
  • 16,912
0

Not sure I understand what you are after, but may be package acronym will be of interest to you. It expands acronyms on first use and allows you to compile a list of them all.

F. Tusell
  • 753