[texhax] Auto capitilise first letter of acronym

Donald Arseneau asnd at triumf.ca
Wed May 2 00:40:43 CEST 2012

Viktor Ahlqvist <viktor at datakaka.net> writes:

> I'm trying to write a macro that auto capitalise the first letter in
> an acronym if the acronym is the first word in a sentence. So far I
> have come up with the following macro.
> \sfcode`\.=1001\sfcode`\?=1001\sfcode`\!=1001\sfcode`\:=1001
> \newcommand{\acr}[1]{\ifnum\spacefactor=1001

\spacefactor is what makes sense, but it has its limitations.  Perhaps
best is to define two commands \acr and \Acr and choose them manually
(just as you choose between "The" and "the" manually).

> I have two problems however, that I can't find a solution for.
> 1) I get an error if I put \acr{} in the beginning of a paragraph.
> ! Improper \spacefactor.

Incorporate \ifhmode or \ifvmode as part of the test.  Note that
the usual \leavevmode will get rid of the error, but will not
capitalize the first letter of the paragraph.
> 2) The macro fails to recognise the beginning of sentences if I use
> polyglossia and set the default language to Swedish. Polyglossia and
> English works fine. 

Space factors are legitimately under the control of the language.
To use them yourself you'd need to override whatever settings the
language specifies.  I don't know the mechanism in polyglossia,
but there must be one.

> I think this has something to do with
> frenchspacing, since the only difference I can find between the two
> languages in \PolyglossiaSetup (in polyglossia.dtx) is
> "frenchspacing=true" in Swedish. If I enable frenchspacing with the
> \frenchspacing command (and omit polyglossia), everything works just
> fine.

I am very surprised that it works with \frenchspacing!  Are you sure
you tested properly?  Perhaps you declared \frenchspacing before setting
your own \sfcodes, so the \frenchspacing was irrelevant.

Donald Arseneau                          asnd at triumf.ca

More information about the texhax mailing list