Sometimes I create ad-hoc macros in the middle of my document for various reasons. However, the definitions sometimes cause extra space to be inserted. My questions are:
- Why does this happen?
- How can I prevent this from happening?
Here is an example:
\documentclass[varwidth]{standalone}
\begin{document}
Lorem ipsum sit amet. Lorem ipsum dolor sit amet.
Lorem ipsum
\newcommand\dolor{dolor}
sit amet. Lorem ipsum \dolor{} sit amet.
\end{document}

\newcommand\dolor{sit}%. But generally it is not a good idea to do definitions like this, your document can get very fast quite messy. Keep them in one place, – Ulrike Fischer Apr 22 '21 at 08:31\newcommandwould insert an extra space. I've learnt that TeX ignores redundant whitespace around words, including a single newline. – MyComputer Apr 22 '21 at 08:45