I think the questions says it all! :)

By TeX, I mean any derivative of TeX as long as the code is clearly a derivative of TeX, i.e. that it could belong on TeX.SX (and not pure Lua for example).

I'll give two answers myself so you see what I mean.


16 Answers 16


I think that Steve Hicks controller for a Mars Rover programmed in TeX is a good candidate: ICFP Contest 2008 - Mars rover in TeX.

  • 4
    The writeup for this one is epic, as such tales usually are.
    – Ryan Reich
    Commented Mar 25, 2013 at 20:09
  • 1
    Sadly the link is not accessible at least from my area :(
    – user156344
    Commented Mar 26, 2019 at 15:18
  • @JouleV The link still works for me, and the article is still worth reading. Maybe the site was temporarily unavailable? Commented Mar 26, 2019 at 19:38
  • @MartinHeller .dk is a Denmark domain AFAIK. So it may be not accessible from some countries.
    – user156344
    Commented Mar 27, 2019 at 4:48

Adding coffee stains to your documents

If my documents don't have those stains, my boss / students think(s) I don't drink coffee. If he or they think I am not drinking coffee, they believe I am slacking. Thanks Hanno!

  • 8
    Great! I need it. I didn't find the package on CTAN - would be nice, if it would be part of TeXLive.
    – knut
    Commented Mar 25, 2013 at 20:05

David Carlisle's Christmas 'card' at http://www.ctan.org/pkg/xii. In fact, here it is: run this through plain TeX:

Fjfi71PAVVFjbigskipRPWGAUU71727374 75,76Fjpar71727375Djifx
RrhC?yLRurtKFeLPFovPgaTLtReRomL;PABB71 72,73:Fjif.73.jelse
B73:jfiXF71PU71 72,73:PWs;AMM71F71diPAJJFRdriPAQQFRsreLPAI
I71Fo71dPA!!FRgiePBt'el@ lTLqdrYmu.Q.,Ke;vz vzLqpip.Q.,tz;
;Lql.IrsZ.eap,qn.i. i.eLlMaesLdRcna,;!;h htLqm.MRasZ.ilk,%
s$;z zLqs'.ansZ.Ymi,/sx ;LYegseZRyal,@i;@ TLRlogdLrDsW,@;G
LcYlaDLbJsW,SWXJW ree @rzchLhzsW,;WERcesInW qt.'oL.Rtrul;e
doTsW,Wk;Rri@stW aHAHHFndZPpqar.tridgeLinZpe.LtYer.W,:jbye

A good collection of Enjoy TeX pearls diving! at GUST, Polish TeX Users Group

For more Pearls of TeX programming at TUGboat ,Volume 26 (2005), No. 3.

  • 7
    Could anyone please explain how it works? Commented Mar 25, 2013 at 20:11
  • 14
    @percusse I think Uwe meant how common mortals are supposed to understand David's code. I know: we're not :)
    – Xavier
    Commented Mar 25, 2013 at 20:17
  • 18
    @UweZiegenhagen It's just a typical plain TeX file, the syntax is slightly different to the LaTeX syntax that's more commonly seen here. Commented Mar 25, 2013 at 20:55
  • 10
    If your French is better than mine... groups.google.com/forum/?hl=fr&fromgroups=#!topic/… Commented Mar 25, 2013 at 21:21
  • 2
    For something similar, and a detailed explanation of the code, see Can you explain how this code works?
    – Werner
    Commented Mar 29, 2013 at 19:53

a basic interpreter written in tex.

see the tugboat article.

  • 2
    Does it support Commodore Basic? My Dad could run the program he typed up on the C64 to play Star Fleet battles on it!
    – Canageek
    Commented Mar 25, 2013 at 18:59

Our own Bruno LeFloch who wrote a Reversi game which runs in the console:

(Please don't try to reformat the code displayed below unless you really know what you are doing; if you do attempt a reformat, try to compile the resulting code before replacing the code here.)

% !TEX TS-program = tex
~QSU_VWJKLMNO@XY[](|+Z'"z:qj^;/)!,\ ${*13\3}
~+{\count1}+1=9~_#1{@+1 1\countdef#1+1_}_QJVSKWUL,'"$\H!_-1'1"2+44'+55'+45"+54"~^{+NQNJ}
~M#1{Y{#1}#1}~\h#1#2{M#2:{ \q#1}&M#2&M{*}}~\q#1#2{&M{(+#1#2  O-O0]}}
~/{Y{Row and column? e.g. E6*}\read_to\MX\j\meaning\M  ;}
~\j#1->#2#3#4;{Q`#2@Q-`@J`#3@J-`0;(VY{Invalid move.}
/]}~;{V0 (jS1z1z0z_S0z1z_S_z1z0z_]}~\_{@,('O-]}
~\&{!\^Q\multiply!3@!\^J@V(!9O1O6O1O1O2O6O2O4] }~\Z{M :{&M}&M{*}}
~){'X"X"N'\halign{&## *M{*}
\vfil\break$1W(W_|0] :\,$0 [0<W[1='QUJL|/];^'\_1][_=WM
{(,Tie| Player [0>,-|0] wins by N[0>,-],].}X\end])})
  • 1
    It is – intentionally, of course – named reverxii in reminescence to David Carlisle. Just compare Peter Flynn’s answer here.
    – Speravir
    Commented Mar 26, 2013 at 16:47
  • 3
    I don't know why it's taken me so long to run this through... this is absolutely insane. Why? Why? Commented Dec 30, 2013 at 12:45
  • 1
    Side effect, you get a play history printed on the resulting PDF/DVI. ■ (I wonder what algorithm the bot uses. The bot is actually pretty good, almost beat me the time I try.)
    – user202729
    Commented Jul 10, 2022 at 5:32

I once spent hours learning enough TeX to format my ex-gf's resume for printing on the computing center laser printer (back when laser printing was magical) and used up most of my monthly laser printing quota printing copies of it -- all under the mistaken belief that she'd see that she was crazy to break up with me.

Not surprisingly, it turned out to be a useless waste of my time (and in retrospect, it was me that should have broken up with her). Worse, word got around that I was a "TeX expert" and I ended up spending the rest of my computer center operator job helping grad students format their theses

  • 5
    Sorry, but this not an answer to the spirt of the question.
    – Speravir
    Commented Mar 26, 2013 at 17:26
  • 9
    Maybe I misunderstood the {fun} tag
    – Johnny
    Commented Mar 26, 2013 at 17:40
  • 51
    @Speravir: I'm not sure about the "spirit of the question", but for me, using TeX for making a gf regret breaking up definitely counts.
    – mbork
    Commented Mar 26, 2013 at 18:57
  • 74
    Well, I actually once met a nice girl because she needed help formatting her thesis and was told I was a "TeX expert". She's now my wife, and we had our first child 6 months ago :)
    – Xavier
    Commented Mar 26, 2013 at 21:12
  • 6
    @Xavier Shouldn't there be a word for it... like "TeXpert"? Commented Jul 7, 2013 at 20:53

Solving a non-linear equation

Not typesetting the solution (actually, also typesetting the solution of course :)), but more bizarrely implementing the bisection and secant non-linear solvers in TeX!

  • You know, I am at this moment wondering whether there is an easy way to graph some trajectories of a nonlinear system of ODEs in pgfplots. Obviously, my search is ended. (Oh, this only does algebraic equations. Boooo!)
    – Ryan Reich
    Commented Mar 25, 2013 at 20:11
  • @RyanReich: You may have a look at ctan.org/tex-archive/graphics/pstricks/contrib/pst-ode . Though I must admit that the actual calculation is done by your Postscript printer rather than by TeX.
    – AlexG
    Commented May 21, 2013 at 11:30

This one is probably my best:

But there are a few of them scattered around on this site. Here are my picks:

... and, as a bonus:

I really don't see why someone would go back to MS Office after using LaTeX... Now that's weird! ;)

EDIT: and i just remembered this one (Why facebook implemented it? But why recreate it in LaTeX? ;)):

  • I am the originator of the "How should I convert my slides to PowerPoint...?" question and if you read it you will note that it was not my desire to back to MS Office. But I'm glad the question has achieved a measure of notoriety. Commented Mar 27, 2013 at 2:16
  • @MatthewLeingang: I know you were forced into it. Nevertheless, it was a weird thing to do IMHO and I'm only happy to advertise it. :)
    – Count Zero
    Commented Mar 29, 2013 at 21:49
  • 1
    and years later, I can add that I use beamer, but some of my users want to modify the slides and only know word. yikes. so I have to maintain both.
    – ivo Welch
    Commented Mar 13, 2017 at 21:55

Calculating π with TeX

Gen­er­ates π, us­ing the for­mula


and leaves the re­sult in an ar­ray \xr, print­ing what it’s cal­cu­lated as it goes along.


Well, as made famous by a question of mine I have used LaTeX to make to make props for a Call of Cthulhu game. I also posted the finished product on my blog.

Then later on I used the same technique to make my teaching assistant's life a bit more interesting


Implementing the bisection method (and other numerical methods) in TikZ,
for exposition purposes.

EDIT: Great thanks to percusse for helping me improve my \ifg command.

enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here



\setbeamertemplate{navigation symbols}{}

% 'if #1 greater than #2 then #3 else #4' construct (compatible with pgfmath)


    \pgfmathdeclarefunction{f}{1}{\pgfmathparse{.5*(exp(-#1)-#1)}} % continuous function
    \pgfmathsetmacro{\ao}{.2}   % lower-bound of initial bracket
    \pgfmathsetmacro{\bo}{1}    % upper-bound of initial bracket
    \pgfmathsetmacro{\co}{0}    % midpoint of inital bracket (initialised at 0)
    \pgfmathtruncatemacro{\n}{3}        % number of iterations

    \ifx\ao\bo % check that \ao and \bo are distinct 
        \node[red] (0,0) {Bisection impossible: singleton initial bracket.};
        \ifg{\ao}{\bo}{ % if \ao > \bo, swop them
        % code in here
            \node[red] (0,0) {Bisection impossible: no root in initial bracket.};
                \draw[->] (\xmin,0) node[left] {$0$} --
                    (\xmax,0) node[right] {$x$};
                \draw[->] (\xmin,\ymin) -- (\xmin,\ymax) node[left] {$f(x)$};
                \draw[fcolor] plot[domain=\xmin:\xmax] (\x,{f(\x)});
            \pgfplotsforeachungrouped \k in {1,2,...,\n}{%
                    \draw[thick,acolor] (\ao,.1ex) --
                        (\ao,-.1ex) node[below] {$a_{\j}$}; % a0
                    \draw[thick,bcolor] (\bo,.1ex) --
                        (\bo,-.1ex) node[below] {$b_{\j}$}; % b0
                    \draw[thick,ccolor] (\co,.1ex) --
                        (\co,-.1ex) node[below] {$c_{\j}$};     
                    \coordinate (a0) at (\ao,{f(\ao)});     
                    \draw[dashed,thin,red]  (a0 |- \xmin,0) -- (a0)
                        -- (a0 -| \xmin,0) node[left] {$f(a_{\j})$};% dashed lines
                    \draw[fill,red] (a0) circle (.05ex);            
                    \coordinate (c0) at (\co,{f(\co)}); 
                    \draw[dashed,thin,orange]   (c0 |- \xmin,0) -- (c0)
                        -- (c0 -| \xmin,0) node[left] {$f(c_{\j})$};% dashed lines      
                    \draw[fill,orange] (c0) circle (.05ex);                                 
                \ifg{f(\ao)*f(\co)}{0}{ % bisection iteration
                        \draw[thick,acolor] (\ao,.1ex) --
                            (\ao,-.1ex) node[below] {$a_{\j}$}; % a0 
                        \draw[thick,bcolor] (\bo,.1ex) --
                            (\bo,-.1ex) node[below] {$b_{\j}$}; % b0 
  • Do I need to do anything special to compile your code? It hangs with ` File ended while scanning use of \next.` :(
    – Xavier
    Commented Mar 25, 2013 at 19:28
  • Weird. Works great on my machine, but copying and pasting it on the site introduces an error somewhere... I'll figure it out.
    – jub0bs
    Commented Mar 25, 2013 at 19:35
  • 2
    @Xavier Remove the white-space in front of \end{frame} and it works. The manual states for using fragile: “In this case, […] the \end{frame} must be alone on a single line.” Commented Mar 25, 2013 at 19:56
  • @Qrrbrbirlbel Thanks! If TeX starts to be picky about spaces, I am lost :)
    – Xavier
    Commented Mar 25, 2013 at 20:00
  • @percusse Thanks. Feel free to edit my answer accordingly. I've tried your improvement but I get an error...
    – jub0bs
    Commented Mar 28, 2013 at 14:53

Providing an excuse for slacking off

Just let (La)TeX burn some CPU cycles while you are relaxing.

  • 4
    The #1 programmers excuse for legitimately slacking off: xkcd.com/303 Commented Jul 10, 2013 at 17:18

Enrico “egreg” Gregorio posted this into our TeX.sx chat:

  1. Let me name it xcix.tex, because it’s in the manner of David Carlisle’s xii.tex, cf. Peter Flynn’s answer

    jlet~jlet~Hjpar ~Bjmscount~~jdef~x{q bottlez of beer}
    ~jw{x on the wall}~jt{jadvanceAB-1ATake one down Aand
    pass it around,H}B99~ji{jifnumB}~q{ji=0Nojelsejnumber
    Bjfi}~z{ji>1sjfiA }jloop jifnumB>0 jw, x,Hjtjw.jvskip
    8ptplus1ptjrepeat Time to buy some more beerjdotsjend

    (source link)

  2. The same as LaTeX3 version

    % user level command
    \NewDocumentCommand{\beers} { O{99} }
      \manual_beers_sing:n { #1 }
    % variables
    \int_new:N \l_manual_beers_count_int
    % functions
    \cs_new_protected:Npn \manual_beers_sing:n #1
      \int_set:Nn \l_manual_beers_count_int { #1 }
      \prg_replicate:nn { \l_manual_beers_count_int }
        \int_decr:N \l_manual_beers_count_int
      Time ~ to ~ buy ~ some ~ more ~ beer ~ \dots
    \cs_new_protected:Npn \manual_beers_print:
      \manual_beer_text:nn { ~ on ~ the ~ wall }{ 0 }, ~
      \manual_beer_text:nn { } { 0 }, \\
      Take ~ one ~ down ~ and ~ pass ~ it ~ around, \\
      \manual_beer_text:nn { ~ on ~ the ~ wall } { -1 }.\par
    \cs_new:Npn \manual_beer_text:nn #1 #2
      \int_case:nnF { \l_manual_beers_count_int + #2 }
        { 0 } { No ~ bottle ~ of ~ beer }
        { 1 } { 1 ~ bottle ~ of ~ beer }
        \int_to_arabic:n { \l_manual_beers_count_int + #2 } ~ bottles ~ of ~ beer

    (source link, small correction; the code as seen above is, though, in this version, as it will appear in a manual by Enrico, which is in the moment, this code was posted, in process of writing)

This was influenced by me, because I had posted these two links:

  • May I ask what is \mscount? I surmise it is like \newcount, but cannot find it anywhere. Thanks a lot in advance.
    – awllower
    Commented Oct 6, 2016 at 7:47

Implementing a Turing machine simulator
(TeX is Turing complete)

Hail to the busy beaver!

  • 1
    Link is broken (domain for sale). Commented Jul 27, 2017 at 14:07

At this stage, having seen a lot of bizarre things done with LaTeX by users :-) I should probably add the bookshelf package I posted to CTAN recently.

This takes a BiBTeX file (eg your thesis) and turns it into an image of a bookshelf so you can use it as a background during video calls; in my case to cover up the fact that my bookshelves were hideously untidy :-)

enter image description here

  • Wow... how did you even think of this? Commented Jun 16, 2021 at 10:16
  • 1
    Some years ago I was playing with the idea of formatting actual book spines in LaTeX (starting with the TeXbook, of course) to make a virtual bookshelf. It's basically a \rotatebox of the text inside a \colorbox,. Then the first lockdown came along and I saw that instead of trying to retypeset the actual appearance, you could just pick a size and shape and a font using the random package, and take the data from any BiBTeX file. Commented Jun 17, 2021 at 13:01

The avremu package

…emulates an 8-bit CPU (ATmega8).

  • 1
    From the manual: “This picture (250x250) took 44 hours to render. ”. ;-)
    – egreg
    Commented Mar 26, 2019 at 18:22

You must log in to answer this question.

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