I want to typeset my acronyms with abbreviating dots with, for instance, P.C.A. standing for principal component analysis and use macros for them. This question provides a trick to avoid double dots when the acronym is at the end of a sentence so that This could be done with a \pca. gives

This could be done with a P.C.A.

and not

This could be done with a P.C.A. .

Now, i would like to combine this approach with the acronym related commands of glossaries. Thus, I defined an acronym with this command

\newacronym{pca}{\pca}{principal component analysis}

and then use it with \gls{pca}

This could be done with a \gls{pca}.

However, the glossaries command add some characters between \pca and the full stop so that the trick mentioned before does not work and I get a double dot.

Any idea how I could deal with that?

Here is a minimal working example. The xspace package and command can be removed ; they are intended to conform to the english usage.




\newacronym{pca}{\pca}{principal component analysis}

This could be done with a \pca. %good

This could be done with a \gls{pca}. %good

This could be done with a \gls{pca}.%awkward
  • Acronyms are usually typeset without periods also in order to avoid problems like this one. The dots don't add anything that can't be obtained by a uniform typographical appearance of acronyms. – egreg Jul 11 '12 at 7:50
  • @egreg Still, the problem is real in some languages where dots are common practice in acronyms, or where there are "complex" abbreviations – a set of truncated words with dots between them, for instance. But I am afraid this calls for own acronym commands that no package offers out of the box. – ienissei Jul 11 '12 at 8:21
  • I am writing in french. In this language, the rule of thumb is that acronyms pronunced as words do not have dots while those pronunced as sequence of letters have some. Their are no unified rules about this particular point and usage vary a lot from one source to another. However, from what I could gather, dots are indeed useful and recomended in some context. – M. Toya Jul 11 '12 at 8:28
  • @AlfredM. I Thought it was something like that (I write in French too). This does not solve your question at all if you need to use the glossaries package for other reasons, but here is how I solved it with a (very ugly) biblatex hack. It could probably be improved by writing the .bib file automatically. Note that I opted for dots in all of the acronyms that should be in the list of abbreviations (the ones pronounced as words are well known and seldom explained, like UNESCO). – ienissei Jul 11 '12 at 8:52
  • Relevant discussions about the use of dots in acronym in french can be found here. The length of them shows how fuzzy the issue is. – M. Toya Jul 11 '12 at 9:09

This is a possible solution:


\newacronym{pca}{P.C.A.}{principal component analysis}

  \expandafter\csname ifglo@#1@flag\endcsname

This could be done with a \pgls{pca}. Just to see the first usage.

This could be done with a \pgls{pca}. And the spacing?

This could be done with a P.C.A\@. And the spacing?

This could be done with a \pgls{pca} or not.

This could be done with a P.C.A. or not.


The lines with the explicit P.C.A. are just to show that the spacing is good. The macro \pgls checks whether we are at the first usage of the acronym. More complicated things, such as using the expanded version at other times can be obtained by the ordinary commands provided by glossaries.

enter image description here

The macro checks first of all whether the acronym has already been used. In this case the conditional \ifglo@pca@flag is true. So when it's false we don't have to do anything special other than issuing \gls{pca}. The \expandafter\csname ifglo@#1@flag\endcsname is just to use the argument: with \pgls{pca} it becomes \ifglo@pca@flag as desired.

If the conditional is true, then the tokens after the final \fi are evaluated. This is the check whether a period follows; if there is a period, then \get@sf is executed, otherwise \xspace (necessary because \@ifnextchar gobbles spaces).

In case there is a period, \@ifnextchar doesn't remove it and it becomes the argument to \get@sf, which expands to \spacefactor\the\sfcode.\relax`, thus setting the desired space factor.

| improve this answer | |
  • 1
    I (and for sure others, too) would have appreciated if you explained in more in detail how the macro works. Just to enlighten us (me). It seems as a useful algorithm. Thank you in advance! – Sveinung Jul 11 '12 at 10:53
  • The spacing is not right if the command \frenchspacing is used. In a french document, one has to be careful to use pgls only at sentences end and \glselsewhere. – M. Toya Jul 21 '12 at 19:30
  • @AlfredM. I don't think the spacing is wrong: the macro adds the current spacefactor associated to a period, which \frenchspacing sets to 1000. – egreg Jul 21 '12 at 23:34
  • That should be some other line in my preamble then. I'll get back here if I find it. – M. Toya Jul 22 '12 at 8:45
  • The problem was caused by commenting the line loading the xspace package by mistake… Took some times to find because it did not throw an error. – M. Toya Oct 13 '12 at 8:51

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.