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."
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityHow 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}