# Macro that checks for the beginning of a line

How can I add a new command that differentiates between the first word of a line, and any other case?

For example, the macro \etc for printing "etcetera" if its the beginning of the line, otherwise, print just "etc."

It's not really possible to do this in full generality as TeX breaks a paragraph into lines after all macros are expanded and the characters typeset into a horizontal list.

You can do this, the main drawback of which is that the space before the word in the case of no line break is not stretchy like other spaces on the line.

\documentclass{article}

\newcommand\etc{\ifhmode\unskip\fi\discretionary{}{etcetera}{\hbox{ etc.}}}
\begin{document}

word \etc\ wordword \etc\ wordword \etc\ word
word \etc\ wordword \etc\ wordword \etc\ word
word \etc\ wordword \etc\ wordword \etc\ word
word \etc\ wordword \etc\ wordword \etc\ word
word \etc\ wordword \etc\ wordword \etc\ word

\end{document}

• That's a fine job underlining the etc.. – Manuel Oct 1 '14 at 13:35
• @Manuel I strive for typographic excellence – David Carlisle Oct 1 '14 at 13:41