6

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 :-(

MiB
  • 837
  • 4
  • 10

1 Answers1

10

A quick test on \spacefactor works:

enter image description here

\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.

Werner
  • 603,163