# How to avoid prepending a blank line or indenting the first line of a post when using \newcommand?

When \newcommand is used, it is somewhat common that it is used in such a way that the (rendered) post starts with a blank line.

While this is minor, it is still somewhat unfortunate, and can be avoided easily.

If there are better or other ideas or related thoughts, please, share them.

• I think this post could be much shorter and much more to-the-point. – Stefan Kohl Dec 17 '13 at 22:49
• Likely true. I will give it another try. Added: I hope it is better now. Feel free to change it. – user9072 Dec 17 '13 at 23:00
• Much better now. -- I just edited the title, since I felt it could still convey a little more information. – Stefan Kohl Dec 17 '13 at 23:27
• By the way, it is probably best to not use \newcommand and similar mathjax commands at the very beginning of the post. Otherwise, that is pretty much all you see in the short excerpt which is shown in lists of questions and answers. – Ricardo Andrade Dec 18 '13 at 1:59
• Good point @RicardoAndrade! And thanks for the additional solutions. (In my very personal opinion it is even best to avoid newcommand not only at the start but altogether on MO; but this is a lost case.) – user9072 Dec 18 '13 at 10:59
• One reason to put definitions at the beginning is to avoid errors when the text is reordered during editing, and the definition ends up after its first use. These mistakes cannot be caught up in preview, because Mathjax does not forget definitions once it learned them in the same session, and the preview is reprocessed many times. (This was inadvertently demonstrated by the now deleted post by @Joel.) – Emil Jeřábek 3.0 Dec 19 '13 at 16:06
• @Emil Jeřábek: Whenever possible, I try to write a short introductory paragraph or sentence in which fancy commands are not required, and only then place \newcommand and similar declarations. However, it is possible this method may not work for everyone or all the time. – Ricardo Andrade Dec 19 '13 at 17:04
• @Ricardo Andrade: Right. I guess no method really works for everyone all the time, I just wanted to point out a factor that may be relevant for the decision which method to follow. – Emil Jeřábek 3.0 Dec 20 '13 at 11:41

You can also introduce new commands only when they are first needed. Such as $\newcommand{\where}{\text{here}}\where$ or $\where$.

Source:

You can also introduce newcommands only when they are first needed.
Such as $\newcommand{\where}{\text{here}}\where$ or $\where$.

• Best method in my opinion, and that's how I do it too. – Asaf Karagila Dec 18 '13 at 6:26
• Thanks for adding this. This method occured to me as well, but I did not dare to propose it as I was worried people would complain it would be "crazy/ugly to parse, and seems [to me] very likely to result in errors upon further edits" (quoting JDH on my proposed solution). To be clear I consider this as an alright method, that has the advantage of not having MathJax at the start but the disadvantage of it being a bit harder to get an overview when latter editing (though MO posts not being that complex MJ-wise typically this should be alright). – user9072 Dec 18 '13 at 10:47

$\newcommand{\test}{\text{test}}$Here it starts in the way it should start. And I continue to get a second line to see that it really starts right at the start of the line and not with some extra space as in still another variant.

Source snippet:

$\newcommand{\test}{\text{test}}$Here it starts in the way it should start.


If there is no space at all between the MathJax and the text it is alright.


$%% Preamble %% \newcommand{\test}{\text{test}}$Here it starts in the way it should start. It is a little easier to parse than the variant proposed by quid. It also has fewer characters than Ricardo's proposal.

Source:

$%% Preamble %% \newcommand{\test}{\text{test}}$Here it starts in the way it should start.
It is a little easier to parse than the variant proposed by quid.
It also has fewer characters than Ricardo's proposal.


$\newcommand{\test}{\text{test}}$

Here we have a lot of space at the start.

Source:

$\newcommand{\test}{\text{test}}$

Here we have a lot of space at the start.


The main issue is the empty-line. While the MathJax does not display anything it is still "there" and the empty-line translates to a 'new' paragraph being started.

$\newcommand{\test}{\text{test}}$Here we have no space at the start, and the source is slightly easier to parse. To achieve this, we use html comments.

Source:

$\newcommand{\test}{\text{test}}$<!--
%
-->Here we have no space at the start, and the source is slightly easier to parse.
To achieve this, we use html comments.

• Unfortunately, html comments appear to break sometimes if there is an empty line within the comment... Hence the random symbol % appears in the code above to create an "empty" separating line, which is meant to increase readability. – Ricardo Andrade Dec 18 '13 at 2:52
• In any case, I still think it is best to avoid using \newcommand at the very beginning of the post. – Ricardo Andrade Dec 18 '13 at 2:52