\documentclass[a4paper,11pt]{article}
\usepackage{array}
\usepackage{multirow}
\usepackage{lastpage}
\usepackage{verbatim}
\usepackage[francais,english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{amsfonts,amsmath,amssymb,mathrsfs,amsthm} 
\usepackage{fancyhdr}
\usepackage{lmodern}
\usepackage{ScratchX}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%----------------------------------- SI ALORS TOUTE BLANCHE-----------------------------------------------------------
\newcommand{\whitesailors}[2]{%loop with as many blocks as we want
	%	Créer un compteur à chaque passage dans cette boucle.	%	l'incrémenter du nombre de fois où ce décalage s'opère
	%	décaler en abscisse : ajouter 0,4 à x	%	mettre le compteur NbreComptr à NbreComptr+1
\ifthenelse{\value{NbrCptrLoupeDuplicate}=0}%aucun compteurs loupe créés
		{
		\ifthenelse{\value{CompteurMax}=0}
		{\loope{\theNbrCptrLoupe}{#2}}
		{
			\ifthenelse{\value{NbrCptrLoupe}<\value{CompteurMax}}%\or\value{NbrCptrLoupe}=\value{CompteurMax}}
				{\looope{\theNbrCptrLoupe}{#2}}
				{\loope{\theNbrCptrLoupe}{#2}}%pour ne pas recréer des compteurs déjà créés
		}
		}
		{\looope{\theNbrCptrLoupe}{#2}}

\ifthenelse{\value{NbrCptrAlorsDuplicate}=0}%aucun compteurs aloors créés
		{\sialoors{#1}}
		{\sialooors{#1}}%pour ne pas recréer des compteurs déjà créés
\settowidth{\malongueuR}{\pgfinterruptpicture #1 \endpgfinterruptpicture}

	\FPeval{X}{\x+(0.4)*\thedecalageX}	
	\FPeval{Y}{\y+(neg 0.66)*(\thedecalageY)}
	
	%\StrLen{#1}[\valeur]% pour ajuster la longueur de la boîte en fonction de la longueur du text
	\FPeval{b}{neg 0.1+Y}\FPeval{c}{0.36+Y}\FPeval{d}{0.1+X}
	\FPeval{e}{0.46+Y}\FPeval{f}{0.4+X}\FPeval{g}{0.5+X}\FPeval{h}{0.7+X}\FPeval{i}{0.8+X}\FPeval{j}{0.7+(X)}
	\FPeval{ii}{1.2+X}\FPeval{iii}{1.1+X}\FPeval{iiii}{0.9+X}\FPeval{gg}{0.6+X}
	\FPeval{l}{neg 0.2+(Y)}\FPeval{m}{neg 0.3+(Y)}\FPeval{o}{0.1+(Y)}
	%top
	%bottom#1
	\FPeval{mm}{neg 0.1+(neg 0.66)*(#2)+(Y)}
	\FPeval{mmm}{neg 0.2+(neg 0.66)*(#2)+(Y)}\FPeval{mmmm}{neg 0.3+(neg 0.66)*(#2)+(Y)}\FPeval{M}{neg 0.75+(neg 0.66)*(#2)+(Y)}\FPeval{MM}{neg 0.85+(neg 0.66)*(#2)+(Y)}\FPeval{MN}{neg 0.95+(neg 0.66)*(#2)+(Y)}\FPeval{MMM}{neg 0.55+(neg 0.66)*(#2)+(Y)}\FPeval{MMMM}{MMM-0.02}\FPeval{JJ}{j+0.02}%adjusting the height of the bottom
	\coordinate (A) at ($(\d,\e) ! \malongueuR ! (\f,\e)$);
	\coordinate (AA) at ($(\X,\c) ! \malongueuR+0.2cm ! (\g,\c)$);
	\coordinate (BB) at ($(\X,\M) ! \malongueuR+0.2cm ! (\f,\M)$);
	\coordinate (B) at ($(\g,\mmm) ! \malongueuR-0.4cm ! (\i,\mmm)$);	

\multido{\i=1+1}{\value{NbrCptrLoupe}}{%Fait défiler tous les compteurs jusqu'au nombre de compteurs : si compteur différent de -1 :
	%		si différent de 0, leur enlever 1. / si égal à 0 : enlever 1 à décalageX et mettre le compteur correspondant à -1.
	\ifthenelse{\value{loupe\i}>-1}{
			\ifthenelse{\value{loupe\i}=0}
			{\addtocounter{decalageX}{-1}\addtocounter{decalageY}{1}\setcounter{loupe\i}{-1}}
			{\addtocounter{loupe\i}{-1}}
			}{}
	}
\addtocounter{decalageX}{1}
\addtocounter{decalageY}{1}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\selectlanguage{english}
\pagestyle{fancy}
\fancyhead{}
		\fancyhead[LE,LO]{\em \LaTeX}
		\fancyhead[CE,CO]{\Large \textsc{The \texttt{ScratchX.sty} package}}
		\fancyhead[RE,RO]{\em 2016--2017}
		\fancyfoot[CE,CO]{\thepage /\pageref{LastPage}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%----------------------------------------------------------------------------------------------------------------------------------%
%----------------------------------------------------------------------------------------------------------------------------------%
\section*{
\centering{
	\begin{Scratch}
	\beginbox{User guide: package \cb[ope]{ScratchX.sty\ }}
	\end{Scratch}
		}
}
\begin{center}
\begin{Scratch}
\scbox{Thibault Ralet}{ctrl}
\scbox{March \rb{2017}}{data}
\end{Scratch}
\end{center}

\noindent\rule{\linewidth}{.5pt}


\parbox{1ex}{\Scratchy[0.1][0.1]}\\

\hspace{1cm}\parbox{1ex}{\Scratchy[0.2][0.2]}\\

\hspace{2cm}\parbox{1ex}{\Scratchy[0.5][1]}\\

\hspace{5cm}\parbox{1ex}{\Scratchy[0.75][1.5]}\\

%----------------------------------------------------------------------------------------------------------------------------------%
%----------------------------------------------------------------------------------------------------------------------------------%
\section{Introduction}
The \texttt{ScratchX.sty} package allows you to write any kind of Scratch program in \LaTeX.

The \texttt{ScratchX.sty} package has to be put at least in the same file where the document \texttt{.tex} is created, or in the dedicated place in your computer.

The \texttt{ScratchX.sty} package must be called in the preamble of the document \texttt{.tex} with:

\begin{verbatim} \usepackage{ScratchX} \end{verbatim}

The \texttt{ScratchX.sty} package uses the following packages:
\begin{verbatim}
\usepackage[nomessages]{fp}
\usepackage{calc}
\usepackage{xstring}
\usepackage[alpine]{ifsym}%pour avoir VarFlag comme
%drapeau de départ de Scratch
\usepackage{ifthen}
\usepackage{multido}
\usepackage{xargs}
\end{verbatim}

In the document \texttt{.tex} that you want to create, you need to load:
\begin{verbatim}
\usepackage{tikz}
\usetikzlibrary{calc}
\end{verbatim}
and also:
\begin{verbatim}
\usepackage{amssymb}
\end{verbatim}

You can compile with XeLaTeX or pdfLaTeX.

\newpage
%----------------------------------------------------------------------------------------------------------------------------------%
%----------------------------------------------------------------------------------------------------------------------------------%
\section{General description}

We write a program (or simply a command) Scratch with the environment:

\begin{verbatim}
\begin{Scratch}
%\LaTeX commands in order to create the Scratch commands
\end{Scratch}
\end{verbatim}

The command \texttt{\textbackslash begin\{Scratch\}} has the scale in option (1 by default).

Thus,\texttt{\textbackslash begin\{Scratch\}[2]} doubles the program size, whereas  \texttt{\textbackslash begin\{Scratch\}[0.7]} reduces by 70\% the size of the created program.

\begin{center}
\begin{tabular}{cc}

\begin{Scratch}[1]
\scbox{default size}{app}
\end{Scratch}
&
\begin{Scratch}[2]
\scbox{bigger}{app}
\end{Scratch}\\
&
\begin{Scratch}[0.7]
\scbox{smaller}{app}
\end{Scratch}
\end{tabular}
\end{center}

%----------------------------------------------------------------------------------------------------------------------------------%
\subsection*{The colors}
The ten specific Scratch colors are defined like this:
\begin{center}
\begin{tabular}{c@{:\quad}cp{1cm}c@{:\quad }c}\hline
mvt&\textcolor{mvt}{Motion}&&evt&\textcolor{evt}{Events}\\
app&\textcolor{app}{Looks}&&ctrl&\textcolor{ctrl}{Control}\\
son&\textcolor{son}{Sound}&&capt&\textcolor{capt}{Sensing}\\
stylo&\textcolor{stylo}{Pen}&&ope&\textcolor{ope}{Operators}\\
data&\textcolor{data}{Data}&&bloc&\textcolor{bloc}{More blocks}\\\hline
\end{tabular}
\end{center}

\newpage
%----------------------------------------------------------------------------------------------------------------------------------%
%----------------------------------------------------------------------------------------------------------------------------------%
\section{Command list}

%----------------------------------------------------------------------------------------------------------------------------------%
\subsection{Simples}
Obtained with \texttt{\textbackslash scbox\{<text>\}\{<color>\}}.

Typing:
\begin{verbatim}
\begin{Scratch}
\scbox{if on edge, bounce}{mvt}
\scbox{hide}{app}
\scbox{stop all sounds}{son}
\scbox{pen down}{stylo}
\scbox{reset timer}{capt}
\end{Scratch}
\end{verbatim}

you get:\\

\begin{Scratch}
\scbox{if on edge, bounce}{mvt}
\scbox{hide}{app}
\scbox{stop all sounds}{son}
\scbox{pen down}{stylo}
\scbox{reset timer}{capt}
\end{Scratch}

%----------------------------------------------------------------------------------------------------------------------------------%
\subsection{Specials}

\subsubsection{Events}%%%%%%%%%%%%%%%%%%%%%%%%
Obtained with \texttt{\textbackslash beginbox\{<text>\}}.

\texttt{\textbackslash beginbox\{\}} gives \parbox{1ex}{\begin{Scratch}\beginbox{}\end{Scratch}}

\texttt{\textbackslash beginbox\{clone\}} gives \parbox{1ex}{\begin{Scratch}\beginbox{clone}\end{Scratch}}

\texttt{\textbackslash beginbox\{when this sprite clicked\}} gives

\hfill\parbox{6cm}{\begin{Scratch}\beginbox{when this sprite clicked}\end{Scratch}}

\subsubsection{Turn}%%%%%%%%%%%%%%%%%%%%%%%%
Obtained with \texttt{\textbackslash turnbox\{<orientation>\}\{<angle>\}}.\\

\texttt{\textbackslash turnbox\{\}\{-145\}} gives \raisebox{-3mm}{\begin{Scratch}\turnbox{}{-145}\end{Scratch}}

\texttt{\textbackslash turnbox\{gauche\}\{30\}} gives \raisebox{-3mm}{\begin{Scratch}\turnbox{gauche}{30}\end{Scratch}}

You can also write \texttt{\textbackslash turnbox\{g\}\{30\}} or \texttt{\textbackslash turnbox\{G\}\{30\}}.

\subsubsection{Loops}%%%%%%%%%%%%%%%%%%%%%%%%
Obtained with

\texttt{\textbackslash boucle\{<text>\}\{<number of blocks inside>\}\{<type>\}},

where <type> is an integer which can be equal to 1 (\emph{repeat $x$ times} or \emph{repeat until}) or -1 (\emph{forever loop}).\\

\parbox{0.53\linewidth}{\texttt{\textbackslash boucle\{repeat \$x\$ times\}\{2\}\{1\}}
\par
\texttt{\textbackslash scbox\{two blocks\}\{red\}}
\par
\texttt{\textbackslash scbox\{in the loop\}\{gray\}}
}
\parbox{0.12\linewidth}{makes}
\parbox{0.2\linewidth}{\raisebox{-3mm}{
\begin{Scratch}[0.9]
\boucle{repeat $x$ times}{2}{1}
\scbox{two blocks}{red}
\scbox{in the loop}{gray}
\end{Scratch}}}

\begin{center}
\begin{tabular}{lcr}
\texttt{\textbackslash boucle\{forever loop\}\{3\}\{-1\}}&&\multirow{3}{*}{\begin{Scratch}[0.9]
\boucle{forever loop}{3}{-1}
\scbox{this time}{pink}
\scbox{three blocks}{blue}
\scbox{in the loop}{purple}
\end{Scratch}}\\
\texttt{\textbackslash scbox\{this time\}\{pink\}}&&\\
\texttt{\textbackslash scbox\{three blocks\}\{blue\}}&&\\
\texttt{\textbackslash scbox\{in the loop\}\{purple\}}&&\\
&&\\
&&\\
\end{tabular}\end{center}

\emph{Notice that if you want to put a loop into another loop, you have to count the correct number of blocks inside the main loop. Actually, a loop counts for two blocks (without the inside blocks).}

\subsubsection{If \dots\ Then}%%%%%%%%%%%%%%%%%%%%%%%%

\emph{Notice that you get this command with the same syntax seen above. Actually:}

\texttt{\textbackslash boucle\{<text>\}\{<number of blocks inside>\}\{2\}}.\\

\parbox{0.53\linewidth}{\texttt{\textbackslash boucle\{if 4 > 5 then\}\{1\}\{2\}}
\par
\texttt{\textbackslash scbox\{problem!\}\{app\}}
}
\parbox{0.12\linewidth}{produit}
\parbox{0.2\linewidth}{\raisebox{-3mm}{
\begin{Scratch}[0.9]
\boucle{if 4 > 5 then}{1}{2}
\scbox{problem!}{app}
\end{Scratch}}}

Remark: in order to properly type the \emph{if\dots then} test, see \emph{the small boxes} in section 3.3.

\subsubsection{If \dots\ Then \dots\ Else}%%%%%%%%%%%%%%%%%%%%%%%%
Obtained with

\texttt{\textbackslash sailors\{<text>\}\{<number of blocks inside>\}}

et

\texttt{\textbackslash simenon\{<number of blocks inside>\}}.\\

Typing:
\begin{verbatim}
\begin{Scratch}
\sailors{if it's an understandable example}{1}
\scbox{then it's all right}{app}
\simenon{2}
\scbox{don't panick}{stylo}
\scbox{see the section \emph{Examples}}{capt}
\end{Scratch}
\end{verbatim}

you get:\\

\begin{Scratch}
\sailors{if it's an understandable example}{1}
\scbox{then it's all right}{app}
\simenon{2}
\scbox{don't panick}{stylo}
\scbox{see the section \emph{Examples}}{capt}
\end{Scratch}

\subsubsection{More blocks}%%%%%%%%%%%%%%%%%%%%%%%%

You get them with \texttt{\textbackslash blocbox\{<text>\}}.\\

\texttt{\textbackslash blocbox\{triangle\}} gives \raisebox{-3mm}{\begin{Scratch}\blocbox{triangle}\end{Scratch}}

\subsubsection{Spécial control}%%%%%%%%%%%%%%%%%%%%%%%%
It's for \raisebox{-3mm}{\begin{Scratch}\kbox{stop \rb{all}}\end{Scratch}}\hspace{-1cm} and \raisebox{-2mm}{\begin{Scratch}\kbox{delete this clone}\end{Scratch}}\hspace{-1cm}.

These commands are obtained with \texttt{\textbackslash kbox\{<text>\}}.

%----------------------------------------------------------------------------------------------------------------------------------%
\subsection{Inside the Scratch commands: the little boxes}
How to get some specific commands, like: \raisebox{-3mm}{\begin{Scratch}\kbox{stop \rb{all}}\end{Scratch}}\hspace{-1cm}?

How to type \raisebox{-3mm}{\begin{Scratch}\scbox{wait until \hb[capt]{color \sqb{orange} is touching \sqb{green}?}\ }{ctrl}\end{Scratch}}\hspace{-1cm}?

or \raisebox{-3mm}{\begin{Scratch}\scbox{point towards \rb{mouse-pointer}}{mvt}\end{Scratch}}\hspace{-1cm}? or even

\raisebox{-3mm}{\begin{Scratch}
\scbox{change volume by \cb[ope]{pick random \cb[w]{1} to \cb[w]{10}} }{son}\end{Scratch}}\hspace{-1cm} ?

\subsubsection{The little rectangular boxes}%%%%%%%%%%%%%%%%%%%%%%%%
\begin{itemize}
\item In the \texttt{\textbackslash scbox}:

obtained with

\texttt{\textbackslash rb[<color>]\{<text>\}}\\

\item dans les \texttt{\textbackslash beginbox} :

you get them with

\texttt{\textbackslash rbb[<color>]\{<text>\}}\\
\end{itemize}

In both cases, <color> has by default the color of the box it is inside. In order to get a white rectangular box, you just have to put <color> at white or w.\\

Typing:
\begin{verbatim}
\begin{Scratch}
\scbox{play sound \rb{meow}}{son}
\scbox{think \rb[white]{Hmm\dots}}{app}
\scbox{ask \rb[w]{What's your name?} and wait}{capt}
\end{Scratch}
\end{verbatim}

you get:\\

\begin{Scratch}
\scbox{play sound \rb{meow}}{son}
\scbox{think \rb[white]{Hmm\dots}}{app}
\scbox{ask \rb[w]{What's your name?} and wait}{capt}
\end{Scratch}

\subsubsection{The small round boxes}%%%%%%%%%%%%%%%%%%%%%%%%

They are hollowed or embossed.

You get them with

\texttt{\textbackslash cb[<color>]\{<text>\}}\\

By default, <color> has the same color of the circular box it is inside. If <color> is white or w, the circular box is hollowed.\\

Typing:
\begin{verbatim}
\begin{Scratch}
\scbox{set video transparency to \cb{answer} \%}{capt}
\scbox{go to x:\cb[w]{x} y:\cb[white]{y}}{mvt}
\scbox{change tempo by \cb[data]{variable} }{son}
\end{Scratch}
\end{verbatim}

you get:\\

\begin{Scratch}
\scbox{set video transparency to \cb{answer} \%}{capt}
\scbox{go to x:\cb[w]{x} y:\cb[white]{y}}{mvt}
\scbox{change tempo by \cb[data]{variable} }{son}
\end{Scratch}


\subsubsection{The small hexagonal boxes}%%%%%%%%%%%%%%%%%%%%%%%%
Only for \emph{Sensing} et \emph{Operators} commands.

You get them with

\texttt{\textbackslash hb[<color>]\{<text>\}}\\

By default, <color> is ope.

Typing:
\begin{verbatim}
\begin{Scratch}
\boucle{if \hb{\cb[data]{variable}=\rb[w]{10}} then}{1}{1}
\scbox{wait until \hb[capt]{mouse down?}}{ctrl}
\end{Scratch}
\end{verbatim}

you get:\\

\begin{Scratch}
\boucle{if \hb{\cb[data]{variable}=\rb[w]{10}} then}{1}{1}
\scbox{wait until \hb[capt]{mouse down?}}{ctrl}
\end{Scratch}


\subsubsection{The small squared boxes}%%%%%%%%%%%%%%%%%%%%%%%%
Only for the colored squares.

You get them with

\texttt{\textbackslash sqb\{<color>\}}\\

Typing:
\begin{verbatim}
\begin{Scratch}
\scbox{set pen color to \sqb{brown}}{stylo}
\end{Scratch}
\end{verbatim}

you get: \raisebox{-3mm}{\begin{Scratch}
\scbox{set pen color to \sqb{brown}}{stylo}
\end{Scratch}}

%----------------------------------------------------------------------------------------------------------------------------------%
\subsection{Intricate commands}

\begin{Scratch}%%%%%%%%%%%%%%%%%%%%%%%% 1
\beginbox{clone}
\boucle{repeat until \hb[capt]{color \sqb{black}
 is touching \sqb{yellow} ? }}{1}{1}
\scbox{go to x: \cb[ope]{\cb[data]{x}+\cb[w]{10}} y: \cb[data]{y}}{mvt}
\boucle{if \hb{\cb[data]{y}<\cb[capt]{answer}} then}{3}{1}
\scbox{set \rb{y} to \cb[son]{volume}}{data}
\scbox{say \rb[w]{Hello!} for \cb[capt]{distance to
\rb{mouse-pointer} } secs}{app}
\kbox{stop \rb{all}}
\turnbox{2}{-146}
\end{Scratch}

Got with:

\begin{verbatim}
\begin{Scratch}
\beginbox{clone}
\boucle{repeat until \hb[capt]{color \sqb{black}
 is touching \sqb{yellow} ? }}{1}{1}
\scbox{go to x: \cb[ope]{\cb[data]{x}+\cb[w]{10}} y: \cb[data]{y}}{mvt}
\boucle{if \hb{\cb[data]{y}<\cb[capt]{answer}} then}{3}{1}
\scbox{set \rb{y} to \cb[son]{volume}}{data}
\scbox{say \rb[w]{Hello!} for \cb[capt]{distance to
\rb{mouse-pointer} } secs}{app}
\kbox{stop \rb{all}}
\turnbox{2}{-146}
\end{Scratch}
\end{verbatim}

%----------------------------------------------------------------------------------------------------------------------------------%
\subsection{Other sort of commands}

\subsubsection{In the loops}%%%%%%%%%%%%%%%%%%%%%%

You need to use the command \texttt{\textbackslash blank} when in the Scratch program, two loops ends at the same time.\\

Typing:
\begin{verbatim}
\begin{Scratch}
\boucle{repeat \cb[w]{3}}{4}{1}
\scbox{move \cb[w]{10} steps}{mvt}
\boucle{repeat \cb[w]{5}}{1}{1}
\scbox{change x by \cb[w]{10}}{mvt}
\scbox{this block is not ok}{data}
\end{Scratch}
\end{verbatim}

you get:\\

\begin{Scratch}
\boucle{repeat \cb[w]{3}}{4}{1}
\scbox{move \cb[w]{10} steps}{mvt}
\boucle{repeat \cb[w]{5}}{1}{1}
\scbox{change x by \cb[w]{10}}{mvt}
\scbox{this block is not ok}{data}
\end{Scratch}

\vspace{0.5cm}

Whereas typing:
\begin{verbatim}
\begin{Scratch}
\boucle{repeat \cb[w]{3}}{4}{1}
\scbox{move \cb[w]{10} steps}{mvt}
\boucle{repeat \cb[w]{5}}{1}{1}
\scbox{change x by \cb[w]{10}}{mvt}
\blank
\scbox{this block is \emph{now} ok}{data}
\end{Scratch}
\end{verbatim}

you get:\\

\begin{Scratch}
\boucle{repeat \cb[w]{3}}{4}{1}
\scbox{move \cb[w]{10} steps}{mvt}
\boucle{repeat \cb[w]{5}}{1}{1}
\scbox{change x by \cb[w]{10}}{mvt}
\blank
\scbox{this block is \emph{now} ok}{data}
\end{Scratch}

\vspace{0.5cm}

If you type:
\begin{verbatim}
\begin{Scratch}
\boucle{repeat \cb[w]{3}}{5}{1}
\scbox{move \cb[w]{10} steps}{mvt}
\boucle{repeat \cb[w]{5}}{1}{1}
\scbox{change x by \cb[w]{10}}{mvt}
\scbox{this block is in another position}{data}
\end{Scratch}
\end{verbatim}

you get:\\

\begin{Scratch}
\boucle{repeat \cb[w]{3}}{5}{1}
\scbox{move \cb[w]{10} steps}{mvt}
\boucle{repeat \cb[w]{5}}{1}{1}
\scbox{change x by \cb[w]{10}}{mvt}
\scbox{this block is in another position}{data}
\end{Scratch}

\subsubsection{How to draw the cat}

You can get the cover cat with:

\texttt{\small\textbackslash Scratchy[<scale>][<lines width>]}

By default, the scale is 0.25 and the lines width is set at 0.25 pt.\\

Here is the code for the cover:
\begin{verbatim}
\parbox{1ex}{\Scratchy[0.1][0.1]}\\

\hspace{1cm}\parbox{1ex}{\Scratchy[0.2][0.2]}\\

\hspace{2cm}\parbox{1ex}{\Scratchy[0.5][1]}\\

\hspace{5cm}\parbox{1ex}{\Scratchy[0.75][1.5]}\\
\end{verbatim}

\newpage
%----------------------------------------------------------------------------------------------------------------------------------%
%----------------------------------------------------------------------------------------------------------------------------------%
\section{Known problems and solutions}
\begin{enumerate}
\item
The black little triangle doesn't exist in the command \emph{point in direction} (motion). You have to write it down.
\begin{verbatim}
\scbox{point in direction \cb[w]{90 \scriptsize$\blacktriangledown$}}{mvt}
\end{verbatim}
\raisebox{-3mm}{\begin{Scratch}\scbox{point in direction \cb[w]{90 \scriptsize$\blacktriangledown$}}{mvt}\end{Scratch}}\\

\item The height of the boxes is set. Therefor, you cannot put a lot of under-commands in a Scratch command.\\

\item When you need to put only one Scratch command into some text, it is not vertically centered. You can use a: \texttt{\textbackslash raisebox\{-3mm\}}.\\

\item There is also a tiny horizontal gap. When a Scratch environment is over, you often need to add a \texttt{\textbackslash hspace\{-1cm\}}.\\

\item The compile time is sometimes long!
\end{enumerate}

%----------------------------------------------------------------------------------------------------------------------------------%
%----------------------------------------------------------------------------------------------------------------------------------%
\section{Commands summary}

\begin{tabular}{m{5cm}l}%%%%%%%%%%
\texttt{\small\textbackslash beginbox\{\}}

&\begin{Scratch}[0.75]
\beginbox{}
\end{Scratch}
\\%%%%%%%%%%
\texttt{\small\textbackslash beginbox\{<text>\}}

\tiny(when this sprite clicked)
&\begin{Scratch}[0.75]
\beginbox{quand ce lutin est cliqué}
\end{Scratch}\\%%%%%%%%%%
\texttt{\small\textbackslash beginbox\{clone\}}

&\begin{Scratch}[0.75]
\beginbox{clone}
\end{Scratch}
\\%%%%%%%%%%
\texttt{\small\textbackslash blocbox\{<text>\}}

&\begin{Scratch}[0.75]
\blocbox{function}
\end{Scratch}
\\%%%%%%%%%%
\texttt{\small\textbackslash turnbox\{\}\{90\}}

&\begin{Scratch}[0.75]
\turnbox{}{90}
\end{Scratch}\\%%%%%%%%%%
\texttt{\small\textbackslash turnbox\{g\}\{-270\}}

\tiny(or <gauche> or <G> or <g>)
&\begin{Scratch}[0.75]
\turnbox{g}{-270}
\end{Scratch}
\\%%%%%%%%%%
\texttt{\small\textbackslash scbox\{<text>\}\{<color>\}}

&\begin{Scratch}[0.75]
\scbox{any color, any text}{purple}
\end{Scratch}\\%%%%%%%%%%
\texttt{\small\textbackslash boucle\{repeat\}\{2\}\{1\}}
\tiny(\{<text>\}\{<nbr blocks>\}\{<type>\})
\vspace{3cm}
&\begin{Scratch}[0.75]
\boucle{repeat}{2}{1}
\end{Scratch}\vspace{-1.5cm}
\\%%%%%%%%%%
\texttt{\small\textbackslash boucle\{forever\}\{1\}\{-1\}}

\tiny(\{<text>\}\{<nbr blocks>\}\{<type>\})
\vspace{2cm}
&\begin{Scratch}[0.75]
\boucle{forever}{1}{-1}
\end{Scratch}\vspace{-1.2cm}
\\%%%%%%%%%%
\texttt{\small\textbackslash boucle\{if \dots then\}\{1\}\{2\}}

\tiny(\{<text>\}\{<nbr blocks>\}\{<type>\})
\vspace{2cm}
&\begin{Scratch}[0.75]
\boucle{if \dots then}{1}{2}
\end{Scratch}\vspace{-1.2cm}
\\%%%%%%%%%%

\texttt{\small\textbackslash sailors\{if\dots then\dots\}\{2\}}

\tiny(\{<text>\}\{<nbr blocks>\})
\vspace{2cm}
&\begin{Scratch}[0.75]
\sailors{fi\dots then\dots}{2}
\end{Scratch}\vspace{-1cm}
\\%%%%%%%%%%
\texttt{\small\textbackslash simenon\{<nbre blocks>\}}

\tiny(ici, \textbackslash simenon\{1\})
\vspace{2.2cm}
&\begin{Scratch}[0.75]
\whitesailors{il faut que ce }{1}
\simenon{1}
\end{Scratch}\vspace{-1.2cm}
\\%%%%%%%%%%
\texttt{\small\textbackslash kbox\{<text>\}}

&\begin{Scratch}[0.75]
\kbox{delete this clone}
\end{Scratch}
\\%%%%%%%%%%
\end{tabular}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{tabular}{m{5cm}l}
\texttt{\small\textbackslash rb\{<text>\}}

\tiny (\texttt{\textbackslash rb\{variable\}})
&\begin{Scratch}[0.75]
\scbox{\phantom{tex} \rb{variable} \phantom{tex}}{data}
\end{Scratch}
\\
\texttt{\small\textbackslash rb[w]\{<text>\}}

\tiny(ou \texttt{\textbackslash rb[white]\{<text>\}})
&\begin{Scratch}[0.75]
\scbox{\phantom{tex} \rb[w]{text} }{data}
\end{Scratch}
\\
\texttt{\small\textbackslash rbb\{<text>\}}

\tiny(only for \texttt{\textbackslash beginbox})

\texttt{\textbackslash beginbox\{when I receive \textbackslash rbb\{message1\}\}}
&\begin{Scratch}[0.75]
\beginbox{when I receive \rbb{message1}}
\end{Scratch}
\\

\texttt{\small\textbackslash cb\{<text>\}}

\tiny(transparent)
&\begin{Scratch}[0.75]
\scbox{\phantom{rex} \cb{answer}}{ctrl}
\end{Scratch}
\\
\texttt{\small\textbackslash cb[w]\{<text>\}}

\tiny(ou \textbackslash cb[white]\{<text>\})
&\begin{Scratch}[0.75]
\scbox{\phantom{rex} \cb[w]{answer}}{ctrl}
\end{Scratch}
\\
\texttt{\small\textbackslash cb[<color>]\{<text>\}}

\texttt{\tiny\textbackslash cb[ope]\{answer\}}
&\begin{Scratch}[0.75]
\scbox{\phantom{rex} \cb[ope]{answer}}{ctrl}
\end{Scratch}
\\
\texttt{\small\textbackslash hb\{<text>\}}

&\begin{Scratch}[0.75]
\scbox{\phantom{rex} \hb{answer}}{ctrl}
\end{Scratch}
\\

\texttt{\small\textbackslash hb[capt]\{<text>\}}

&\begin{Scratch}[0.75]
\scbox{\phantom{rex} \hb[capt]{answer}}{ctrl}
\end{Scratch}
\\
\texttt{\small\textbackslash sqb\{<color>\}}

&\begin{Scratch}[0.75]
\scbox{set pen color to \sqb{red}}{stylo}
\end{Scratch}
\\

\end{tabular}

%----------------------------------------------------------------------------------------------------------------------------------%
%----------------------------------------------------------------------------------------------------------------------------------%
\newpage
\section{Examples of programs (in French):}

\begin{verbatim}
\begin{Scratch}
\boucle{répéter \cb[w]{3} fois}{5}{1}
\scbox{avancer de \cb[w]{10}}{mvt}
\boucle{répéter \cb[w]{5} fois}{1}{1}
\scbox{ajouter \cb[w]{10} à x}{mvt}
\scbox{ce bloc est placé autrement}{data}
\scbox{un nouveau bloc}{son}
\end{Scratch}
\end{verbatim}

\begin{verbatim}
\begin{Scratch}
\beginbox{quand \rbb{espace} est pressé}
\boucle{répéter \cb[w]{3} fois}{8}{1}
	\scbox{aller à x: \cb[w]{0} y: \cb[data]{y}}{mvt}
	\boucle{répéter \cb[w]{2} fois}{3}{1}
		\scbox{mettre \rb{x} à \rb[w]{0}}{data}
		\scbox{ajouter à \rb{y} \cb[w]{10}}{data}
		\scbox{mettre la couleur du stylo à \sqb{red}}{stylo}
	\scbox{mon bloc}{bloc}
	\scbox{montrer}{app}
\scbox{effacer tout}{stylo}
\end{Scratch}
\end{verbatim}
\begin{center}
\begin{tabular}{cc}%\hline
\parbox[b]{5.5cm}{
\hspace{1cm}deuxième programme $\rightarrow$
\vspace{2em}
\par
premier programme
\par
\hspace{1.25em}$\downarrow$
\par
\begin{Scratch}
\boucle{répéter \cb[w]{3} fois}{5}{1}
\scbox{avancer de \cb[w]{10}}{mvt}
\boucle{répéter \cb[w]{5} fois}{1}{1}
\scbox{ajouter \cb[w]{10} à x}{mvt}
\scbox{ce bloc est placé \dots}{data}
\scbox{un nouveau bloc}{son}
\end{Scratch}
}
&
\begin{Scratch}
\beginbox{quand \rbb{espace} est pressé}
\boucle{répéter \cb[w]{3} fois}{8}{1}
	\scbox{aller à x: \cb[w]{0} y: \cb[data]{y}}{mvt}
	\boucle{répéter \cb[w]{2} fois}{3}{1}
		\scbox{mettre \rb{x} à \rb[w]{0}}{data}
		\scbox{ajouter à \rb{y} \cb[w]{10}}{data}
		\scbox{mettre la couleur du stylo à \sqb{red}}{stylo}
	\scbox{mon bloc}{bloc}
	\scbox{montrer}{app}
\scbox{effacer tout}{stylo}
\end{Scratch}
\end{tabular}
\end{center}
\newpage
%----------------------------------------------------------------------------------------------------------------------------------%
\subsection{Loops of loops}

%%%%%%%%%%%%%%%%%%%%%%%% 1
\begin{verbatim}
\begin{Scratch}
\beginbox{quand \rb{chronomètre} > \cb[w]{10}}

\sailors{si \hb[capt]{touche \rb{espace} pressée?} alors}{12}

	\sailors{si \hb[capt]{souris pressée?} alors}{1}
		\scbox{aller à x: \cb[w]{0} y: \cb[w]{0}}{mvt}

	\simenon{2}
		\scbox{donner la valeur \cb[w]{0} à x}{mvt}
		\scbox{ajouter \cb[w]{10} à y}{mvt}

	\sailors{si couleur \sqb{son} touchée?}{1}
		\scbox{aller à x: \cb[w]{0} y: \cb[w]{0}}{mvt}

	\simenon{1}
		\scbox{donner la valeur \cb[w]{0} à x}{mvt}
		
	\simenon{1}
		\scbox{donner la valeur \cb[w]{0} à y}{mvt}

\sailors{si \hb[capt]{souris pressée?} alors}{1}
	\scbox{ajouter \cb[w]{10} à y}{mvt}

\simenon{2}
	\scbox{donner la valeur \cb[w]{0} à x}{mvt}
	\scbox{cacher la variable \rb{variable}}{data}

\end{Scratch}
\end{verbatim}

\begin{center}
\begin{Scratch}[1]%%%%%%%%%%%%%%%%%%%%%%%% 1
\beginbox{quand \rb{chronomètre} > \cb[w]{10}}

\sailors{si \hb[capt]{touche \rb{espace} pressée?} alors}{12}

	\sailors{si \hb[capt]{souris pressée?} alors}{1}
		\scbox{aller à x: \cb[w]{0} y: \cb[w]{0}}{mvt}

	\simenon{2}
		\scbox{donner la valeur \cb[w]{0} à x}{mvt}
		\scbox{ajouter \cb[w]{10} à y}{mvt}

	\sailors{si couleur \sqb{son} touchée?}{1}
		\scbox{aller à x: \cb[w]{0} y: \cb[w]{0}}{mvt}

	\simenon{1}
		\scbox{donner la valeur \cb[w]{0} à x}{mvt}
		
	\simenon{1}
		\scbox{donner la valeur \cb[w]{0} à y}{mvt}

\sailors{si \hb[capt]{souris pressée?} alors}{1}
	\scbox{ajouter \cb[w]{10} à y}{mvt}

\simenon{2}
	\scbox{donner la valeur \cb[w]{0} à x}{mvt}
	\scbox{cacher la variable \rb{variable}}{data}

\end{Scratch}\end{center}
\newpage
%%%%%%%%%%%%%%%%%%%%%%%% 2
\begin{verbatim}
\begin{Scratch}
\beginbox{}

\sailors{si couleur \sqb{stylo} touchée?}{12}

	\sailors{si \hb[capt]{souris pressée?} alors}{6}
		\scbox{aller à x: \cb[w]{0} y: \cb[w]{0}}{mvt}
		
 		\sailors{si \hb[capt]{touche \rb{espace} pressée?} alors}{1}
			\scbox{aller à x: \cb[w]{0} y: \cb[w]{0}}{mvt}

		\simenon{1}
			\scbox{donner la valeur \cb[w]{0} à x}{mvt}
			
	\simenon{2}
		\scbox{donner la valeur \cb[w]{0} à x}{mvt}
		\scbox{ajouter \cb[w]{10} à y}{mvt}
		
	\simenon{1}
		\scbox{donner la valeur \cb[w]{0} à x}{mvt}

\end{Scratch}
\end{verbatim}
\begin{center}
\begin{Scratch}[1]%%%%%%%%%%%%%%%%%%%%%%%% 2
\beginbox{}

\sailors{si couleur \sqb{stylo} touchée?}{12}

	\sailors{si \hb[capt]{souris pressée?} alors}{6}
		\scbox{aller à x: \cb[w]{0} y: \cb[w]{0}}{mvt}
		
 		\sailors{si \hb[capt]{touche \rb{espace} pressée?} alors}{1}
			\scbox{aller à x: \cb[w]{0} y: \cb[w]{0}}{mvt}

		\simenon{1}
			\scbox{donner la valeur \cb[w]{0} à x}{mvt}
			
	\simenon{2}
		\scbox{donner la valeur \cb[w]{0} à x}{mvt}
		\scbox{ajouter \cb[w]{10} à y}{mvt}
		
	\simenon{1}
		\scbox{donner la valeur \cb[w]{0} à x}{mvt}

\end{Scratch}\end{center}

\newpage
%%%%%%%%%%%%%%%%%%%%%%%% 3
\begin{verbatim}
\begin{Scratch}
\beginbox{}
\boucle{répéter indéfiniment}{13}{-1}
	\turnbox{}{24}
	\boucle{répéter \cb[w]{4} fois}{2}{1}
		\scbox{stylo en position d'écriture}{stylo}
		\scbox{ajouter \cb[w]{20} au tempo}{son}
	\boucle{quand le lutin s'en va}{6}{1}
		\scbox{cacher la variable \rb{A}}{data}
		\scbox{costume suivant}{app}
		\scbox{arrêter tous les sons}{son}
		\turnbox{g}{24}
		\scbox{stylo en position d'écriture}{stylo}
		\scbox{ajouter \cb[w]{20} au tempo}{son}
	\blank
\end{Scratch}
\end{verbatim}
\begin{center}
\begin{Scratch}[1]%%%%%%%%%%%%%%%%%%%%%%%% 3
\beginbox{}
\boucle{répéter indéfiniment}{13}{-1}
	\turnbox{}{24}
	\boucle{répéter \cb[w]{4} fois}{2}{1}
		\scbox{stylo en position d'écriture}{stylo}
		\scbox{ajouter \cb[w]{20} au tempo}{son}
	\boucle{répéter \cb[w]{4} fois}{6}{1}
		\scbox{cacher la variable \rb{A}}{data}
		\scbox{costume suivant}{app}
		\scbox{arrêter tous les sons}{son}
		\turnbox{g}{24}
		\scbox{stylo en position d'écriture}{stylo}
		\scbox{ajouter \cb[w]{20} au tempo}{son}
	\blank
\end{Scratch}
\end{center}
\newpage
%%%%%%%%%%%%%%%%%%%%%%%% 4
\begin{verbatim}
\begin{Scratch}
\beginbox{quand on le veut}
\boucle{répéter un certain nombre de fois}{8}{1}
	\scbox{aller à x: \cb[w]{0} y: \cb[w]{0}}{mvt}
	\boucle{le dernier ??}{2}{1}
		\scbox{on peut faire}{gray}
		\scbox{ce que l'on veut}{black}
	\boucle{ne pas répéter}{1}{1}
	\scbox{faux bloc}{brown}
	\blank
\scbox{dernier bloc}{pink}
\end{Scratch}
\end{verbatim}

\begin{center}
\begin{Scratch}[1]%%%%%%%%%%%%%%%%%%%%%%%% 4
\beginbox{quand on le veut}
\boucle{répéter un certain nombre de fois}{8}{1}
	\scbox{aller à x: \cb[w]{0} y: \cb[w]{0}}{mvt}
	\boucle{se répéter que}{2}{1}
		\scbox{l'on peut faire}{gray}
		\scbox{ce que l'on veut}{black}
	\boucle{ne pas répéter}{1}{1}
	\scbox{faux bloc}{brown}
	\blank
\scbox{dernier bloc}{pink}
\end{Scratch}
\end{center}
\newpage
%%%%%%%%%%%%%%%%%%%%%%%% 5
\begin{verbatim}
\begin{Scratch}
\beginbox{}
\boucle{répéter \cb[w]{3} fois}{19}{1}
	\scbox{costume suivant}{app}
	\scbox{arrêter tous les sons}{son}
	\turnbox{1}{24}
	\scbox{stylo en position d'écriture}{stylo}
	\boucle{répéter \cb[data]{compteur} fois}{10}{1}
		\scbox{ajouter \cb[w]{20} au tempo}{son}
		\boucle{répéter \cb[ope]{\cb[data]{A}+1} fois}{6}{1}
			\scbox{réinitialiser le chronomètre}{capt}
			\boucle{répéter jusqu'à \hb[capt]{\rb{pointeur de souris} touché?}}{2}{1}
				\scbox{cacher la variable \rb{A}}{data}
				\scbox{avancer de 35}{mvt}
			\scbox{regroupe \rb[w]{hello}\rb[w]{world}}{ope}
		\scbox{nouveau bloc}{bloc}
	\turnbox{2}{-146}
	\scbox{estampiller}{stylo}
	\scbox{annuler les effets graphiques}{app}
\sailors{si ça marche}{1}
	\scbox{je suis content}{stylo}
\simenon{1}
	\scbox{je suis déçu}{app}
\end{Scratch}
\end{verbatim}

\begin{center}
\begin{Scratch}[1]%%%%%%%%%%%%%%%%%%%%%%%% 5
\beginbox{}
\boucle{répéter \cb[w]{3} fois}{19}{1}
	\scbox{costume suivant}{app}
	\scbox{arrêter tous les sons}{son}
	\turnbox{1}{24}
	\scbox{stylo en position d'écriture}{stylo}
	\boucle{répéter \cb[data]{compteur} fois}{10}{1}
		\scbox{ajouter \cb[w]{20} au tempo}{son}
		\boucle{répéter \cb[ope]{\cb[data]{A}+1} fois}{6}{1}
			\scbox{réinitialiser le chronomètre}{capt}
			\boucle{répéter jusqu'à \hb[capt]{\rb{pointeur de souris} touché?}}{2}{1}
				\scbox{cacher la variable \rb{A}}{data}
				\scbox{avancer de 35}{mvt}
			\scbox{regroupe \rb[w]{hello}\rb[w]{world}}{ope}
		\scbox{nouveau bloc}{bloc}
	\turnbox{2}{-146}
	\scbox{estampiller}{stylo}
	\scbox{annuler les effets gRaphiques}{app}
\sailors{si ça marche}{1}
	\scbox{je suis content}{stylo}
\simenon{1}
	\scbox{je suis déçu}{app}
\end{Scratch}
\end{center}

\newpage
%----------------------------------------------------------------------------------------------------------------------------------%
%----------------------------------------------------------------------------------------------------------------------------------%
\section{Conclusion}

Please feel free to leave a comment:

Thibault.Ralet\at ac-clermont.fr.

Thank you!

\end{document}
%%
%% This is file `ScratchX.sty',
%%
%% Copyright (C) Thibault Ralet - Thibault.Ralet@ac-clermont.fr
%%
%% 16 mars 2017 (version 0.1) - 27 juillet 2017 (version 1.1)
%% 
%% the LaTeX Project Public License v1.3c or later, see http://www.latex-project.org/lppl.txt
%%
%% Unlimited copying and redistribution of this file are permitted as
%% long as this file is not modified.  Modifications, and distribution
%% of modified versions, are permitted, but only if the resulting file
%% is renamed.