# MathJax exposed

WARNING   $\color{red}{\boxed{\boxed{ \sf ~~{ \large N \, S \, F \, P \rlap{\small P\&CG~SE} }~~~ \huge\raise-.2ex\strut }}} \kern2em$   NOT SUITABLE FOR Programming Puzzles & Code Golf SE

Ain’t it so true that the best MathJax hacks are vanishingly modest?   Not at this puzzle!

Let’s find the shortest answer that is pure MathJax and unabashedly bares all.

•   Begins with the line   \require{begingroup}\begingroup (safety first) • Has no line longer than 77 characters • Renders entirely in a single size of MathJax’s typewriter font ( \small \texttt{\\tt}~ or \small~\texttt{\\texttt{...}} ) • Lays out and reads exactly the same when rendered and when shown in the edit frame, like a quine, including the first and last lines specified here as well as alignment and spacing • Spells out its own length, somewhere, formatted like \small~\texttt{LENGTH = 123}~ with space on the left and right of  \small \tt LENGTH  and  \small \tt 123  each • Ends with the line \endgroup   (again, for safe MathJax)

Spaces and line breaks are encouraged for readability, so they do not count in measuring length. Remember that $\small \texttt {\tt}$ produces the wrong font for some symbols, such as $\small ~\tt \{ ~ \} ~$ braces, which should look like $\small ~\texttt { { } }~$ as produced by $\small ~\texttt{\texttt{ { } }}$ .

Admittedly, the audience for this puzzle is small. Please share any answer that even almost works. No way to spoilerize multi-line MathJax here but who cares, this puzzle is about letting it all hang out.

NOTE ☆ Before posting an answer, be sure to test it on a freshly loaded browser page ☆ Might also need to reload the page while editing, as inadvertent indiscretions in one edit can pervert MathJax results during later edits ☆

• Not MathJax specifically, but there's a question on TeX quines here. – f'' Jul 12 '16 at 13:13
• This seems to be a MathJax promoting tour :c) I guess you have a 77 chars solution, right? – BmyGuest Jul 12 '16 at 14:53
• Looks like MathJax has to go in completely different directions than the solutions at (La)TeX SE.Those approaches rely on unavailable features (unless some can be $\small\texttt{\require{}}$d?). Far as I know, MathJax has to use $\small\texttt{\begin{array}}$ or \small\texttt{\begin{align}} just to simulate a text margin. – humn Jul 13 '16 at 9:54
• MathJax can also produce a straight margin with $\small \texttt{\matrix{...}}$ (or $\small \texttt{\begin{matrix}}$) and $\small \texttt{\hfil}$, as in Davide Cervone's solution, or by right-padding with $\small \texttt{ \phantom{...}}$. Beware, though, $n$ consecutive spaces do not seem to be rendered $n$ times as wide as a single space. – humn Jul 14 '16 at 6:31

Here's a shorter version that improves on my earlier answer (below). One of the places where there is a lot of redundancy is in the initial definitions that had to be repeated in the \D...\D block for printing. I wondered if it would be possible to have the code for printing also be executed so that it would not have to be duplicated. This gives the following:
$$\require{begingroup}\begingroup \def\<#1:#2>{\matrix{#1#2\T{#1:}#2\E}} \< \def\C#1;{#1} \def\T#1{\text{#1}\hfil\cr\tt} : \C \def\S{\unicode{36}} \tt\S\S\T{\require{begingroup}\begingroup} ; \C \T{\def\<#1:#2>{\matrix{#1#2\T{#1:}#2\E}}} ; \C \def\E{\T>\text\endgroup\S\S\hfil} % LENGTH = 316 ; \C { \def\C#1;{\T{\C #1;}} } \T\< ; > \endgroup$$
Here, we need one definition to handle the printing of duplicates (the \<#1:#2> macro), so this is the only one that needs to be duplicated (along with the \require{begingroup}\begingroup and \endgroup). The #1 from this macro is code to be executed right away (to define the other macros that are needed internally), and it is explicitly turned into a printed line when it is repeated. The other code (#2) gets executed after the #1 definitions are in place and is repeated a second time, after the first invocation changes the definitions of the key macro, \C, which is for code that is executed on the first pass, and printed on the second. The \T macro is for printing a line.