Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

add comment

1 Answer 1

up vote 9 down vote accepted

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.

share|improve this answer
2  
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
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.