I want to draw the following tree in a question. But, I don't want to upload a picture. Can anyone tell me how to do it using MathJax?
1 Answer
It can be done in MathJax, but it is painful and a complete hack. Here is one way:
\require{enclose}
\def\uline#1#2{\enclose{updiagonalstrike}{\phantom{\Rule{#1em}{#2em}{0em}}}}
\def\dline#1#2{\enclose{downdiagonalstrike}{\phantom{\Rule{#1em}{#2em}{0em}}}}
%
\def\place#1#2#3{\smash{\rlap{\hskip{#1em}\raise{#2em}{#3}}}}
%
\hskip 1em
%
\place{0}{12}{\bullet}
\place{2}{0}{\bullet}
\place{4}{4}{\bullet}
\place{6}{0}{\bullet}
\place{8}{8}{\bullet}
\place{10}{0}{\bullet}
\place{12}{4}{\bullet}
\place{14}{0}{\bullet}
\place{16}{12}{\bullet}
%
\place{.3}{4.4}{\dline{3.6}{7.6}}
\place{2.3}{.5}{\uline{1.6}{3.6}}
\place{4.3}{.4}{\dline{1.6}{3.6}}
\place{4.3}{4.4}{\uline{3.6}{3.7}}
\place{8.3}{4.4}{\dline{3.6}{3.6}}
\place{10.3}{.5}{\uline{1.6}{3.6}}
\place{12.3}{.4}{\dline{1.6}{3.6}}
\place{12.2}{4.4}{\uline{3.7}{7.6}}
%
\place{-1}{12.5}{\frac01}
\place{1}{-.5}{\frac13}
\place{2.75}{4}{\frac12}
\place{6.5}{-.5}{\frac23}
\place{7.75}{9.5}{\frac11}
\place{9}{-.5}{\frac32}
\place{12.75}{4}{\frac21}
\place{14.5}{-.5}{\frac31}
\place{16.5}{12.5}{\frac10}
%
\hskip18em\Rule{0em}{14em}{1.5em}
which produces
$$ \require{enclose} \def\uline#1#2{\enclose{updiagonalstrike}{\phantom{\Rule{#1em}{#2em}{0em}}}} \def\dline#1#2{\enclose{downdiagonalstrike}{\phantom{\Rule{#1em}{#2em}{0em}}}} % \def\place#1#2#3{\smash{\rlap{\hskip{#1em}\raise{#2em}{#3}}}} % \hskip 1em % \place{0}{12}{\bullet} \place{2}{0}{\bullet} \place{4}{4}{\bullet} \place{6}{0}{\bullet} \place{8}{8}{\bullet} \place{10}{0}{\bullet} \place{12}{4}{\bullet} \place{14}{0}{\bullet} \place{16}{12}{\bullet} % \place{.3}{4.4}{\dline{3.6}{7.6}} \place{2.3}{.5}{\uline{1.6}{3.6}} \place{4.3}{.4}{\dline{1.6}{3.6}} \place{4.3}{4.4}{\uline{3.6}{3.7}} \place{8.3}{4.4}{\dline{3.6}{3.6}} \place{10.3}{.5}{\uline{1.6}{3.6}} \place{12.3}{.4}{\dline{1.6}{3.6}} \place{12.2}{4.4}{\uline{3.7}{7.6}} % \place{-1}{12.5}{\frac01} \place{1}{-.5}{\frac13} \place{2.75}{4}{\frac12} \place{6.5}{-.5}{\frac23} \place{7.75}{9.5}{\frac11} \place{9}{-.5}{\frac32} \place{12.75}{4}{\frac21} \place{14.5}{-.5}{\frac31} \place{16.5}{12.5}{\frac10} % \hskip18em\Rule{0em}{14em}{1.5em} $$
It allows you to define an abstract grid on which you place the items you want (bullets for dots, fractions, and diagonal lines created using the enclose
package). I also use \hskip
and \Rule
to define the size of the complete diagram, and an \hskip
at the front to compensate for the use of -1
for the left-most labels.
Anyway, you can make these kinds of diagrams with some effort.
-
3$\begingroup$ I'd like to mention this doesn't work on the iOS app $\endgroup$– KoAApr 22, 2016 at 5:28
-
$\begingroup$ The numbers after place, for example \place{2}{0} are relative coordinates with respect to previous position? Or are they absolute coordinates? $\endgroup$ Apr 22, 2016 at 7:54
-
1$\begingroup$ @shieldbug1 And I can confirm that it does not render correctly on the mobile version of the site, using iOS's Safari (but switching to the "full site" in Safari still, it does work). Very interesting answer, either way! $\endgroup$– pjs36Apr 22, 2016 at 12:29
-
1$\begingroup$ @MartinSleziak, they are absolute with respect to the lower left-hand corner of the graph. $\endgroup$ Apr 22, 2016 at 13:10
-
1$\begingroup$ Thx for this great hack. $+1$ The diagram flooted on the code out of the screen though. $\endgroup$ Dec 4, 2018 at 5:05
-
$\begingroup$ Here's what it looks like on an Android phone; viz., a ZTE Blade V8. $\endgroup$– ShaunDec 9, 2018 at 2:13
-
1$\begingroup$ Here's what it looks like on the same phone but using the desktop site. $\endgroup$– ShaunDec 9, 2018 at 2:15
amscd
) available for use on the website. $\endgroup$