6
$\begingroup$

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.

One answer illustrates the problem, another one a solution, and still another an almost but not quite solution.

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

$\endgroup$
8
  • $\begingroup$ I think this post could be much shorter and much more to-the-point. $\endgroup$
    – Stefan Kohl Mod
    Dec 17, 2013 at 22:49
  • $\begingroup$ Likely true. I will give it another try. Added: I hope it is better now. Feel free to change it. $\endgroup$
    – user9072
    Dec 17, 2013 at 23:00
  • 1
    $\begingroup$ Much better now. -- I just edited the title, since I felt it could still convey a little more information. $\endgroup$
    – Stefan Kohl Mod
    Dec 17, 2013 at 23:27
  • 4
    $\begingroup$ 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. $\endgroup$ Dec 18, 2013 at 1:59
  • 1
    $\begingroup$ 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.) $\endgroup$
    – user9072
    Dec 18, 2013 at 10:59
  • $\begingroup$ 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.) $\endgroup$ Dec 19, 2013 at 16:06
  • 1
    $\begingroup$ @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. $\endgroup$ Dec 19, 2013 at 17:04
  • 1
    $\begingroup$ @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. $\endgroup$ Dec 20, 2013 at 11:41

5 Answers 5

8
$\begingroup$

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$.
$\endgroup$
2
  • $\begingroup$ Best method in my opinion, and that's how I do it too. $\endgroup$
    – Asaf Karagila Mod
    Dec 18, 2013 at 6:26
  • 1
    $\begingroup$ 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). $\endgroup$
    – user9072
    Dec 18, 2013 at 10:47
5
$\begingroup$

$\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.

$\endgroup$
1
  • $\begingroup$ Sorry to hear that. I hope you find one of the other solutions more satisfactory. I agree it is not optimal; the reason why I propsed it is that it felt very simple to integrate in the worklflow of people putting newcommand at the start. One could do everything as always and delete the blanklines at the end. To suggest it is very likely to result in erros upon further edits seems like an exageration to me. Anyway, if you are very worried about errors upon further editing I'd recommend to avoid newcommand altogether. $\endgroup$
    – user9072
    Dec 18, 2013 at 10:56
3
$\begingroup$

$ %% 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.
$\endgroup$
1
$\begingroup$

$\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.

$\endgroup$
1
$\begingroup$

$\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.
$\endgroup$
2
  • 1
    $\begingroup$ 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. $\endgroup$ Dec 18, 2013 at 2:52
  • $\begingroup$ In any case, I still think it is best to avoid using \newcommand at the very beginning of the post. $\endgroup$ Dec 18, 2013 at 2:52

You must log in to answer this question.