# Drawing Super Mario Bros…in LaTeX

There are several questions about TeX.SE. that concern designs for recurrences such as fireworks, lunar calendar, the pi-greek, and into my mind I'm remembering a protagonist of an old video game: Super Mario Bros.

But is it possible to make detailed drawings of the protagonists of video games with LaTeX?

I'm just curious to see only how the users build Super Mario Bros. Thank you everyone.

• Why would you do that in TeX? – cfr Oct 2 '19 at 23:01
• @cfr cwac! Miss you! – Paulo Cereda Oct 3 '19 at 13:02
• @PauloCereda Cwac! – cfr Oct 3 '19 at 16:32
• As you Know my answer is here. – vi pa Oct 4 '19 at 8:53
• I need to think of questions like these to get my reputation boosted.... – jvriesem Oct 5 '19 at 17:05

## 5 Answers

What if Mario and Luigi are going to a party? Somebody said that they love ducks!!

From The TikZducks package

MWE

\documentclass[border=2mm]{standalone}
\usepackage{xcolor}
\usepackage{tikzducks}

\newcommand{\superstripes}{\stripes[color=blue!80!black,width=3,height=1.0,rotate=5] \stripes[color=blue!80!black,width=0.1,rotate=0,distance=0.7,initialx=-1.1,height=2]}

\begin{document}

\begin{tikzpicture}
\duck[tshirt=red!80!black,peakedcap=red!80!black,stripes={\superstripes}]
\fill[white] (0.8,2) circle (0.13);
\node[red!80!black,rotate=-25] at (0.8,2) {\scalebox
{0.6}{\textsf{M}}};
\end{tikzpicture}
\begin{tikzpicture}
\duck[tshirt=green!70!black,peakedcap=green!70!black,
stripes={\superstripes}]
\fill[white] (0.8,2) circle (0.13);
\node[green!70!black,rotate=-25] at (0.8,2) {\scalebox
{0.6}{\textsf{L}}};
\end{tikzpicture}
\end{document}


• Seeing the question, I felt confident that tikzducks would be rolled out. You did not disappoint. – Steven B. Segletes Oct 3 '19 at 1:24
• Thank you for your invaluable cooperation and your collaboration. – Sebastiano Oct 6 '19 at 19:16
• @Sebastiano, you are welcome. – Sigur Oct 7 '19 at 12:14

As everyone knows, the game was released in 1985, and at that time LaTeX was just making it out into the world and there was no such thing as pdfTeX, let alone TikZ and other fancy systems, so what Nintendo had to make the pictures was Knuth's TeX only.

They needed an efficient way to make the pictures, so they obviously didn't have the time to write all those coordinates, so they resorted to a syntax which was easy to draw each frame of the game, like this:

\beginmario
..=====....
.=========.
.---@@-@...
-@-@@@-@@@.
-@--@@@-@@@
--@@@@----.
..@@@@@@@..
.==+===....
===+==+===.
===++++====
@=+@++@+=@@
@@++++++@@@
@++++++++@@
.+++..+++..
---....---.
---....----
\endmario


to produce:

So they used something like this:

\input color.tex
\newtoks\marioactives
\def\newmariocolor#1#2#3{%
\definecolor{M#2}{rgb}{#3}%
\expandafter\def\csname MarioSquare#1\endcsname
{\begingroup\color{M#2}\MarioBox}%
\marioactives\expandafter{\the\marioactives\mkactive{#1}}}
\newdimen\unitlength
\newdimen\rulesize
\newcount\therow
\newcount\thecol
\def\MarioBox{\leavevmode\raise\therow\unitlength
\hbox to 0pt{\kern\thecol\unitlength\DrawBox\hss}%
\endgroup\advance\thecol 1 \ignorespaces}
\def\DrawBox{\leavevmode\hbox{\vrule width\rulesize height\rulesize}}
\def\mkactive#1{%
\catcode#1=13\relax
\begingroup\lccode~=#1\lowercase{\endgroup
\expandafter\let\expandafter~}\csname MarioSquare#1\endcsname}
{\catcode\^^M=13
\gdef\beginmario{%
\begingroup
\catcode\ =9
\catcode\^^M=13
\def^^M{\advance\therow-1 \thecol 0 }%
\rulesize\unitlength
\advance\rulesize 0.1pt
\the\marioactives}%
\gdef\endmario{\endgroup}%
}

\newmariocolor{=}{red}{1,0,0}
\newmariocolor{+}{blue}{0,0.15,1}
\newmariocolor{@}{yellow}{1,0.65,0}
\newmariocolor{-}{brown}{0.5,0.1,0}
\newmariocolor{.}{white}{1,1,1}
\unitlength=5pt

\beginmario
..=====....
.=========.
.---@@-@...
-@-@@@-@@@.
-@--@@@-@@@
--@@@@----.
..@@@@@@@..
.==+===....
===+==+===.
===++++====
@=+@++@+=@@
@@++++++@@@
@++++++++@@
.+++..+++..
---....---.
---....----
\endmario

\bye

• Unbelievable!!!! Did you already known this solution, right? Or did you create this just now? – Sigur Oct 2 '19 at 23:33
• @Sigur I never worked for Nintendo, if that's what you're asking ;-) (yes, I wrote it now :-) – Phelype Oleinik Oct 2 '19 at 23:35
• Ow, I was asking the second. Amazing how fast you wrote the code. Congs. – Sigur Oct 2 '19 at 23:37
• @Sigur Actually the \MarioBox above is a modified version of LaTeX's \put, and \DrawBox is almost the same as \rule. The rest are funny catcode settings to obfuscate the code ;-) – Phelype Oleinik Oct 2 '19 at 23:39
• Simply excellent the story... and the code. – Sebastiano Oct 6 '19 at 19:16

Like Sigur, I am also convinced this is an XY question. Probably Italian autocorrection replaced marmot my Mario, right? ;-)

\documentclass[border={1cm 3.14mm 1cm 3.14mm}]{standalone}
\usepackage{tikzlings} % https://ctan.org/pkg/tikzlings
\begin{document}
\begin{tikzpicture}
\marmot[whiskers,teeth,3D,shadow]
\fill[top color=blue!70,bottom color=blue,shading angle=-30]
(-0.56,1.35) to[out=-10,in=190] (0.56,1.35)
to[out=-80,in=85] (0.58,0.6) to[out=-175,in=-5] (-0.58,0.6)
to[out=95,in=-100] cycle;
\shade[ball color=brown!50!black,rotate around={70:(0.385,0.93)}] (0.385,0.93) ellipse (0.24 and 0.13);
\shade[ball color=brown!50!black,rotate around={-70:(-0.385,0.93)}] (-0.385,0.93) ellipse (0.24 and 0.13);
\draw[red,thick,fill=yellow] (-0.1,1.2) -- (-0.25,1.05) -- (0,0.7) -- (0.25,1.05) --
(0.1,1.2) -- cycle;
\node[font=\sffamily\bfseries,text=red] at (0,1) {S};
\end{tikzpicture}
\end{document}


• Actually I expected reply from you....and you fulfilled....Great.... – MadyYuvi Oct 4 '19 at 12:32
• Put a raccoon tail on it and it might look like Mario in the tanuki suit as seen in Super Mario Bros. 3. – Renan Oct 4 '19 at 14:22

With ducksay package:

\documentclass{article}
\usepackage{ducksay}

\AddAnimal{luigi}
{
,-"-.
/     :
'   ,- |
|  | L|---.
.   ,'     |
|   / _  _  |
,|  /."_ "."/
| ' :  ( || |
\  |b  D| b|.-.
,--8b     "   )
| _     d._ -'
'.     YCGMMP
""\    " |"
\    /
|__|
}

\begin{document}

\ducksay[animal=luigi]{I'm luigi}

\end{document}


Not exactly Mario, but close enough. You'll need to download the Super Mario 256 font and compile this with XeTeX or LuaTeX.

\documentclass{article}
\usepackage{fontspec}
\usepackage{xcolor}
\usepackage{relsize}
\newfontfamily\mario{SuperMario256.ttf}
\newcommand\marioltr[2]{{%
\mario \sbox0{#1}\sbox2{\larger#1}%
\dimen0=\dimexpr(\wd2-\wd0)/2\relax
\dimen2=\dimexpr\ht2-\ht0\relax
\leavevmode \kern-\dimen0\lower\dimen2 \rlap{\unhbox2}\kern \dimen0
\textcolor{#2}{#1}}}
\newcommand\textmario[2]{%
\textmarioAUX#1{}\relax\textmarioAUXX#2{}\relax\stop}
\newcommand\textmarioAUX{}
\def\textmarioAUX#1#2\textmarioAUXX#3#4\stop{%
\stopifempty{#1}\stopifempty{#3}%
\marioltr{#1}{#3}\textmarioAUX#2\textmarioAUXX#4\stop}
\newcommand\stopifempty[1]{%
\if\relax\detokenize{#1}\relax\stopmario\fi}
\newcommand\stopmario{}
\def\stopmario#1\stop{\fi}
\newcommand\mariologo{{%
\sbox0{\textmario{SUPER}{byrgy}}%
\sbox2{\larger\textmario{MARIO}{rgybg}}%
\dimen0=\dimexpr(\wd2-\wd0)/2\relax
\leavevmode \vbox {\hsize=\wd2 \parindent=0pt
\leavevmode \kern\dimen0 \box0 \par\nointerlineskip
\leavevmode \ht2=0.9\ht2 \box2}}}
\newcommand\makeHTMLcolors[1]{%
\ifx\relax#1 \else\expandafter\makeHTMLcolorAUX \fi{#1}}
\newcommand\makeHTMLcolorAUX[2]{\definecolor{#1}{HTML}{#2}\makeHTMLcolors}
\makeHTMLcolors b{049CD8}y{FBD000}r{E52521}g{43B047}\relax
\begin{document}
\mariologo
\end{document}

• Wow...thank you so much...for a happy new year...and for your nice answer. Thank you very much again. – Sebastiano Jan 1 at 12:41
• You're welcome @Sebastiano! I fixed the code: the previous version had some problems when using the logo inline with other text – The Drunken Whaler Jan 2 at 14:09