# Automatically capitalize macro output if used after a period [duplicate]

Possible Duplicate:
Detect beginning of a sentence in a macro for capitalization

Is it possible to write a macro that is able to determine if it is used at the beginning of a sentence? For example, imagine

\def\location{street}
...
This \location is nice. \location has its charm.


A simple and silly one, but anyway, you get the idea. I want the second street to be "Street." How would one do this? I am using lualatex, so if only a lua-specific solution is possible, I'd be happy with it. If it is not possible then I would have to do it manually, but that would be a lot of work in my text :-(

-

## marked as duplicate by Werner, Hendrik Vogt, Gonzalo Medina, cgnieder, Harish KumarJul 21 '12 at 23:45

A quick test on \spacefactor works:

\documentclass{article}
\newcommand{\location}{%
\ifnum\spacefactor=3000
\expandafter\MakeUppercase\fi%
street}
\begin{document}
This \location\ is nice. \location\ has its charm.
\end{document}


The \spacefactor differs depending on the preceding punctuation: 3000 after a period.

Since I'm unfamiliar with \spacefactor, I'm not sure how robust it is.

-
That's really nice, it fails, if \frenchspacing is set though. With nonfrenchspacing set before ifnum it seems to work with frenchspacing too. –  Peter Breitfeld Jul 21 '12 at 20:04
Ha! And I was thinking that this was nearly impossible within LaTeX and required perhaps some lua magic! –  Gonzalo Medina Jul 21 '12 at 20:07
+1 and a (virtual) 'Sneaky Badge'! ;) –  Count Zero Jul 21 '12 at 20:41