4

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

7

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.

enter image description here

\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
  • 7
    @Manuel I strive for typographic excellence – David Carlisle Oct 1 '14 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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