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 ☆
MathJax linx (feel free to add)
MathJax reflex (puzzle)
Starring MathJax (puzzle)
Defining macros in MathJax
$\sf\scriptsize \raise2mu( L \raise4mu{\tiny A} \kern2mu \raise2mu) {\small T} \kern-1mu \raise-4mu E \kern2mu X$ commands in MathJax
$\sf\scriptsize {\small T} \kern-1mu \raise-4mu E \kern2mu X$ commands available in MathJax
MathJax reference at Mathematics Meta
MathJax questions at Meta SE | Physics Meta | Puzzling Meta | Mathematics Meta
Answer
New Answer
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.
The first call to \C defines \S
for the dollars, and prints the opening line. The next \C
prints the definition of \<#1:#2>
that is the second line. The third \C
defines the \E
used in \<#1:#2>
to print the ending lines (the >
and \endgroup$$
). The last \C
redefines \C
to print itself (so that during the second pass, the code prints itself verbatim), and prints the \<
line. We have to put the redefinition in braces so that it's ;
won't end the \C
for that line.
We use \C#1;
rather than \C{#1}
in order to save a character per line (the opening brace, since spaces don't count against us).
The \tt
font is added to each row automatically by the \T
macro (and the initial row has it explicitly before the \S\S
). The \text
macro will pick up the current font, so we save a couple of characters with this trick.
You can reduce the character and line count slightly by moving the \<
and >
to adjacent lines, shifting the \C
lines around a bit, moving the \T
from the definition of \<#1:#2>
into the last \C
, and not using the ;
with \C
, since there are too few to make that an advantage, at the loss of some readability, to come in at 307 characters and 7 lines.
$$\require{begingroup}\begingroup \def\<#1:#2>{\matrix{#1#2{#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{#1:}#2\E}} \<} % LENGTH = 307 } \C{ \def\E{>\text\endgroup\S\S\hfil} \def\C#1{\T{\C{#1}}} \T } > \endgroup$$
I think that is as far as I will go.
Initial Answer
Here's a version that is slightly shorter than humn's, and uses a somewhat different approach to the duplication. It uses \matrix{}
rather than \begin{array}...\end{array}
to save space, and \hfil
to make the lines align flush left. Since humn didn't count spaces or line breaks in the character count, I left them out of mine as well.
$$\require{begingroup}\begingroup % LENGTH = 463 \def\S{\tt\unicode{36}} \def\N{\hfil\cr} \def\E{\texttt{\endgroup}} \def\R#1{\texttt{#1}\N} \def\T#1{\R{\L{#1}}} \let\L=\R \def\D#1\D{\matrix{\S\S#1 \R\D \let\L=\T #1 \R\D \E\S\S\N}} \D \L{\require{begingroup}\begingroup} \L{% LENGTH = 463 } \L{\def\S{\tt\unicode{36}} \def\N{\hfil\cr} \def\E{\texttt{\endgroup}}} \L{\def\R#1{\texttt{#1}\N} \def\T#1{\R{\L{#1}}} \let\L=\R} \L{\def\D#1\D{\matrix{\S\S#1 \R\D \let\L=\T #1 \R\D \E\S\S\N}}} \D \endgroup$$
No comments:
Post a Comment