%% %% examples.tex %% examples using the rubikrotation package v3.0 %% Requires rubik packages (v3.0) and also the tikz package %% Part of the Rubik bundle (www.ctan.org/pkg/rubik) %% RWD Nickalls & A Syropoulos %% September 25, 2015 %%--------NOTE------------------------------------------- %% USAGE: (pdf)latex --shell-escape example-rot1.tex %% run three times to get all labels and fig nos correct %%------------------------------------------------------- \documentclass[a4paper]{article} \usepackage{tikz} %% load tikz BEFORE rubikcube \usepackage{rubikcube,rubikrotation} \usepackage{url} %------------- \pagestyle{myheadings} \markright{\textsc{rubikrotation} package v3.0 (Sept 2015) \hspace{0.5cm}\texttt{www.ctan.org/pkg/rubik} \hspace{0.5cm}examples.tex} %----------- %% some well known sequences (see the web page of Reid) \newcommand{\sixTs}{*sixTs,F2,R2,U2,Fp,B,D2,L2,F,B} \newcommand{\CubeInCube}{*CubeInCube,F,L,F,Up,R,U,F2,L2,Up,Lp,B,Dp,Bp,L2,U} \newcommand{\sixspot}{[sixspot],U,Dp,R,Lp,F,Bp,U,Dp} \newcommand{\superflip}{U,R2,Fp,R,Dp,L,Bp,R,Up,R,Up,D,% Fp,U,Fp,Up,Dp,B,Lp,Fp,Bp,Dp,Lp} %-------------------- %% brace and bracket \newcommand{\Rubikbracket}[1]{$\left(\mbox{#1}\right)$} \newcommand{\Rubikbrace}[1]{$\left\{\mbox{#1}\right\}$} %--------------- %% increase text space to make room \addtolength{\oddsidemargin}{-1.5cm} \addtolength{\textwidth}{3cm} \addtolength{\textheight}{1cm} %%================== \begin{document} \begin{center} \Huge{Rubikrotation examples}\,\footnote{These examples are part of the \textsc{rubikrotation} package, and assume some familiarity with the Rubik bundle documentation \texttt{rubikcube.pdf} and \texttt{rubikrotation.pdf}.} \end{center} \bigskip \textsc{note}: Since the \verb!\RubikRotation! command calls the perl script \texttt{rubikrotation.pl} this \texttt{.tex}~file needs to be run using the \verb!--shell-escape! command-line switch, as follows: \begin{quote} \begin{verbatim} latex --shell-escape example-tex \end{verbatim} \end{quote} If you forget to use the command-line switch, the file will run OK, but the cubes will remain in the initial `solved' configuration. The \texttt{tikz} package must be loaded before the two \texttt{rubik..} packages. %%------------------ \section*{Example~1} In Figure~\ref{fig:cubeincube} we show the so-called ``sixspot'' configuration, generated from a solved cube using the rotation sequence \rr{U}, \rr{Dp}, \rr{R}, \rr{Lp}, \rr{F}, \rr{Bp}, \rr{U}, \rr{Dp}\ (see the website of Reid at \url{www.cflmath.edu/~reid/Rubik/patterns.html}). %%--------FIGURE 1 ----------- \begin{figure}[hbt] \centering \RubikCubeSolved \RubikRotation{\sixspot} \ShowCube{7cm}{0.7}{\DrawRubikCubeFlat} \caption{\label{fig:cubeincube}The so-called `sixspot' configuration (Reid).} \end{figure} %---------------- {\noindent}Creating a macro to hold a rotation sequence greatly facilitates their use, as follows: \begin{quote} \begin{verbatim} \newcommand{\sixspot}{[sixspot],U,Dp,R,Lp,F,Bp,U,Dp} \end{verbatim} \end{quote} We can now process this sequence using its macro name as an argument for the \verb!\RubikRotation! command. The code used for the above Figure uses the \verb!\ShowCube{}{}{}! command for which \verb!#1! is the minipage width, \verb!#2! is the tikzpicture scale factor (0--1), and \verb!#3! is a Rubik \verb!\Draw..! command (see \textsc{rubikrotation} documentation for details). \begin{quote} \begin{verbatim} \usepackage{tikz,rubikcube,rubikrotation} \thispagestyle{empty} %% disables pagenumbers ... \begin{figure}[hbt] \centering \RubikCubeSolved \RubikRotation{\sixspot} \ShowCube{7cm}{0.7}{\DrawRubikCubeFlat} \caption{...} \end{figure} \end{verbatim} \end{quote} Note that running the `sixspot' sequence 3 times returns the cube to its original `solved' state (it is a so-called `order~3' sequence). The~command for processing it three times is \verb!\RubikRotation[3]{\sixspot}!. \pagebreak %%------------------------- \section*{Example~2} In this example we demonstrate the use of the \verb!\ShowRubikErrors! command, which places a copy of the Perl output file \verb!rubikstateERRORS.dat! underneath the graphic so you can see a list of all the errors, if any (in this example we have introduced a few errors---wrong minipage width, typos and some animals---into the rotation sequence). It is important to note that the \verb!\ShowRubikErrors! command must be placed \textit{after} the TikZ picture environment (i.e.,~in this case after the \verb!\ShowCube! command). Note that full details of all errors are also included in the .log file. %%--------FIGURE 2 ----------- \RubikCubeSolved \RubikRotation{[sixspot],U,Dp,R,Lp,F,Bp,U,Dpppp,cat,dog} \begin{figure}[hbt] \centering \ShowCubeF{4.5cm}{0.7}{\DrawRubikCubeFlat} \ShowRubikErrors \parbox{0.7\textwidth}{% \caption{\label{fig:cubeincubeE}The same `sixspot' sequence of rotations as shown in Example~1, but now with some errors (wrong minipage-width, typos \& animals\,!) in the rotation sequence (it should be just \texttt{U,Dp,R,Lp,F,Bp,U,Dp}).} } \end{figure} {\noindent}In this example we have used the F version of the \verb!\ShowCube! command (\verb!\ShowCubeF!) which places an fbox around the image so you can see the extent of any white space etc. This reveals that the set minipage-width (4.5cm) in the \verb!\ShowCubeF! command---see code below---is too narrow: it should be 7cm ($10 \times 0.7$) to just include the whole image. Once fixed, we can remove the F from the \verb!\ShowCubeF! command. Note also that only `\verb!\Draw...!' commands really need to be inside the TikZ picture environment (i.e.,~inside the \verb!\ShowCube! command). The above figure was generated by the following code. %----------------- \begin{quote} \begin{verbatim} \RubikCubeSolved \RubikRotation{[sixspot],U,Dp,R,Lp,F,Bp,U,Dpppp,cat,dog} \begin{figure}[hbt] \centering \ShowCubeF{4.5cm}{0.7}{\DrawRubikCubeFlat} \ShowRubikErrors \caption{....} \end{figure} \end{verbatim} \end{quote} Even if the \verb!\ShowRubikErrors! command is not used, it is always a good idea to check the file \verb!rubikstateERRORS.dat! after a \LaTeX\ run, since this file will reveal any errors. \pagebreak %------------------------------- \section*{Example~3} In this example we use the \verb!\RubikRotation! command to scramble a `solved' Rubik cube via a sequence of 120 random rotations, using the following command (the details of the process can be seen in the \texttt{.log} file): \begin{quote} \begin{verbatim} \RubikRotation{random,120} \end{verbatim} \end{quote} In this example, we also save the final configuration (state) to a file (\texttt{exampfig4.tex}) using the command \verb!\SaveRubikState{exampfig4.tex}! so we can display the cube in the same state later (see Example~4) but in a different format. Note that since we are using a random sequence, it follows that each time this file is run not only will a visually different cube be generated, but the same state will be shown in both Figures~\ref{fig:randomone} and \ref{fig:randomtwo}. %%--------FIGURE 3 ----------- \begin{figure}[hbt] \centering \RubikCubeSolved \RubikRotation{random,120} \SaveRubikState{exampfig4.tex} \ShowCube{8.4cm}{0.7}{\DrawRubikFlat} \parbox{0.7\textwidth}{% \caption{\label{fig:randomone}This shows a cube generated by 120 random rotations}} \end{figure} %---------------- \begin{quote} \begin{verbatim} \usepackage{tikz,rubikcube,rubikrotation} ... \begin{figure}[hbt] \centering \RubikCubeSolved \RubikRotation{random,120} \SaveRubikState{exampfig4.tex} \ShowCube{8.4cm}{0.7}{\DrawRubikFlat} \caption{....} \end{figure} \end{verbatim} \end{quote} Q: How do we determine the minipage-width (8.4cm) in the \verb!\ShowCube! command? A: The object is 12 cubie squares wide (1\,cm each). Since the specified TikZ scale factor is~$0.7$ here, then the true width of the image is $12 \times 0.7 = 8.4$\,cm. If you change the scale then the size of the image will change, and a new width will be required to just fit the image. Note that in this particular case (only a single image in the `figure' environment), since the \verb!\ShowCube! command places the image centrally inside the minipage, the image will in fact be centrally placed in the \verb!\textwidth! provided the image is \textit{smaller} than the fbox---i.e.,~if we used instead a minipage-width of, say, 12\,cm the image would still appear centered in the \verb!\textwidth! in this case. However, when there are several images in the `figure', then the spacing may appear strange unless each image closely fits its own minipage-width etc. It is often useful, therefore, to check the size of the fbox (using the \verb!\ShowCubeF! command). \pagebreak %---------------------- \section*{Example~4} In this example we display a cube having the same state as that shown in Figure~\ref{fig:randomone}. The configuration state was saved from Figure~\ref{fig:randomone} using the command \verb!\SaveRubikState{exampfig4.tex}!, and then input here using \verb!\input{exampfig4.tex}!. These commands therefore allow the state of a previous cube to be saved to a file, and then displayed again later in a different format. %%-----------FIGURE 4 ----------- \begin{figure}[hbt] \centering \input{exampfig4.tex} \ShowCube{4cm}{0.8}{\DrawRubikCubeLD} \parbox{0.7\textwidth}{% \caption{\label{fig:randomtwo}This shows a Rubik cube in exactly the same state as the one shown in Figure~\ref{fig:randomone}} } \end{figure} %%--------------------------------- \begin{quote} \begin{verbatim} \usepackage{tikz,rubikcube,rubikrotation} ... \begin{figure}[hbt] \centering \input{exampfig4.tex} \Showcube{4cm}{0.8}{\DrawRubikCubeLD} \caption{....} \end{figure} \end{verbatim} \end{quote} \pagebreak %---------------------- \section*{Example~5} Here we show a convenient way of displaying a series of small cubes showing a sequence of rotations (\rr{U}, \rr{R}, \rr{F}). \begin{figure}[hbt] \centering \RubikCubeSolved \ShowCube{2cm}{0.5}{\DrawRubikCubeRU} \Rubik{U} \RubikRotation{U}\ShowCube{2cm}{0.5}{\DrawRubikCubeRU} \Rubik{R} \RubikRotation{R}\ShowCube{2cm}{0.5}{\DrawRubikCubeRU} \Rubik{F} \RubikRotation{F}\ShowCube{2cm}{0.5}{\DrawRubikCubeRU} \caption{The rotations \rr{U}, \rr{R}, \rr{F}\ on a solved cube.} \end{figure} The code for the above sequence is as follows: \begin{quote} \begin{verbatim} \usepackage{tikz,rubikcube,rubikrotation} ... \begin{figure}[hbt] \centering \RubikCubeSolved \ShowCube{2cm}{0.5}{\DrawRubikCubeRU} \Rubik{U} \RubikRotation{U}\ShowCube{2cm}{0.5}{\DrawRubikCubeRU} \Rubik{R} \RubikRotation{R}\ShowCube{2cm}{0.5}{\DrawRubikCubeRU} \Rubik{F} \RubikRotation{F}\ShowCube{2cm}{0.5}{\DrawRubikCubeRU} \caption{The rotations \rr{U}, \rr{R}, \rr{F}\ on a solved cube.} \end{figure} \end{verbatim} \end{quote} \pagebreak %---------------------- \section*{Example~6} In this example we highlight the fact that commands used inside a TikZ picture environment remain local to that environment. Note that this applies with other environments too; for example, with both the \verb!\minipage! the \verb!\figure! environments. Consequently, it is generally best when drawing a sequence of cubes to reserve the TikZ picture environment (i.e.,~the \verb!\ShowCube! command) only for Rubik \verb!\Draw..! commands and TikZ commands. In this example the first cube uses the \verb!\RubikCubeSolved! \textit{inside} the TikZ environment. However, if we then perform the rotation \textRubik{R}\ the command \verb!RubikRotation{R}! results in something quite unexpected (and obviously not correct). This is because the effect of the \verb!\RubikCubeSolved! command is not visible outside its TikZ environment, and hence the \verb!RubikRotation{R}! command has to operate on the current globally available colour state information; i.e.,~that following the action of the \textbackslash\texttt{RubikRotation\{[sixspot],....\}} command in the earlier Example~2 (shown in Figure~2) which was executed \textit{before, and outside} the \texttt{figure} environment in that example, and hence the strange form of the second cube below. \medskip \begin{minipage}{0.4\textwidth} \ShowCube{2cm}{0.5}{% \RubikCubeSolved \DrawRubikCubeRU } \hspace{4mm}\Rubik{R}\hspace{5mm}% \RubikRotation{R}% \ShowCube{2cm}{0.5}{\DrawRubikCubeRU} \end{minipage} %--------------- \hspace{1cm} \begin{minipage}{0.5\textwidth} \begin{verbatim} \usepackage{tikz,rubikcube,rubikrotation} ... \begin{minipage}{0.4\textwidth} \ShowCube{2cm}{0.5}{% \RubikCubeSolved \DrawRubikCubeRU } \hspace{4mm}\Rubik{R}\hspace{5mm}% \RubikRotation{R}% \ShowCube{2cm}{0.5}{\DrawRubikCubeRU} \end{minipage} \end{verbatim} \end{minipage} \bigskip If we now bring the \verb!\RubikCubeSolved! command out and place it before the \verb!\ShowCube! command then its `state' information becomes globally accessable, and can therefore be acted upon (\&~updated) by the \verb!\RubikRotation{R}! command, and hence is rendered (correctly for us) by the next \verb!\DrawRubikCubeRU! command. \bigskip \begin{minipage}{0.4\textwidth} \RubikCubeSolved \ShowCube{2cm}{0.5}{\DrawRubikCubeRU} \hspace{4mm}\Rubik{R}\hspace{5mm}% \RubikRotation{R}% \ShowCube{2cm}{0.5}{\DrawRubikCubeRU} \end{minipage} %--------------- \hspace{1cm} \begin{minipage}{0.5\textwidth} \begin{verbatim} \begin{minipage}{0.4\textwidth} \RubikCubeSolved \ShowCube{2cm}{0.5}{\DrawRubikCubeRU} \hspace{4mm}\Rubik{R}\hspace{5mm}% \RubikRotation{R}% \ShowCube{2cm}{0.5}{\DrawRubikCubeRU} \end{minipage} \end{verbatim} \end{minipage} \pagebreak %---------------------- \section*{Example~7} \subsection*{The `superflip' configuration} Once you have mastered Rubik's cube, then an interesting exercise is to generate the so-called `superflip' configuration, in which all the corners are correctly solved, while all the edges are flipped. For the impatient, the superflip sequence of 24 quarter-turn rotations (listed on Randelshofer's website (\url{www.randelshofer.ch/rubik/patterns/U080.01.html}) is as follows. This converts the solved cube on the left into the configuration shown on the right. \bigskip \begin{center} \Rubik{U}\Rubik{R}\Rubik{R}\Rubik{Fp}\Rubik{R}\Rubik{Dp}\Rubik{L}\Rubik{Bp}\Rubik{R}% \Rubik{Up}\Rubik{R}\Rubik{Up}\Rubik{D}\Rubik{Fp}\Rubik{U}\Rubik{Fp}\Rubik{Up}\Rubik{Dp}% \Rubik{B}\Rubik{Lp}\Rubik{Fp}\Rubik{Bp}\Rubik{Dp}\Rubik{Lp} \end{center} \medskip {\noindent}Surprisingly, this sequence is actually equivalent to \Rubikbrace{\Rubikbracket{\Rubik{M}\Rubik{Up}}4, \Rubik{yp}, \Rubik{x}}3 %--------draw the images------------- \begin{figure}[hbt] \centering \RubikCubeSolved% \ShowCube{2cm}{0.5}{\DrawRubikCubeRU} \hspace{5mm}$\Longrightarrow$\hspace{5mm}% \RubikRotation{\superflip}% \ShowCube{2cm}{0.5}{\DrawRubikCubeRU} \hspace{1cm}% \ShowCube{5cm}{0.5}{\DrawRubikCubeFlat} \caption{Two representations of the superflip configuration.} \end{figure} %---------------------- %\pagebreak {\noindent}The full code for the figure above is as follows: \begin{quote} \begin{verbatim} \usepackage{tikz,rubikcube,rubikrotation} ... \begin{center} \Rubik{U}\Rubik{R}\Rubik{R}\Rubik{Fp}\Rubik{R}\Rubik{Dp}\Rubik{L}\Rubik{Bp}% \Rubik{R}\Rubik{Up}\Rubik{R}\Rubik{Up}\Rubik{D}\Rubik{Fp}\Rubik{U}\Rubik{Fp}% \Rubik{Up}\Rubik{Dp}\Rubik{B}\Rubik{Lp}\Rubik{Fp}\Rubik{Bp}\Rubik{Dp}\Rubik{Lp} \end{center} \medskip %% brace and bracket macros \newcommand{\Rubikbracket}[1]{$\left(\mbox{#1}\right)$} \newcommand{\Rubikbrace}[1]{$\left\{\mbox{#1}\right\}$} {\noindent}Surprisingly, this sequence is actually equivalent to \Rubikbrace{\Rubikbracket{\Rubik{M}\Rubik{Up}}4, \Rubik{yp}, \Rubik{x}}3 \newcommand{\superflip}{U,R2,Fp,R,Dp,L,Bp,R,Up,R,Up,D,% Fp,U,Fp,Up,Dp,B,Lp,Fp,Bp,Dp,Lp} \begin{figure}[hbt] \centering \RubikCubeSolved% \ShowCube{2cm}{0.5}{\DrawRubikCubeRU} \hspace{5mm}$\Longrightarrow$\hspace{5mm}% \RubikRotation{\superflip}% \ShowCube{2cm}{0.5}{\DrawRubikCubeRU} \hspace{1cm}% \ShowCube{5cm}{0.5}{\DrawRubikCubeFlat} \caption{...} \end{figure} \end{verbatim} \end{quote} \begin{center} ------ END ------ \end{center} \end{document}