# I am failing to make the answer look good. What can I do?

My answer to this question Minimizing $a_1x_1^2 + a_2x_2^2$ for positive $a_i$, where $a_1x_1+a_2x_2=B$ looks very bad on the phone. The syntaxes look fine when I switch to the desktop version of the site on the phone. But again, when I switch to the normal version, it looks bad enough. I've edited my answer several times. But it doesn't work. The problem is that I don't know what the codes will look like before. (only possible on desktop version). However, I don't want to do too much "trial and error". Because this is generally not welcome. Right now I almost don't know how I can improve my answer.

\begin{align}a_1x_1^2+a_2x_2^2&=a_1\left(\frac{B-a_2x_2}{a_1}\right)^2+a_2x_2^2\\ &=\frac{B^2-2Ba_2x_2+a_2^2x_2^2}{a_1}+a_2x_2^2\\ &=\left(a_2+\frac{a_2^2}{a_1}\right)x_2^2-\left(\frac{2Ba_2}{a_1}\right)x_2+\frac{B^2}{a_1}\end{align}

\begin{align}a_1x_1^2+a_2x_2^2&=a_1\left(\frac{B-a_2x_2}{a_1}\right)^2+a_2x_2^2\\ &=\frac{B^2-2Ba_2x_2+a_2^2x_2^2}{a_1}+a_2x_2^2\\ &=\left(a_2+\frac{a_2^2}{a_1}\right)x_2^2-\left(\frac{2Ba_2}{a_1}\right)x_2+\frac{B^2}{a_1}\end{align}

\begin{align]a:=a_2+\frac{a_2^2}{a_1}, ~b:=-\frac{2Ba_2}{a_1} , ~c:=\frac{B^2}{a_1}\end{align}

\begin{align}a:=a_2+\frac{a_2^2}{a_1}, ~b:=-\frac{2Ba_2}{a_1} , ~c:=\frac{B^2}{a_1}\end{align}

\begin{align}a_1x_1^2+a_2x_2^2=\left(a_2+\frac{a_2^2}{a_1}\right)\left(x_2-\frac{B}{a_1+a_2}\right)^2+\frac{B^2}{a_1+a_2}\end{align}

\begin{align}a_1x_1^2+a_2x_2^2=\left(a_2+\frac{a_2^2}{a_1}\right)\left(x_2-\frac{B}{a_1+a_2}\right)^2+\frac{B^2}{a_1+a_2}\end{align}

\begin{align}\color {gold}{\boxed {\color{black}{{\min\left\{a_1x_1^2+a_2x_2^2 \mid a_1x_1+a_2x_2=B\right\}=\frac{B^2}{a_1+a_2} ~ \text{at}~ x_1=x_2=\frac{B}{a_1+a_2}}}}}\end{align}

\begin{align}\color {gold}{\boxed {\color{black}{{\min\left\{a_1x_1^2+a_2x_2^2 \mid a_1x_1+a_2x_2=B\right\}=\frac{B^2}{a_1+a_2} ~ \text{at}~ x_1=x_2=\frac{B}{a_1+a_2}}}}}\end{align}

As it seems the equations seem to be broken and scattered. I was able to do the first one somehow. As I moved towards the end, I just couldn't align my equations.

How can I prevent equations from breaking?

Thank you.

• How does it looks like? By switching to the Mobile version, was one supposed to see what you're saying? I did it but I saw nothing ugly, I saw what I saw on the desktop version, a good look answer btw. – Verónica Rmz. May 5 at 21:47
• @Verónica No, I don't agree. Unfortunately, my answer definitely doesn't look good. And it needs good MathJax knowledge. – lone student May 5 at 21:53
• You are trying too hard. Your answer looks great (visually, will get an upvote when I read the math content, :D). On phone in portrait mode some equation will break into multiple lines. Just put the phone in landscape mode (rotate) and then reload the page. I use the site exclusively on mobile device and I am used to this problem which you face, so sometimes I keep the phone in landscape. – Paramanand Singh May 6 at 0:29
• Also why do you use "align" environment when you don't need any alignment using "&". – Paramanand Singh May 6 at 0:33
• @ParamanandSingh Thank you for taking care of my question! I don't know what these symbols mean. I just had to memorize it while using the site. Answers from high reputation users often contain excellent MathJax knowledge. I'm looking at the codes for their answers. As far as I understand this, the & symbol divides the equations and makes them equal one under the other. But I don't know how to use it yet. Actually, I have 1 million questions in my head about MathJax. Sometimes I can't write equations the way I want... – lone student May 6 at 0:44
• @ParamanandSingh Since I am not making a career, I am not asking MathJax questions here unless I have to. There is a lot of information about MathJax on the site. But usually I couldn't find what I was looking for. – lone student May 6 at 0:47
• Take your time to learn mathjax. Also confirm if you can see you answer properly in landscape. – Paramanand Singh May 6 at 0:55
• @ParamanandSingh Often I could not find what I was looking for, probably a systematic knowledge base is required. Anyway, not much information is needed anyway. I am not solving Differential Geometry. Middle school algebra as we know it. Too much MathJax is not required. Yes I did what you said. It did not help. (landscape mode) It probably won't work for you either. But, there is no problem with the Desktop version. – lone student May 6 at 1:04
• That's strange, it should have helped. Do you use the full version of the site on mobile? There is a specific mobile site version which you should not use. Switch to full site version and I think you will see exactly as in your desktop. At least this is working fine for me on Firefox on Android. – Paramanand Singh May 6 at 1:06
• Go to the bottom of the page and click on "full site". It appears you have been missing a lot of features by remaining within "mobile site". – Paramanand Singh May 6 at 1:10
• @ParamanandSingh There is no problem when I switch to desktop version on the phone. Everything gets mixed up when I switch to normal phone mode. Now, you say everything is alright? So nothing is needed? (by the way thank you for upvote $\ddot\smile$) – lone student May 6 at 1:13
• – Paramanand Singh May 6 at 1:14
• Why do you call this aligning? Alignment means that the equality signs are on top of each other. Like in your first displayed multistep calculation. If you attempt to squeeze more than one equation into a single displayed line, things may go South, and the spacing is usually unpleasant. I sometimes do things like $$x=2\quad\text{and}\quad y=3$$ with $$x=2\quad\text{and}\quad y=3$$ to get more space in between (and to save vertical space). But I'm not sure about the wisdom of that. – Jyrki Lahtonen May 6 at 5:11
• One of the first hits. Don't know if all of those are supported in MathJax. – Jyrki Lahtonen May 6 at 5:14
• @JyrkiLahtonen Thank you for your comment! I have an English language problem. I changed the sentence. – lone student May 6 at 6:01

The first few are understandable. But I only understood the last one in the gold box after staring at it for a while. My issue was that there are in fact two(or more) separate equalities being asserted on the same line. The line break on mobile makes it especially bad.

There is a line break on mobile because this is what Mathjax does to \displaystyle maths that is too long for the current display. While individual users can avoid the problem by using a computer or other device with a larger display, you simply cannot force some or all of your readers to change their website settings, much less their devices. I'll note that reloading the page on my iPhone 12 in Landscape mode (and using the "full site") still gives me the following output (An "Artist's recreation" follows) \begin{align}\color {gold}{\boxed {\color{black}{{\min\left\{a_1x_1^2+a_2x_2^2 \mid a_1x_1+a_2x_2=B\right\}=\frac{B^2}{a_1+a_2} ~ \text{at}~ x_1=x_2\\=\frac{B}{a_1+a_2}}}}}\end{align} which IMO is rather confusing; it looks like the minimum is both $$\frac{B}{a_1+a_2}$$ and $$\frac{B^2}{a_1+a_2}$$, which occurs anywhere on the line $$x_1=x_2$$.


1. (Forcing a line break at a better spot) $$\gbox{\min\left\{a_1x_1^2+a_2x_2^2 \mid a_1x_1+a_2x_2=B\right\}=\frac{B^2}{a_1+a_2} , \\ \text{at}~ x_1=x_2=\frac{B}{a_1+a_2}.}$$ $$\gbox{\min\left\{a_1x_1^2+a_2x_2^2 \mid a_1x_1+a_2x_2=B\right\}=\frac{B^2}{a_1+a_2} , \\ \text{at}~ x_1=x_2=\frac{B}{a_1+a_2}.}$$
2. (alternate notation for min) $$\gbox{\min_{ a_1x_1+a_2x_2=B}(a_1x_1^2+a_2x_2^2)=\frac{B^2}{a_1+a_2} , ~ \text{at}~ x_1=x_2=\frac{B}{a_1+a_2}.}$$ $$\gbox{\min_{ a_1x_1+a_2x_2=B}(a_1x_1^2+a_2x_2^2)=\frac{B^2}{a_1+a_2} , ~ \text{at}~ x_1=x_2=\frac{B}{a_1+a_2}.}$$
3. (Adding text; this is what I would use) $$\gbox{\min_{a_1x_1+a_2x_2=B}(a_1x_1^2+a_2x_2^2) = \frac{B^2}{a_1+a_2},}$$which is achieved when $x_1=x_2=B/(a_1+a_2)$. $$\gbox{\min_{a_1x_1+a_2x_2=B}(a_1x_1^2+a_2x_2^2) = \frac{B^2}{a_1+a_2},}$$which is achieved when $$x_1=x_2=B/(a_1+a_2)$$.
4. (Evaluation at points with bar notation) This one is only a little shorter but it line breaks more gracefully $$\gbox{\min_{a_1x_1+a_2x_2=B}(a_1x_1^2+a_2x_2^2) = (a_1x_1^2+a_2x_2^2) \Bigg|_{\substack{x_1= B/(a_1+a_2)\\ x_2=B/(a_1+a_2) }}= \frac{B^2}{a_1+a_2} .}$$$$\gbox{\min_{a_1x_1+a_2x_2=B}(a_1x_1^2+a_2x_2^2) = (a_1x_1^2+a_2x_2^2) \Bigg|_{\substack{x_1= B/(a_1+a_2)\\ x_2=B/(a_1+a_2) }}= \frac{B^2}{a_1+a_2} .}$$
5. (Argmin, technically correct but rather uncommon notation) $$\gbox{\min_{a_1x_1+a_2x_2=B}(a_1x_1^2+a_2x_2^2)= \frac{B^2}{a_1+a_2},\\ \operatorname*{argmin} _{a_1x_1+a_2x_2=B}(a_1x_1^2+a_2x_2^2) =\left(\frac B{a_1+a_2 }, \frac B{a_1+a_2 }\right).}$$$$\gbox{\min_{a_1x_1+a_2x_2=B}(a_1x_1^2+a_2x_2^2)= \frac{B^2}{a_1+a_2},\\ \operatorname*{argmin} _{a_1x_1+a_2x_2=B}(a_1x_1^2+a_2x_2^2) =\left(\frac B{a_1+a_2 }, \frac B{a_1+a_2 }\right).}$$

I found a way to force it to not line break, which relies on the background colour being white (in particular breaking that person’s unofficial Dark Mode that I can’t easily link to atm as I’m on mobile). I do not recommend this, I hate it when the scroll bar appears. But I am not your boss :) also mathjax works a little differently on the main site and I haven’t tested it there$$\gbox{\color{white}{\overline{\color{black}{ \min\left\{a_1x_1^2+a_2x_2^2 \mid a_1x_1+a_2x_2=B\right\}=\frac{B^2}{a_1+a_2} , \\ \text{at}~ x_1=x_2=\frac{B}{a_1+a_2}}}}}$$$$\gbox{\color{white}{\overline{\color{black}{ \min\left\{a_1x_1^2+a_2x_2^2 \mid a_1x_1+a_2x_2=B\right\}=\frac{B^2}{a_1+a_2} , \\ \text{at}~ x_1=x_2=\frac{B}{a_1+a_2}}}}}$$

• Thanks.Do we have the tools to prevent the equation from breaking? – lone student May 6 at 5:45
• @lonestudent I thought I tried everything and failed but I found one ‘hack’ and updated the answer. All I can do now is hope you don’t use it :) – Calvin Khor May 6 at 6:17
• Thank you @CalvinKhor. You got close to what I wanted. In the last line, to bring the next part from B to the bottom and to get it right in the middle. Actually, that's what I wanted to do. What's the difference between gbox and boxed? Why did you use gbox? On the other hand, here everything seems to be OK in the question place. But everything is bad in the answer place. I think the question place is "wider" than the answer place. I don't know any other answer.. – lone student May 6 at 11:38
• @lonestudent You’re welcome; I’ll note a variant of my suggestion 3 was edited into the post in question. I’m not sure what you are saying about ‘B to the bottom and to get it right in the middle’. I made gbox out of your commands (one of which being boxed). The reason I made gbox is because of the large number of {}s which made it hard for me to make this post on mobile. With gbox I only had to get it right once – Calvin Khor May 6 at 13:52
• Lack of my English. Never mind. Everything else aside. When we get a down vote, we don't lose points. But I was just curious. Can people give me a valid argument to downvote my question? It is really interesting. Well, it doesn't matter. I just wanted to note. Thanks for answer. However, I know that the formulas in my answer still don't look perfect. If you look at my answer, you can still see the broken lines. Probably, I need to apply what you did last to my previous formulas. It's a little troubled. Anyway. Now I will leave my answer as it is. – lone student May 6 at 14:05
• @lonestudent Sorry I couldn't understand. Well, I can only guess: a Mathjax purist might object to trying to do things that go against what Mathjax tries to help you to do. Or perhaps someone would prefer less Mathjax posts on their Math.Meta front page... – Calvin Khor May 6 at 14:31
• Yes. Of course. We can make a guess. But we don't know the truth. Thanks for trying to help. As I said, now I'll leave my answer as it is. You have a lot of help on the meta. I appreciate. – lone student May 6 at 14:42
• For example, see Robjohn's latest answer.. It is possible to see a flawless Mathjax at the highest level that lines never break. math.stackexchange.com/a/4124328/460967 – lone student May 9 at 0:59
• @lonestudent it seems that using \tag may also force the line to not break. Also he very specifically avoids putting text in a display math environment. Though I’m not so sure that avoiding line breaking on smaller screens is something robjohn actively tries to do. In LaTeX, long displaymathstyle lines do not automatically break. – Calvin Khor May 9 at 2:19