37

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:

\documentclass{article}
\usepackage{tikz}
\usepgfmodule{nonlineartransformations}
\usetikzlibrary{shapes}
\usetikzlibrary{patterns}
\makeatletter
% from https://tex.stackexchange.com/q/56353/121799
\newcommand{\gettikzxy}[3]{%
  \tikz@scan@one@point\pgfutil@firstofone#1\relax
  \global\edef#2{\the\pgf@x}%
  \global\edef#3{\the\pgf@y}%
}
% 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\relX{\the\pgf@x}%
\edef\relY{\the\pgf@y}% Yes, there is a more elegant solution based on \pgfpointadd
\pgfmathsetmacro{\relNx}{\xN-\xC}%
\pgfmathsetmacro{\relNy}{\yN-\yC}%
\pgfmathsetmacro{\angleN}{atan2(\relNy,\relNx)}%
\pgfmathsetmacro{\LeN}{veclen(\relNx,\relNy)}%
\pgfmathsetmacro{\myp}{(\relX*\relNx+\relY*\relNy)/(\LeN*28.3465)}
\pgfmathsetmacro{\myo}{(((\relY*\relNx-\relX*\relNy))/(\myp*\LeN*(28.3465*pi/180)))+\angleN)}
\pgfpointadd{\pgfqpoint{\xC}{\yC}}{\pgfpointpolarxy{\myo}{\myp}}
} % 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}
\ensuremath{\vcenter{\resizebox{0.4cm}{!}{\begin{tikzpicture}[#1]
%\path[use as bounding box](-0.1,-0.1) rectangle (0.1,0.1);
\coordinate (C) at (0,3) {};
\gettikzxy{(C)}{\xC}{\yC}
\coordinate (N) at (0,0) {};
\gettikzxy{(N)}{\xN}{\yN}
\begin{scope}[transform shape nonlinear=true]
\pgftransformnonlinear{\marmotransformation} 
\shade[shading=ball,opacity=1] (0,0) circle (2);
\end{scope}
\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;
\end{tikzpicture}
}}}}
\begin{document}
\resizebox{!}{4cm}{$\pi\ne\apple$}
\end{document}

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 Mar 14 '18 at 3:34
  • 6
    Marmots should not been put on a pizza. :-) – Przemysław Scherwentke Mar 14 '18 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 – Thorbjørn E. K. Christensen Mar 14 '18 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. – David Carlisle Mar 14 '18 at 8:59
  • 4
    @DavidCarlisle You seem to confuse what’s popular with what’s right. – Konrad Rudolph Mar 14 '18 at 17:21
24

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. :)

\documentclass[12pt]{article}
\usepackage{tikzducks}
\usepackage{xparse}
\usepackage[margin=1cm]{geometry}
\usepackage{luacode}

\ExplSyntaxOn
\NewDocumentCommand{\ducks}{mm}{
  \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} }
}
\ExplSyntaxOff

\setlength{\parindent}{0pt}
\pagestyle{empty}

\begin{document}
\raggedright
\begin{luacode}
a = {}
n = 1000
cl = false
len = math.modf( 10 * n / 3 )

for j = 1, len do
    a[j] = 2
end
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 ) )
    end
    a[1] = math.fmod( q, 10 )
    q = math.modf( q / 10 )
    if q == 9 then
        nines = nines + 1
    else
        if q == 10 then
            tex.print('\\ducks{' .. (predigit + 1) .. '}{' ..
            (cl and 'light' or '')  .. 'gray}')
            cl = not cl
            for k = 1, nines do
                tex.print('\\ducks{1}{black}')
            end
            predigit = 0
            nines = 0
        else
            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
                end
                nines = 0
            end
        end
    end
end
tex.print( '\\ducks{' .. predigit .. '}{' ..
(cl and 'light' or '') .. 'gray}' )
\end{luacode}
\end{document}

Quack

Happy Pi day! Quack! :)

19

Almost random character generator, compile with XeTeX:

\font\forpi="[FreeSans.otf]"
\forpi
\def\printpi3.{3.\otherpi}
\def\otherpi#1#2#3{%
  \iffontchar\font"#1#2
    \char"#1#2
  \else
    \char"1#1#2
  \fi
  \ifx#3\end\else\expandafter\otherpi\fi#3
}


\printpi
3.
243F
6A88
85A3
08D3
1319
8A2E
0370
7344
A409
3822
299F
31D0
082E
FA98
EC4E
6C89
4528
21E6
38D0
1377
BE54
66CF
34E9
0C6C
C0AC
\end

enter image description here

Exercises.

  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 Mar 14 '18 at 9:07
  • @wipet: Nor do the exercises seem to be suitable for “LaTeX newcomers”… :-) – GuM Mar 17 '18 at 3:22
16

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

Here are 2 simple riddles:

\documentclass{article}
\begin{document}
\noindent
You better watch out,\\
$u\beta \not \pi\dots$\\
Q: Who is coming to town?
\end{document}

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."

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

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.

\documentclass{article}
\begin{document}
The doctor says...$\pi\ss \in a \cup$
\end{document}

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."

\documentclass{article}
\parindent0pt
\begin{document}
\def\you{8}
$\if \you 8 a \pi\ll\you'\ll b \fi\ne$,\\
but\\
$\if \you 8 5 \pi\ll{s}\you'\ll \not b \fi\ne$!
\end{document}

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.

\documentclass{article}
\begin{document}
$a \big(\pi\ll) {\wedge}d \in a \cup$.
\end{document}

enter image description here

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

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

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. – Steven B. Segletes Mar 14 '18 at 12:15
  • 1
    hee hee /giggles youtube.com/watch?v=eSrXqOI9988 – Paulo Cereda Mar 14 '18 at 14:48
  • @PauloCereda Is it obvious that I've sunk that far?? – Steven B. Segletes Mar 14 '18 at 16:10
  • Is there a phonetic version for non fluently english speakers, please ? – Tarass Mar 14 '18 at 16:39
  • @Tarass are you referring to Paulo's cited video, or one of my pi-quips? – Steven B. Segletes Mar 14 '18 at 16:56
15
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-vehicle,graphicx}

\def\V{\rput(0,4){\includegraphics[angle=10]{hawking}}}

\begin{document}
\multido{\i=0+15}{25}{%
\begin{pspicture}[dimen=m](-5,-1)(18,12)
        \pstVerb{/distance {\i\space DegtoRad 2 mul} def}
    \psVehicle[vehicle=\SelfDefinedVehicle,ownvehicle=\V,showSlope=false,frontwheel=,backwheel=\SpokesWheelB,rB=2]{1}{distance}{0}
        \psline(-4,0)(17,0)
        \multido{\iX=0+4,\iLabel=0+1}{4}{\rput(\iX,-.4){\large$\iLabel$}}
        \ifnum\i=360\relax\rput(!distance -.4){\large$\pi$}\fi
        \multips(2,2)(4,0){3}{\psset{linecolor=gray,linewidth=2pt,linestyle=dashed}\pscircle[linestyle=solid]{2}\psline(-2,0)(-2,-2.1)\psline(2,0)(2,-2.1)}
        \psset{linewidth=3pt,linecolor=red}
        \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}}
\end{pspicture}}
\end{document}

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 Mar 14 '18 at 17:19
11

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.

\documentclass{article}
\usepackage[safe]{tipa}
\usepackage{amsmath}
\begin{document}
\paragraph*{Question:}\leavevmode

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

\paragraph*{``Proof'':}\leavevmode

$\text{oiseau} = \beta\ell$ (\text{b\^ete \`a ailes}, [\textipa{bEt a El}],
$\text{\textsl{winged beast}}$),
so
\[
\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}}$''),
so 
\[
\frac{\text{cheva}}{\beta} = \frac{\beta\pi}{\beta} = \pi.
\]
C.Q.F.D. -- sorry, Q.E.D.

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

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
  end
  out = gsub(line,'(%g+)',-- match everything that is not a space. This will split the input into words.
  function(rest)
    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
    end
    subs = gsub(rest,'(\\?)(%a+)', -- Match the whole word, and split the backslash
      function(esc,csname)
        if esc == '\\' then -- If there is a backslash, return without replacing
          return esc .. csname
        end
        -- 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
      end
    )
    return subs
  end
  )
  return out
end
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:

\documentclass{article}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{bm}
\definecolor{piblue}{HTML}{292EC2}

\AtBeginDocument{\directlua{dofile('piday.lua')}}

\def\ip{ip}
\def\ipi{ipi}
\def\pip{pip}
\def\envpienv{Warning: Many \(\pi\)s here:}
\def\endenvpienv{\rotatebox[origin=c]{180}{\(\pi\)}}

\begin{document}

A tribute to Stephen Hawking. RIP.

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

\begin{envpienv}

ipipipippipippipipipipiiipipipipipippippiip

\end{envpienv}

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.

\end{document}

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

It was fun :)

9
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 Mar 17 '18 at 18:41
  • @GuM pi is an irrational number. – user139954 Mar 17 '18 at 22:16
  • Well, why not a prayer, then? Pi is also a “transcendental” number… :-D :o) – GuM Mar 17 '18 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 Mar 18 '18 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 Mar 18 '18 at 2:49
8

It is obvious if you are not into pi

CAi\esset2C

7

enter image description here

\documentclass{article}
\usepackage{array,amsmath}
\begin{document}
\pagestyle{empty}
$
\renewcommand{\arraystretch}{2}
\begin{array}{r@{}>{{}}l@{}>{\qquad}l}
\dfrac{\text{horse}}{\text{bird}}=\dfrac{\text{cheval}}{\text{oiseau}}
&=\dfrac{\text{cheval}}{\beta\text{l}}
&\left(\dfrac{}{\text{\textit{animal with wings}}}\right)\\
&=\dfrac{\text{cheva}}{\beta}\\
&=\dfrac{\text{vache}}{\beta}
&\left(\dfrac{\text{\textit{cow}}}{}\right)\\
&=\dfrac{\beta\pi}{\beta}
&\left(\dfrac{\text{\textit{animal with udder}}}{}\right)\\
&=\pi\\
\end{array}
$
\end{document}
  • 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. – Michel Fioc Mar 15 '18 at 13:17
  • Saint Cloud Paris Match ;-) – Tarass Mar 15 '18 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy