0
$\begingroup$

I have this MathJax sequence that I want to format properly in MathOverflow:

$$S_m = \begin{cases} \begin{aligned} 1, \quad\text{for m=1}\\ 12, \quad\text{for m=2}\\ 123, \quad\text{for m= 3}\\ 1234, \quad\text{for m= 4}\\ 12345, \quad\text{for m= 5}\\ 123456, \quad\text{for m= 6}\\ 1234567, \quad\text{for m= 7}\\ 12345678, \quad\text{for m= 8}\\ 123456789, \quad\text{for m= 9}\\ 1234567890, \quad\text{for m=10}\\ 12345678901, \quad\text{for m=11}\\ 12345678901..., \quad\text{for m>11}\\ S_{m-1} \times 10 + (m \bmod 10), \quad\text{for m>11}\\ \end{aligned} \end{cases} $$

$$S_m =
\begin{cases}
\begin{aligned}
1, \quad\text{for  m=1}\\
12, \quad\text{for  m=2}\\ 
123, \quad\text{for  m= 3}\\
1234, \quad\text{for  m= 4}\\
12345, \quad\text{for  m= 5}\\ 
123456, \quad\text{for  m= 6}\\  
1234567, \quad\text{for  m= 7}\\
12345678, \quad\text{for  m= 8}\\
123456789, \quad\text{for  m= 9}\\ 
1234567890, \quad\text{for m=10}\\  
12345678901, \quad\text{for m=11}\\  
12345678901..., \quad\text{for m>11}\\
S_{m-1} \times 10 + (m \bmod 10), \quad\text{for m>11}\\ 
\end{aligned}
\end{cases}
$$

However, it is rendered as follows (in the below screenshot):

Picture of rendering of the sequence

For $m=1$ to $m=9$ the formatting of "for" is left-indented as compared to $m=10$, $m=11$, and $m>11$.

I tried padding the "\text" statements with spaces but I was not successful.

From the link on how to add white space, it seems that this issue needs to be treated very carefully to allow rendering to complete as best-possible in multiple scenarios.

Update - My Homework : I received comment support from @Emil Jeřábek and also checked the Stack Exchange Overflow reference Aligning multiple equations in MathJax. Using the support and also the "Aligning multiple equations in MathJax, I updated the MathJax equation and now it renders as:

Updated Rendering From Jeřábek and the Aligning multiple equations Stack Exchange Overflow article

The MathJax text is as follows:

$$S_m =
\begin{cases}
\begin{aligned}
1, \quad \text{for m=} & 1\\
12, \quad \text{for m=} & 2\\ 
123, \quad \text{for m=} & 3\\
1234, \quad \text{for m=} & 4\\
12345, \quad \text{for m=} & 5\\ 
123456, \quad \text{for m=} & 6\\  
1234567, \quad \text{for m=} & 7\\
12345678, \quad \text{for m=} & 8\\
123456789, \quad \text{for m=} & 9\\ 
1234567890, \quad \text{for m=} & 10\\  
12345678901, \quad \text{for m=} & 11\\  
12345678901..., \quad \text{for m>} & 11\\
S_{m-1} \times 10 + (m \bmod 10), \quad \text{for m>} & 11\\ 
\end{aligned}
\end{cases}
$$

I saw in the Stack Overflow article Aligning multiple equations in MathJax that the recommended equation layout is as follows:

Recommended equation layout with space on both sides of the = sign

So I updated the layout as follows:

Updated layout using the referenced recommended equation layout

The updated MathJax text follows.

$$S_m =
\begin{cases}
\begin{aligned}
1, \quad \text{for m = } & 1\\
12, \quad \text{for m = } & 2\\ 
123, \quad \text{for m = } & 3\\
1234, \quad \text{for m = } & 4\\
12345, \quad \text{for m = } & 5\\ 
123456, \quad \text{for m = } & 6\\  
1234567, \quad \text{for m = } & 7\\
12345678, \quad \text{for m = } & 8\\
123456789, \quad \text{for m = } & 9\\ 
1234567890, \quad \text{for m = } & 10\\  
12345678901, \quad \text{for m = } & 11\\  
12345678901..., \quad \text{for m > } & 11\\
S_{m-1} \times 10 + (m \bmod 10), \quad \text{for m > } & 11\\ 
\end{aligned}
\end{cases}
$$

What is left to my question about how to format the sequence?

With the previously comments from @Emil Jeřábek, there was the recommendation that perhaps "begin{cases}" is not required, and he was surprised that this equation was rendering at all, if I understood his comment properly.

But for me, if I do not include the begin{cases} and end{cases} then the left bracket does not render at all (with FireFox).

The question still stands as to whether my MathJax updated text is the recommended route or if further MathJax text modifications are recommended or are necessary to prevent other rendering problems.

The only reference that I have found for the left bracket is here from the Stack Exchange Superuser Site Article "Using the cases environment in LyX" - for which Lyx is a LatTex front-end:

\begin{cases}
1st\\
2nd\\
3rd\end{cases}

In this MathJax environment, it renders as follows:

$$\begin{cases} 1st\\ 2nd\\ 3rd\end{cases}$$

I still have not found a reference for other techniques for casting the left bracket, but I hope that updated comments or answers might provide the referenced links (preferably from the Stack Exchange web-sites) to get a better idea of the Stack Exchange recommended practice.

What else is recommended or needed to render the equation properly under the multiple supported browsers?

$\endgroup$
7
  • 1
    $\begingroup$ @ Emil Jeřábek : Where I got the begin{aligned} is from Stack Overflow. I updated the equation using "1, \quad \text{for m=} & 1\\"... and it seems to render well. Thank you for your help. I am also attempting to update the question. The part that I am still not understanding : why Stack Overflow article recommending a different way of MathJax layout (45 positive votes), while I could not find the article mentioning your technique. Maybe answer well "Stack Exchange Aligning multiple equations in MathJax". $\endgroup$ Sep 7, 2023 at 7:21
  • 1
    $\begingroup$ If you took it from that answer, why didn’t you do it as in that answer, which is correct, and which is exactly what I recommended? (I have no idea what else do you mean by “my technique”.) It explains how to use & (including the fact that it goes in front of $=$ signs rather than after them). It does not suggest to omit the &, nor does it suggest mixing aligned with cases. $\endgroup$ Sep 7, 2023 at 8:27
  • 1
    $\begingroup$ By "your technique" I meant the use of "\left\{" and "\right." I tried a web-search for stack exchange \left\{ \right. and came up with nothing that seemed to be to be simple enough and relevant to understand. On the other hand, in my question, I included an independent link to "cases" usage. It is not to say that "your technique" is not good. Rather, I just am quickly starting out with something independently referenced and I might update it with your recommendation soon. Thank you for your suggestions, and your insistence that I use them! $\endgroup$ Sep 7, 2023 at 13:46
  • 1
    $\begingroup$ If you want to format things properly in MathJax, you should not write $\text{“for m=4”}$ (coded as \text{for m=4}) but rather $\text{“for } m = 4\text{”}$ (coded as \text{for } m=4). The thing that causes you to think that one font looks good and another looks terrible consists precisely of a large number of little things of just that kind. And Donald Knuth invented TeX (the ancestor of MathJax) with precisely that in mind. $$ \begin{align} \text{wrong: } & \text{for m=4} \\ \text{right: } & \text{for } m=4 \end{align} $$ $\endgroup$ Sep 8, 2023 at 23:22
  • 1
    $\begingroup$ Also, you should not write 12345678901..., but rather 12345678901\ldots. In LaTeX (as opposed to MathJax) the latter will appear as $12345678901\text{...}$ rather than $12345678901\ldots \qquad$ $$\begin{align} & 12345678901\text{...} \\ & 12345678901\ldots \end{align} $$ The first version above is incorrect. $\endgroup$ Sep 8, 2023 at 23:27
  • $\begingroup$ @EmilJeřábek, re, to the extent that there is an agreed-upon best practice, it is surely the one supported by the AMS's LaTeX packages; but there is no pure-LaTeX obstruction to having & after = instead of before, as long as you insert an atom: 1 ={} & 2. This has come in handy for me in non-artificial circumstances where putting the = where the AMS expects would have taken significant re-arrangement. $\endgroup$
    – LSpice
    Sep 28, 2023 at 23:28
  • $\begingroup$ Yeah, yeah, but that's a completely pointless complication here when all the alignments are on the $=$ signs. Thank you for confusing the matter for the OP even more, as he is obviously not confused enough already. $\endgroup$ Sep 29, 2023 at 5:09

2 Answers 2

3
$\begingroup$
  • The way you are supposed to use alignment environments like aligned, cases, align, etc., is that you put a & character on each line, at the places that should be aligned with each other.

  • There is hardly any point in using the cases environment if you replace its alignment facilities with another alignment environment. It’s more efficient to just put a big { there manually (which is effectively the only thing the cases environment will do in this case, anyway).

  • You need to enclose math material embedded in a \text{...} with $...$ to switch back to math mode:

$$S_m =
\left\{
\begin{aligned}
1,& \quad\text{for  $m=1$}\\
12,& \quad\text{for  $m=2$}\\ 
123,& \quad\text{for  $m=3$}\\
1234,& \quad\text{for  $m=4$}\\
12345,& \quad\text{for  $m=5$}\\ 
123456,& \quad\text{for  $m=6$}\\  
1234567,& \quad\text{for  $m=7$}\\
12345678,& \quad\text{for  $m=8$}\\
123456789,& \quad\text{for  $m=9$}\\ 
1234567890,& \quad\text{for $m=10$}\\  
12345678901,& \quad\text{for $m=11$}\\  
12345678901\dots,& \quad\text{for $m>11$}\\
S_{m-1} \times 10 + (m \bmod 10),& \quad\text{for $m>11$}
\end{aligned}
\right.
$$

$$S_m = \left\{ \begin{aligned} 1,& \quad\text{for $m=1$}\\ 12,& \quad\text{for $m=2$}\\ 123,& \quad\text{for $m=3$}\\ 1234,& \quad\text{for $m=4$}\\ 12345,& \quad\text{for $m=5$}\\ 123456,& \quad\text{for $m=6$}\\ 1234567,& \quad\text{for $m=7$}\\ 12345678,& \quad\text{for $m=8$}\\ 123456789,& \quad\text{for $m=9$}\\ 1234567890,& \quad\text{for $m=10$}\\ 12345678901,& \quad\text{for $m=11$}\\ 12345678901\dots,& \quad\text{for $m>11$}\\ S_{m-1} \times 10 + (m \bmod 10),& \quad\text{for $m>11$} \end{aligned} \right. $$

Alternatively, you can align on the $=$ signs as in the updated question. But then to make the formatting correct, you need to pull the whole$m=\dots$” outside the \text, and you need to put the alignment tabs in front of the $=$ sign, not after it (as the latter prevents TeX from properly formatting $=$ as a binary relation symbol, resulting in wrong spacing):

$$S_m =
\left\{
\begin{aligned}
1, \quad\text{for } m&=1\\
12, \quad\text{for } m&=2\\ 
123, \quad\text{for } m&=3\\
1234, \quad\text{for } m&=4\\
12345, \quad\text{for } m&=5\\ 
123456, \quad\text{for } m&=6\\  
1234567, \quad\text{for } m&=7\\
12345678, \quad\text{for } m&=8\\
123456789, \quad\text{for } m&=9\\ 
1234567890, \quad\text{for } m&=10\\  
12345678901, \quad\text{for } m&=11\\  
12345678901\dots, \quad\text{for } m&>11\\
S_{m-1} \times 10 + (m \bmod 10),& \quad\text{for } m&>11
\end{aligned}
\right.
$$

$$S_m = \left\{ \begin{aligned} 1, \quad\text{for } m&=1\\ 12, \quad\text{for } m&=2\\ 123, \quad\text{for } m&=3\\ 1234, \quad\text{for } m&=4\\ 12345, \quad\text{for } m&=5\\ 123456, \quad\text{for } m&=6\\ 1234567, \quad\text{for } m&=7\\ 12345678, \quad\text{for } m&=8\\ 123456789, \quad\text{for } m&=9\\ 1234567890, \quad\text{for } m&=10\\ 12345678901, \quad\text{for } m&=11\\ 12345678901\dots, \quad\text{for } m&>11\\ S_{m-1} \times 10 + (m \bmod 10), \quad\text{for } m&>11 \end{aligned} \right. $$

$\endgroup$
7
  • 1
    $\begingroup$ Please see my updated question with my new "homework-what I have tried to do to resolve the issue, but I am not completely successful". I think that the 1 should be directly left aligned against the equal sign, as with the 10 and 11. With your recommended MathJax text, the "begin{cases}" and "end{cases}" are left out. On my FireFox browser, when I test that, it drops the left bracket. So there is no confusion, please update your answer and answer Aligning multiple equations in MathJax also without {. $\endgroup$ Sep 7, 2023 at 7:51
  • 1
    $\begingroup$ If you want the numbers left-aligned, why did the question ask them to be right-aligned? This is the root of all trouble. It's easier for them to be left-aligned, as that is the natural formatting. Just omit all the \phantom stuff. $\endgroup$ Sep 7, 2023 at 7:54
  • 1
    $\begingroup$ The big { is perfectly standard MathJax, it is what \begin{cases}..\end{cases} does under the hood, and it renders fine in Firefox. If it does not work in your environment, something else is amiss with your font set-up or some such. Also try to bypass the cache. $\endgroup$ Sep 7, 2023 at 8:13
  • 1
    $\begingroup$ What does these "\left\{" and "\right." do with MathJax? I am accustomed with parenthesis to have "\left( ...\right)"; and for "\left(" it must have "\right)" to render under MathJax. But when I attempt a web-search for Stack Exchange MathJax "\right." I come up with nothing that I find relevant. If you could update your answer with an answer with a reference (preferably from a Stack Exchange website link) that could sort out my lack of understanding of the MathJax text. Also, with the alignment, it is important that the "for m = " and "for m > " signs are right-aligned as updated. $\endgroup$ Sep 7, 2023 at 8:25
  • 2
    $\begingroup$ In TeX (and MathJax), “.” serves as a dummy delimiter in \left or \right that matches the corresponding other delimiter, but renders empty. See e.g. tex.stackexchange.com/a/77593 . $\endgroup$ Sep 7, 2023 at 8:33
  • 1
    $\begingroup$ The “for $m={}$” signs are right-aligned because they are adjacent to a first (i.e., odd-numbered) & on the given line. This has nothing to do with whether the & is put in front or after the $=$. This position has no bearing on the alignment of the $=$’s as all the $=$ signs have (obviously) identical width, but putting the & after the $=$ breaks the spacing around $=$ as it is then not recognized as a binary relation symbol. $\endgroup$ Sep 7, 2023 at 8:44
  • 1
    $\begingroup$ I tried to upvote your answer just now because your support has been both thought-provoking (in a positive sense) as well as complete (to the extent that I am learning a lot about MathJax from your response). However, I still do not have enough reputation for the upvote to count. Thank you so much in any case! $\endgroup$ Sep 7, 2023 at 8:55
1
$\begingroup$

Try & and \phantom{0}:

$$
\newcommand{\nc}{\phantom{0}}
S_m =
\begin{cases}
\begin{aligned}
1&, \quad\text{for }  m=\nc1\\
12&, \quad\text{for }  m=\nc2\\ 
123&, \quad\text{for }  m= \nc3\\
1234&, \quad\text{for } m= \nc4\\
12345&, \quad\text{for } m= \nc5\\ 
123456&, \quad\text{for } m= \nc6\\  
1234567&, \quad\text{for } m= \nc7\\
12345678&, \quad\text{for } m= \nc8\\
123456789&, \quad\text{for } m= \nc9\\ 
1234567890&, \quad\text{for } m=10\\  
12345678901&, \quad\text{for } m=11\\  
12345678901...&, \quad\text{for } m>11\\
S_{m-1} \times 10 + (m \bmod 10)&, \quad\text{for }m>11\\ 
\end{aligned}
\end{cases}
$$

$$ \newcommand{\nc}{\phantom{0}} S_m = \begin{cases} \begin{aligned} 1&, \quad\text{for } m=\nc1\\ 12&, \quad\text{for } m=\nc2\\ 123&, \quad\text{for } m= \nc3\\ 1234&, \quad\text{for } m= \nc4\\ 12345&, \quad\text{for } m= \nc5\\ 123456&, \quad\text{for } m= \nc6\\ 1234567&, \quad\text{for } m= \nc7\\ 12345678&, \quad\text{for } m= \nc8\\ 123456789&, \quad\text{for } m= \nc9\\ 1234567890&, \quad\text{for } m=10\\ 12345678901&, \quad\text{for } m=11\\ 12345678901...&, \quad\text{for } m>11\\ S_{m-1} \times 10 + (m \bmod 10)&, \quad\text{for }m>11\\ \end{aligned} \end{cases} $$

$\endgroup$
1
  • $\begingroup$ This was in my answer, until the OP clarified that he actually wants these numbers left-aligned rather than right-aligned. $\endgroup$ Sep 29, 2023 at 5:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .