This is a maybe not too serious question, but in order to honor \pi day I'd like to collect a set of LaTeX riddles. The aim is to encourage newcomers to learn some very basic LaTeX commands. Here is an example:

% from https://tex.stackexchange.com/q/56353/121799
% from the manual section 103.4.2
% \pgf@x will contain the \xout{radius} angle
% \pgf@y will contain the distance \pgfmathsincos@{\pgf@sys@tonumber\pgf@x}%
% pgfmathresultx is now the cosine of \xout{radius} radius and 
% pgfmathresulty is the sine of radius 
% \pgf@x=\pgfmathresultx\pgf@y% 
% \pgf@y=\pgfmathresulty\pgf@y%
% what the thing in the pgf manually is probably doing it to express the x coordinate in pt
% then take the cos and sin of x/pt (i.e. if x=50pt then it will return cos(50))
% and multiply the outcome by a the y coordinate
% (x_new,y_new) = (y_old cos(x_old/pt), y_old sin(x_old/pt))
% now comes a slightly modified version
\def\marmotransformation{% modified version of the manual 103.4.2 Installing Nonlinear Transformation
\advance\pgf@x by -\xC% relative
\advance\pgf@y by -\yC% coorinates
\edef\relY{\the\pgf@y}% Yes, there is a more elegant solution based on \pgfpointadd
} % I have no idea why the factor 5 is needed
% I'm using https://tex.stackexchange.com/a/167109/121799
\newcommand{\apple}[1][ball color=red]{\hspace*{-0.5cm}
%\path[use as bounding box](-0.1,-0.1) rectangle (0.1,0.1);
\coordinate (C) at (0,3) {};
\coordinate (N) at (0,0) {};
\begin{scope}[transform shape nonlinear=true]
\shade[shading=ball,opacity=1] (0,0) circle (2);
\draw[smooth,fill=black](-0.15,3) .. controls (-0.15,2.5) .. (0,2) to 
(0.1,2) .. controls (-0.05,2.5) .. (-0.05,3) --cycle;

enter image description here

(Hint: the answer is something that should \emph{not} be put on a \pi\zz{a}.)

Question: Are you aware of similar riddles? Could you post them?

Clarification: The basic LaTeX commands to be learned are \pi and \ne, not the nonlinear transformations.

Thanks everyone! I am absolutely overwhelmed by all the brilliant answers this "question" got. Unfortunately, the rules in this forum I can accept only one of them. In the end I decided to accept Paulo Cereda's answer because I hope that the reputation gained this way will allow him to spend more time on his thesis. ;-)

  • 29
    I'd hate to see what you consider complicated LaTeX code ....
    – cfr
    Commented Mar 14, 2018 at 3:34
  • 6
    Marmots should not been put on a pizza. :-) Commented Mar 14, 2018 at 3:48
  • 4
    Really cool, but in no way basic ;-) also nice to see the answer written the the LaTeX code, I hadn't considered that Commented Mar 14, 2018 at 4:42
  • 11
    I'm struggling to answer this, as what I thought was the answer is, along with ham, the world's favourite pizza topping. So that can't be the answer, I'll have to think harder. Commented Mar 14, 2018 at 8:59
  • 4
    @DavidCarlisle You seem to confuse what’s popular with what’s right. Commented Mar 14, 2018 at 17:21

9 Answers 9


The best way to represent digits of Pi is, of course, with ducks. :) E.g, 5 ducks of the same colour denote the digit 5, and so forth. However, this system had to rely on a duck to represent no ducks at all, so I used an American black duck species to act accordingly.

The following code has to be executed with LuaLaTeX, and the digit generator is courtesy of Rosetta Code. Beware, for this code is slow. If you want to specify the number of digits (and ducks), please change the n variable in the Lua code scope. :)

Update: The algorithm starts with zero. :)


  \int_compare:nTF { #1 != 0 }
  { \prg_replicate:nn { #1 } { \tikz[scale=.25]{ \duck[body=#2]; } \hspace{.16667em} } }
  { \tikz[scale=.25]{ \duck[body=black]; } \hspace{.16667em} }


a = {}
n = 1000
cl = false
len = math.modf( 10 * n / 3 )

for j = 1, len do
    a[j] = 2
nines = 0
predigit = 0
for j = 1, n do
    q = 0
    for i = len, 1, -1 do
        x = 10 * a[i] + q * i
        a[i] = math.fmod( x, 2 * i - 1 )
        q = math.modf( x / ( 2 * i - 1 ) )
    a[1] = math.fmod( q, 10 )
    q = math.modf( q / 10 )
    if q == 9 then
        nines = nines + 1
        if q == 10 then
            tex.print('\\ducks{' .. (predigit + 1) .. '}{' ..
            (cl and 'light' or '')  .. 'gray}')
            cl = not cl
            for k = 1, nines do
            predigit = 0
            nines = 0
            tex.print( '\\ducks{' .. predigit .. '}{' .. 
            (cl and 'light' or '') .. 'gray}' )
            cl = not cl
            predigit = q
            if nines ~= 0 then
                for k = 1, nines do
                    tex.print('\\ducks{9}{' ..
                    (cl and 'light' or '') .. 'gray}')
                    cl = not cl
                nines = 0
tex.print( '\\ducks{' .. predigit .. '}{' ..
(cl and 'light' or '') .. 'gray}' )


Happy Pi day! Quack! :)

  • 2
    I don't think the zeroes are rendering correctly
    – Maya
    Commented Mar 14, 2018 at 16:05
  • @NieDzejkob I do see some zeroes ;-) Commented Mar 14, 2018 at 16:12
  • @ThorbjørnE.K.Christensen I don't see any American black ducks
    – Maya
    Commented Mar 14, 2018 at 16:13
  • I do however think that the number of zeroes in a row is hard to see. Commented Mar 14, 2018 at 16:13
  • Ohh you are right Commented Mar 14, 2018 at 16:14

Almost random character generator, compile with XeTeX:



enter image description here


  1. Where did all spaces go?
  2. Why does the code only features a single %?

Hexadecimal expansion of π courtesy of http://turner.faculty.swau.edu/mathematics/materialslibrary/pi/pibases.html

  • 9
    The question were about LaTeX riddlers but this is TeX code which has nothing common with LaTeX :)
    – wipet
    Commented Mar 14, 2018 at 9:07
  • @wipet: Nor do the exercises seem to be suitable for “LaTeX newcomers”… :-)
    – GuM
    Commented Mar 17, 2018 at 3:22

EDIT: translations provided for the non-English-speaking native.

Here are 2 simple riddles:

You better watch out,\\
$u\beta \not \pi\dots$\\
Q: Who is coming to town?

enter image description here

Refers to the Christmas verse, "You better watch out, you better not cry, better not pout, I'm telling you why, Santa Claus is coming to town." Here, "u beta not pi" carries the same rhythm as "you better not cry."

\parindent 0pt
Clue: {3\tiny$\pi\gg$s}\\
Q: Who is the bad guy in this story?

enter image description here

"3 tiny piggs" is making reference to the fairy tale, "The 3 Little Pigs," in which the big bad wolf is the antagonist.

The following are decipher games. Construct the LaTeX code from reading the image.

The doctor says...$\pi\ss \in a \cup$

enter image description here

Perhaps intended for the older crowd, when asked to provide a urine specimen, the colloquial description is to "piss in a cup."

$\if \you 8 a \pi\ll\you'\ll b \fi\ne$,\\
$\if \you 8 5 \pi\ll{s}\you'\ll \not b \fi\ne$!

enter image description here

"If you [ate] a pill, you'll be fine, but if you [ate] 5 pills, you'll not be fine" is what the code essentially reads as. The LaTeX renditions is, of course, most subtle, as \if...\fi are tests and not typeset text. It further relies on the macro \you being set to 8.

$a \big(\pi\ll) {\wedge}d \in a \cup$.

enter image description here

Just a stupid line here, "a big pill wedged in a cup" is what the code looks like.

The Mama circle asked her child what time ($t$) is it?\\
The reply: $t = 2 (\mathrm{Go})^{\pi D}$

enter image description here

Knowing t is time, the math might be phonetically read as "time to go to the pottie (aka bathroom)."

  • 2
    Since I've already resorted to potty humor, and because I don't want to encourage the use of deprecated features, I will refrain from adding \do\do$\pi\le$ =\sc at to the list. Commented Mar 14, 2018 at 12:15
  • 1
    hee hee /giggles youtube.com/watch?v=eSrXqOI9988 Commented Mar 14, 2018 at 14:48
  • @PauloCereda Is it obvious that I've sunk that far?? Commented Mar 14, 2018 at 16:10
  • Is there a phonetic version for non fluently english speakers, please ?
    – Tarass
    Commented Mar 14, 2018 at 16:39
  • @Tarass are you referring to Paulo's cited video, or one of my pi-quips? Commented Mar 14, 2018 at 16:56


        \pstVerb{/distance {\i\space DegtoRad 2 mul} def}
        \ifnum\i=360\relax\rput(!distance -.4){\large$\pi$}\fi
        \psline(!distance 0)
        \rput{!\i\space neg}(!distance 2){\psline[linecolor=cyan,linewidth=2pt]{->}(0,-2)\psarc(0,0){2}{-90}{!\i\space 90 sub}}

enter image description here

I believe that all of you don't know the geometrical interpretation of π until you watch the animation given above.

  • 9
    He died today, OMG! (A pray for him).
    – CarLaTeX
    Commented Mar 14, 2018 at 17:19

OK, I dare. Here is a famous test of the level in mathematics of students in "classes préparatoires" to French engineer schools. In French, with English translation and IPA pronunciation.


Show that
\frac{\text{cheval}}{\text{oiseau}} = \pi.
(``$\text{\textsl{horse}}/\text{\textsl{bird}} = \pi$''.)


$\text{oiseau} = \beta\ell$ (\text{b\^ete \`a ailes}, [\textipa{bEt a El}],
$\text{\textsl{winged beast}}$),
\frac{\text{cheval}}{\text{oiseau}} = \frac{\text{cheva}\ell}{\beta\ell}
= \frac{\text{cheva}}{\beta}.
But $\text{cheva} = \text{vache}$ (product is commutative) and 
$\text{vache} = \beta\pi$ (b\^ete \`a pis, [\textipa{bEt a pi}]; 
``$\text{\textsl{cow}} = \text{\textsl{beast with udders}}$''),
\frac{\text{cheva}}{\beta} = \frac{\beta\pi}{\beta} = \pi.
C.Q.F.D. -- sorry, Q.E.D.

  • @Tarass Sorry, I saw you posted the same joke as me only after I clicked on "post answer". Commented Mar 14, 2018 at 14:42
  • I think I solved the puzzle why your code does not compile: because there is no \end{document}.
    – user121799
    Commented Mar 14, 2018 at 15:59
  • @marmot Corrected. Commented Mar 14, 2018 at 16:02
  • You have a small typo on the last line, it should be \frac{\beta\pi}{\beta}. Commented Mar 15, 2018 at 12:56

Mine is not exactly a riddle, but since Mr. Marmot said that:

The aim is to encourage newcomers to learn some very basic LaTeX commands.

(and I must agree with @cfr about the complicated example :P), here's my contribution.

I am too a rather new user of LaTeX and friends, so this applied to me as well. I'll show you here my first attempt at programming something in LuaLaTeX :).

Since we're celebrating π day, I made a LuaLaTeX function that will replace every-ish occurrence of the string pi by π:

enter image description here

A word of advice: please don't sneak this function in your friend's thesis U_U.

The function is executed in a process_input_buffer callback, which is called every time TeX reads a line from an input file. This callback receives an returns a string which is the line read from the file.

The function, piday replaces pi by \(\pi\), and Pi and PI by \(\Pi\) when these sequences are found within normal text. With "normal text" I mean that the string pi is not found in a control sequence, for example, \ePIgraph.

The function also does a few checks if the pi string is not part of a \begin{tikzPIcture}, for example. The function also checks for citation commands (works with \<text|paren>cite<t,p>), and for \urls. In both cases the substitution makes TeX throw an error afterwards.

Another exception is for \bibitems. The substitution happens twice (for the style I was using), so I had to make the check for \bibitem valid for the whole line. For example, in my test file I had a bibitem like this:

\bibitem[{MPI Forum}, 2015]{MPIForum2015}

which became

\bibitem[{M\(\Pi\) Forum}, 2015]{M\(\Pi\)Forum2015}

and broke stuff :P.

Other than that the function seems to work fine. The document I used to test it on was my 100-page graduation project, so it guess it works quite well :)

Bonus: I initially tried to replace occurrences of ip (and such) by \reflectbox{\(\pi\)}. For normal text it works like a charm, but it was breaking too many things, so eventually I gave up (sob).

Sadly, it only works when the pies are read from the input file, so anything already defined in a macro (\lipsum, for example), doesn't work. I tried to use some output equivalent of the process_input_buffer, but failed miserably Ç_Ç.

Anyway, here is the .lua file:

local gsub = string.gsub
piday = function(line)
  if string.match(line,'bibitem') ~=nil then -- Exception for \bibitem
    return line
  out = gsub(line,'(%g+)',-- match everything that is not a space. This will split the input into words.
    if string.match(rest,'begin{') ~=nil or -- Exception for begin
       string.match(rest,'end{')   ~=nil or -- Exception for end{
       string.match(rest,'cite')   ~=nil or -- Exception for <text|paren>cite<t|p>
       string.match(rest,'url')    ~=nil then -- Exception for url
      return rest
    subs = gsub(rest,'(\\?)(%a+)', -- Match the whole word, and split the backslash
        if esc == '\\' then -- If there is a backslash, return without replacing
          return esc .. csname
        -- Otherwise, let the π rain upon the document
        csname = gsub(csname,'pi','\\(\\pi\\)')
        csname = gsub(csname,'Pi','\\(\\Pi\\)')
        csname = gsub(csname,'PI','\\(\\Pi\\)')
        -- And the failed attempt to make flipped pies (pun intended)
--         csname = gsub(csname,'ip','\\protect\\reflectbox{\\(\\pi\\)}')
--         csname = gsub(csname,'Ip','\\protect\\reflectbox{\\(\\Pi\\)}')
--         csname = gsub(csname,'IP','\\protect\\reflectbox{\\(\\Pi\\)}')
        return csname
    return subs
  return out
luatexbase.add_to_callback("process_input_buffer", piday, "replace `pi' by π" )

To use the function, one just have to put \directlua{dofile('piday.lua')} somewhere in the document and comπle it with LuaLaTeX. I opted to put the call in an \AtBeginDocument hook.

For the example I also loaded the xcolor and bm packages and made the πs blue and bold. If you really do want to sneak this function in your friend's thesis, I advise against the bold-blue πes. For the example I also uncommented the flipped π lines.

Here it goes:



\def\envpienv{Warning: Many \(\pi\)s here:}


A tribute to Stephen Hawking. RIP.

p i pi ip ipi pip \(\pi \ip \ipi \pip\)




Lorem Ipsum dolor sit amet, consectetuer
adipiscing elit. Ut purus elit, vestibulum ut, placerat ac,
adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu
libero, nonummy eget, consectetuer id, vulputate a, magna. Donec
vehicula augue eu neque. Pellentesque habitant morbi tristique
senectus et netus et malesuada fames ac turpis egestas. Mauris ut
leo. Cras viverra metus rhoncus sem. Nulla et lectus vestibulum urna
fringilla ultrices.  Phasellus eu tellus sit amet tortor gravida
placerat. Integer sapien est, iaculis in, pretium quis, viverra ac,
nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus.
Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla.
Curabitur auctor semper nulla. Donec varius orci eget risus. Duis
nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. Duis
eget orci sit amet orci dignissim rutrum.


If someone have suggestions about any improvement, please do tell.

It was fun :)

On Pi day, a TeXie named Kyle,
Did fiddle with LaTeX awhile;
  Irrational coding
  Provided foreboding
His document class won't compile.
  • Just out of curiosity, how does this relate to pi? Perhaps there’s a similar English limerick that talks about it?
    – GuM
    Commented Mar 17, 2018 at 18:41
  • @GuM pi is an irrational number.
    – user139954
    Commented Mar 17, 2018 at 22:16
  • Well, why not a prayer, then? Pi is also a “transcendental” number… :-D :o)
    – GuM
    Commented Mar 17, 2018 at 23:41
  • 1
    @GuM On Pi day a TeXie named Rick, Decided to try a new trick; His coding was mental, But not transcendental: The document ending was quick.
    – user139954
    Commented Mar 18, 2018 at 2:21
  • In Leslie Lamport’s book (LaTeX: A Document Preparation System) there’s a limerick concerning the verse environment (p. 25) that is clearly based on the same model: could you tell me what this model is? (:-)
    – GuM
    Commented Mar 18, 2018 at 2:49

It is obvious if you are not into pi



enter image description here

&\left(\dfrac{}{\text{\textit{animal with wings}}}\right)\\
&\left(\dfrac{\text{\textit{animal with udder}}}{}\right)\\
  • Sorry, I saw you posted the same joke as me only after I clicked on "post answer". Mine provides some context and gives the IPA pronunciation for the few people on TeX.SE who do not speak French. Commented Mar 15, 2018 at 13:17
  • Saint Cloud Paris Match ;-)
    – Tarass
    Commented Mar 15, 2018 at 13:49

You must log in to answer this question.