# Results

1. Gonzalo Medina – 31
2. Andy – 19
3. cmhughes – 11
4. mbork – 6

## Other

1. Yiannis Lazarides – 38
2. szantaii – 20
3. Ant – 15
4. Paulo Cereda – 14
5. Count Zero – 13
7. Andrew Stacey – 9
8. Max Lambertini – 7

The votes were counted at the end of the one week voting period, Nov. 25, 2011 14:00 UTC.

Congratulations to Gonzalo and Yiannis! And a big thank you to the twelve submitters, the high number of votes and views shows that the community took great interest in your work. As for the prizes, I think we're still waiting to hear back from Stack Exchange, so you'll have to be patient, sorry :(.

And here's the contest post itself:

# What's going on?

TeX.sx turned one on November 11, 2011. This contest is part of our celebrations. This question doesn't meet the normal question form requirements on this site, but it is considered an exception, and was approved of on meta.

Show off the knowledge in TeX & friends that you've gathered over the time. Include things that a more-or-less everyday document can benefit from.

Final number of submissions: 12

# Any conditions my document has to fulfill?

• ## Form

• All common formats (LaTeX, Plain TeX, ConTeXt) and engines (pdfTeX, XeTeX, LuaTeX) are allowed. However, the "ingredients" are limited to things provided on CTAN or otherwise easily publicly and freely available, so that everybody can reproduce and compile the document.
• The source must be included and you agree that other users can reuse your code.
• Annotate your source extensively, so that non-expert users can understand which package and which hack does what.
• ## Contents

• Your document should mainly be text, but content doesn't matter -- feel free to show the most beautiful lorem ipsum ever. Reuse of something you have already written earlier is fine as well.
• Academic paper-like submissions are as welcome as cooking recipes, role-playing game sheets, CVs or anything text-based that can be produced with TeX & friends. [see "Update"]
• Include whatever visual stimuli you can think of, e.g. figures, tables, margin notes, background pictures, drop caps / initials — but in the end, it has to look good, not cluttered.
• Make it typographically, aesthetically and perhaps even funwise maximally appealing.

# How do I participate?

• Post your submission, in an answer to this question and delete it immediately — in consequence, it won't be publicly visible, but the site moderators can restore it later.

• When you add a new answer, please edit the question to update the current number of submissions.

• Include 1) screenshots of your output, 2) the full compilable code, and 3) links to any additional material that needs to be downloaded. Specify if a particular compiler or compiling sequence is required. This question will be locked on Nov. 18, 14:00h UTC, so that no more answers can be added. Then all answers will be undeleted and voting starts.

# Prizes?

Yes, there will most likely be prizes, but it hasn't been decided yet which in particular, see Which prizes for contests?. Besides that, chances are you enjoy TeX & friends at any rate, there are the usual answer badges to win (no reputation though), and the community can benefit from contributions enormously!

# Who determines the winner; who votes?

## You do!

Once the submissions are visible, you can vote for all submissions that you want to support. Thus, each TeX.sx user has as many votes as there are submissions, but each submission can only get one vote from each user. Downvoting is possible but, but strongly discouraged. If you feel you have to downvote, please explain why in a comment (e.g. if a document is in HTML instead of TeX or one of its friends). You can determine what you consider a good contribution, things to consider are:

• Are above conditions met?
• Is the submissions useful for other users of TeX & friends?
• Is the source comprehensibly annotated?
• Do you enjoy the submission?

Voting ends after a week, I'll try to note down the vote counts Nov. 25 around 14h UTC, these will determine the winner, regardless of votes cast afterwards.

### A note to high rep users

You might be able to see the temporarily deleted submissions. You've proven trustworthy to the community in the past, so just pretend you couldn't see them.

Please lock the question on Nov. 18, 14:00h UTC and undelete the answers. Rollback any edits to the contributions after this deadline.

Any help in overseeing this contest is highly appreciated.

Update (per meta)

1. There is a limit of three submissions per user.
2. There are two categories: academic and other. Please indicate to which one your submission belongs. The result of the voting will be split into these categories.

None of this is in any way legally binding. TeX.sx and I reserve the right to change all conditions of this contest at any point as it seems reasonable to us. (We don't plan to, though.)

-
Shouldn't it be "TeX" skills without the "La" part? –  Khaled Hosny Nov 11 '11 at 16:56
@KhaledHosny: Have a look at the discussion page I linked to in the comment above yours. –  doncherry Nov 11 '11 at 17:23

I'd like to add a humble contribution to the contest. But beware, don't expect too much. After all, it's me. :)

Before the code is properly unveiled, I'd like to provide some background, so everybody will understand why I came up with it. There we go.

# Background

I'm the coordinator of a small choir in a parish. I decided to come up with a personal songbook to help me on keeping track of songs we use during masses or processions. But it is not an easy task.

First of all, I decided to use the songs package. IMHO it's a nice package for handling songbooks and it really suits my purposes. As a bonus, it can handle chords beautifully. But unfortunately, the whole process of cataloging songs required much more than a good layout.

Catholic liturgy teaches us that music is an important part of the mass. So I had to have every rite or gesture mapped to the correct song, e.g, entrance song, Kyrie, Gloria, Alleluia, Presentation of the Gifts, and so forth.

So I wrote down how many categories I had to map to my songs. I came up with 22 categories. So far so good.

But it was not that simple. I had to map songs according to their categories and also taking the time of the liturgical year into consideration, e.g, Advent, Christmas, Ordinary Time, Lent and Easter. So I had to cross map all categories along the year. Besides, I also had to take into consideration the calendar of saints, feasts and the sacraments. Oh my!

How should I do such project using LaTeX? We will see how I did it.

# Implementation

First of all, the songs package is a prerequisite. I decided to use it and I'm quite satisfied with the result. I must warn you that the CTAN version is very outdated, so please download the updated one from here.

I had 22 categories, so I decided to convert them to 22 indices. I usually search songs by their category, so it was a natural choice. imakeidx is the way to go, very easy to use and powerful. Ah, I decide to use another one for a thematic index, so saints, feasts and sacraments were correctly mapped.

I won't write my real code, as it is more a monstruous example than a minimal one. :) But you will probably get the idea. Lets check it:

% the document class, no big deal
\documentclass[a4paper,oneside,11pt]{book}

% the usual packages
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}

% index features
\usepackage{imakeidx}


No secret here. Now let's then create, say, four categories:

% four indices will be created, each
% one representing a category
\makeindex[name=foo,title=Index of Foo]
\makeindex[name=bar,title=Index of Bar]
\makeindex[name=foobar,title=Index of Foobar]
\makeindex[name=qux,title=Index of Qux]


Please, don't expect the 23 categories I have! :) Ah, in my real document, I use the splitindex option for imakeidx, otherwise we will run out of registers. Let's move on:

% my favorite layout lifesaver
\usepackage{idxlayout}

% drawing stuff
\usepackage{tikz}

% swiss army knife
\usepackage{etoolbox}

% for string comparison
\usepackage{xstring}


In every song, I want to display the categories, so I wrote the following code to display an acronym to represent every category:

% this command will draw a circle
% with #1 text inside it
\newcommand*\drawtype[1]{%
\begin{tikzpicture}
\node[draw,circle,inner sep=1pt, minimum height=0.5cm, minimum width=0.5cm] {\scriptsize #1};
\end{tikzpicture}%
}


The songs package, of course:

% songs
\usepackage[lyric]{songs}


Remember the divisions of the liturgical year? I decided to use the following plan: Imagine five bullets in front of a song name. The order for the times of the liturgical year is well-defined, so each bullet represents one time. If, say, the first bullet is filled (\bullet), the song might be used in this time, otherwise an empty bullet (\circ) will be used. Let's say we have four times, A, B, C and D:

% print the bullets according to the
% #1 input
\DeclareRobustCommand*\drawbullets[1]{%
{\footnotesize%
\IfSubStr{#1}{A}{$\bullet$}{$\circ$}%
\IfSubStr{#1}{B}{$\bullet$}{$\circ$}%
\IfSubStr{#1}{C}{$\bullet$}{$\circ$}%
\IfSubStr{#1}{D}{$\bullet$}{$\circ$}}~%
}


And I want to have the liturgical time being displayed in the song, so I wrote another code for it:

% draw a little square with #1 text
% inside it
\newcommand*\timebox[1]{%
\begin{tikzpicture}
\node[draw,inner sep=1pt, minimum height=0.3cm, minimum width=0.3cm] {\tt\raisebox{0pt}[\height][0pt]{#1}};
\end{tikzpicture}%
}

% print a timebox and add a space
\newcommand*\indextime[1]{%
\timebox{#1}~%
}


I love this part. Thanks to the etoolbox package, I can iterate through elements of a list, so I add a new list parser:

% declare a new list parser
\DeclareListParser*{\myforeach}{,}


Now I create a command to iterate through a list of times:

% create a command that will print a
% timebox for every letter found
\newcommand*\settime[1]{%
\myforeach{\indextime}{#1}%
}


This part is the heart of my implementation. I read the category of the current song and index it accordingly:

% index song according to the
% category
\newcommand*\indexsong[1]{%
\IfEq{#1}{F}{%
\resettitles%
\index[foo]{\songtitle@\songliturgy \songtitle}
\drawtype{F}~%
}{%
\IfEq{#1}{B}{%
\resettitles%
\index[bar]{\songtitle@\songliturgy \songtitle}
\drawtype{B}~%
}{%
\IfEq{#1}{FB}{%
\resettitles%
\index[foobar]{\songtitle@\songliturgy \songtitle}
\drawtype{FB}~%
}{%
\IfEq{#1}{Q}{%
\resettitles%
\index[qux]{\songtitle@\songliturgy \songtitle}
\drawtype{Q}~%
}{%
\textbf{Error!}%
}%
}%
}%
}%
}%


Again, for every category of every song, let's index it:

% create a command to index the current song
% according to the list of categories
\newcommand*\classify[1]{%
\myforeach{\indexsong}{#1}%
}


Now, I need to add support to these entries in my song environment:

% create a new song key to print the categories
\newsongkey{cla}{\def\songclassify{}}
{\def\songclassify{ #1 \par}}

% create a new song key to print the time
\newsongkey{tin}{\def\songliturgy{}}
{\def\songliturgy{#1}}

% Renew the song prelude to print
% the categories
\renewcommand{\extendprelude}{%
\showrefs{\footnotesize\showauthors}%
{\ttfamily\songclassify}%
}


Now I create both author and song indices required by the songs package and set the chorus font to be bold:

% create both song and author indices
\newindex{reltitleidx}{cbreltitle}
\newauthorindex{relauthidx}{cbrelauth}

% bold chorus font
\renewcommand{\chorusfont}{\bfseries}


Thanks to egreg, the following code will add the song number instead of the page number to my indices entries:

% add the song number instead of
% page number
\makeatletter
\patchcmd{\@wrindex}{\thepage}{\thesongnum}{}{}%
\makeatother


Now it's simple enough. The document begins and the songs are added:

\begin{document}

\showindex{My songs}{reltitleidx}

\begin{songs}{reltitleidx,relauthidx}

\beginsong{My cool song}[by={Some guy},sr={},cla={\classify{F,B}},cr={\settime{A,C}},tin={\drawbullets{A,C}}]

\beginchorus
This is a cool song, I wrote it by myself! \rep{2}
\endchorus

\beginverse
Meow, said the cat! Of course you will love this song!
\endverse

\endsong

\beginsong{Another cool song}[by={Some guy},sr={},cla={\classify{B}},cr={\settime{A}},tin={\drawbullets{A}}]

\beginchorus
This is a cool song, I wrote it by myself! \rep{2}
\endchorus

\beginverse
Meow, said the cat! Of course you will love this song!
\endverse

\endsong

\beginsong{Cool cool cool}[by={Some guy},sr={},cla={\classify{FB}},cr={\settime{D}},tin={\drawbullets{D}}]

\beginchorus
This is a cool song, I wrote it by myself! \rep{2}
\endchorus

\beginverse
Meow, said the cat! Of course you will love this song!
\endverse

\endsong

\beginsong{Cooler song}[by={Some guy},sr={},cla={\classify{Q}},cr={\settime{A,D}},tin={\drawbullets{A,D}}]

\beginchorus
This is a cool song, I wrote it by myself! \rep{2}
\endchorus

\beginverse
Meow, said the cat! Of course you will love this song!
\endverse

\endsong

\beginsong{Cool yeah}[by={Some guy},sr={},cla={\classify{F,FB}},cr={\settime{B,C}},tin={\drawbullets{B,C}}]

\beginchorus
This is a cool song, I wrote it by myself! \rep{2}
\endchorus

\beginverse
Meow, said the cat! Of course you will love this song!
\endverse

\endsong

\beginsong{Coolness}[by={Some guy},sr={},cla={\classify{B,Q}},cr={\settime{C}},tin={\drawbullets{C}}]

\beginchorus
This is a cool song, I wrote it by myself! \rep{2}
\endchorus

\beginverse
Meow, said the cat! Of course you will love this song!
\endverse

\endsong

\beginsong{Hallelujah cool!}[by={Some guy},sr={},cla={\classify{F,Q}},cr={\settime{B}},tin={\drawbullets{B}}]

\beginchorus
This is a cool song, I wrote it by myself! \rep{2}
\endchorus

\beginverse
Meow, said the cat! Of course you will love this song!
\endverse

\endsong

\beginsong{Coolest song!}[by={Some guy},sr={},cla={\classify{F}},cr={\settime{A,B}},tin={\drawbullets{A,B}}]

\beginchorus
This is a cool song, I wrote it by myself! \rep{2}
\endchorus

\beginverse
Meow, said the cat! Of course you will love this song!
\endverse

\endsong

\end{songs}

\printindex[foo]
\printindex[bar]
\printindex[foobar]
\printindex[qux]

\end{document}


The output is as we expect:

And the indices are correct:

I can now easily find the songs I want! By the way, my original songbook has now 2000+ songs, powered by LaTeX. :)

That's it, hope you guys like it! Happy birthday, TeX.sx! :)

-

Academic submission: This document is part of a project I am working on for my students- it consists of problems, examples, and solutions (at the end). The final document will be many more than 4 pages, but this part gives a flavour :)

First of all, to help you decide if you want to read the rest of my answer :), here are screen shots of my 4 pages

Some of the packages that are important for my document:

• answers to typeset solutions to problems, which are included separately at the end
• hyperref to link between the problems and solutions
• pstricks to typeset the graphs
• xstring to help determine if the problems are even or odd numbered
• cleveref to get clever references

Some features that I have designed:

• There are two booleans, showoddsolns and showevensolns which can be set as true or false. Naturally, these toggle if the odd or even solutions are shown or not
• Both the problem and subproblem environments can take an optional argument [special] which will label it with a *. Furthermore, these 'special' problems can be listed using \listspecialproblems; this works on a per-section basis
• If you click on the problem numbers, you will be hyperlinked to the solution; if you click on the solution number, you will be hyperlinked back to the problem
• I have used a newpsobject to help make global changes to my graphs

Note that because I have used pstricks the code should be compiled with

pdflatex -shell-escape myfile.tex


or else through the latex-> dvips-> ps2pdf routine.

I've pasted the code on pastebin, which perhaps makes it more accessable

The code for the mainfile.tex is also below.

\documentclass[10pt,twoside]{report}
\usepackage{etex}
\reserveinserts{28}
\usepackage[left=6cm,right=1cm,showframe=false,                 % page settings (showframe is useful!)
textheight=27cm,
top=1.5cm,bottom=1.5cm,asymmetric=true,bindingoffset=1cm]{geometry}
\usepackage{amsmath}                            % mathematical content
\usepackage{amssymb}                            % mathematical content
\usepackage[amsmath,standard,framed,thmmarks]{ntheorem} % custom enumerations *Needs to stay here, otherwise cross references can go wrong*
\usepackage{ifthen}                             % conditionals
\usepackage{xcolor}                             % colour
\usepackage{answers}                            % solutions to problems done *beautifully*
\usepackage{framed}                             % needed for putting boxes round theorems, examples
\usepackage[explicit]{titlesec}
\usepackage{multicol}                           % multicols
\usepackage{changepage}                         % needed for hanging paragraphs
\usepackage{calc}                               % calculations (such as \textwidth/2)
\usepackage[small,bf]{caption}                  % figures/tables in margins, and not floating
\usepackage{subcaption}                         % subfigures, subtables (replaces subfig)
\usepackage{xstring}                            % needed to determine if problems are odd or even
\usepackage{enumitem}                           % enumerate & itemize
\usepackage{placeins}                           % FloatBarrier
\usepackage{marginfix}                          % fixes margin notes (otherwise they can cut through pages)
\usepackage{needspace}                          % needed to keep problems looking good (stops ugly pagebreaks)
\usepackage{xargs}                              % helps with optional arguments for environments
\usepackage{booktabs}       % used with tables (allows \toprulewidth etc)
\usepackage{flafter}          % ensures that floats don't appear until after their placement in the text
% pstricks
\usepackage[pdf]{pstricks}
\usepackage{hyperref}           % to allow hyper refs in the final pdf document

% hyperref NEEDS TO STAY AT THE END!
\usepackage[all]{hypcap}        % needed to help hyperlinks direct correctly;
% note that this needs to be loaded AFTER
% the hyperref package; the option [all]
% makes hyperlinks to figures & tables go
% to the top
\usepackage{cleveref}       % needs to be loaded after hyperref

% hyperref settings- it seemed to work better here rather than
% as options to the \usepackage call above
}

\psset{algebraic=true}           % set up options for PS figures

% custom ps options
\newpsobject{pccpsplot}{psplot}{linecolor=blue,plotstyle=curve,%
linewidth=1pt,arrows=<->}
\newpsobject{pccgridline}{psline}{linecolor=black!20,linestyle=dashed}
\newpsobject{pccpsframe}{psframe}{linecolor=gray,linewidth=0pt}
\newpsobject{pccpsSolDot}{psdots}{linecolor=blue,dotsize=0.25}
\newpsobject{pccpsHolDot}{psdots}{linecolor=blue,dotsize=0.25,dotstyle=o}
\newpsobject{pccasymptote}{psline}{linestyle=dotted,linecolor=red}

% grid stuff
\newcommand{\drawXgrid}[3]{%
\multido{\nx=#1+#2}{#3}%
{%
\pccgridline(\nx,\ymin)(\nx,\ymax)
}%
}
\newcommand{\drawYgrid}[3]{%
\multido{\ny=#1+#2}{#3}%
{%
\pccgridline(\xmin,\ny)(\xmax,\ny)
}%
}

% set figure width

\newlength{\figurewidth}
% setwindow command: takes 6 arguments (1st is optional)
%       [1]. aspect ratio (height = aspect ratio * width) default=1
%         2. xmin (number)
%         3. ymin (number)
%         4. xmax (number)
%         5. ymax (number)
%         6. figurewidth (length)
\makeatletter
\newcommand{\setwindow}[6][5]{\def\xmin{#2}%
\def\ymin{#3}%
\def\xmax{#4}%
\def\ymax{#5}%
% set up xunit
\pstFPsub\viewingwidth{#4}{#2}%
\pstFPdiv\result{\strip@pt#6}{\viewingwidth}%
\psset{xunit=\result pt}
% set up yunit
\pstFPsub\viewingheight{#5}{#3}%
\pstFPdiv\result{\strip@pt#6}{\viewingheight}%
% set up aspect ratio
\pstFPmul\result{\result}{#1}%
\psset{yunit=\result pt}%
}
\makeatother

% caption settings
\captionsetup[table]{skip=0pt}
\captionsetup[subfigure]{labelformat=parens,labelsep=colon,labelfont=normal}
\captionsetup[subtable]{labelformat=parens,labelsep=colon,labelfont=normal}

% enumerate settings
\setlist{itemsep=0.05em,topsep=0.01em}

% paragraph settings
\setlength{\parskip}{3.0mm}
\setlength{\parindent}{0.0mm}

% use left margin
\reversemarginpar
\setlength{\marginparwidth}{5cm}

% Define fix command
%   - it puts a comment in the margin
%   - it writes to a file with a list of things that need fixing
\newcommand{\fixthis}[1]%
{%
\marginpar{\huge \color{red} \framebox{FIX}}%
\typeout{FIXTHIS: p\thepage : #1^^J}%
}

%   BEGIN CLEVEREF

% standard environments
\crefname{table}{Table}{Tables}
\Crefname{table}{Table}{Tables}
\crefname{figure}{Figure}{Figures}
\Crefname{figure}{Figure}{Figures}
\crefname{section}{Section}{Sections}
\Crefname{section}{Section}{Sections}
\crefname{equation}{Equation}{Equations}
\Crefname{equation}{Equation}{Equations}
% custom environments
\crefname{problem}{Problem}{Problems}
\Crefname{problem}{Problem}{Problems}
\crefname{pccdefinition}{Definition}{Definitions}
\Crefname{pccdefinition}{Definition}{Definitions}
\crefname{pccexample}{Example}{Examples}
\Crefname{pccexample}{Example}{Examples}
\crefname{enumi}{Problem}{Problems}
\Crefname{enumi}{Problem}{Problems}
% conjunction between range; e.g Figures 1.2-1.3
\newcommand{\crefrangeconjunction}{|}

%   BEGIN MARGIN ENVIRONMENTS (shamelessly copied from tufte documentclass)
\makeatletter
% Margin float environment
\newsavebox{\@tufte@margin@floatbox}
\newenvironment{@tufte@margin@float}[2][-1.2ex]%
{\FloatBarrier% process all floats before this point so the figure/table numbers stay in order.
\begin{lrbox}{\@tufte@margin@floatbox}%
\begin{minipage}{\marginparwidth}%
\def\@captype{#2}%
\hbox{}\vspace*{#1}%
\noindent%
}
{\end{minipage}%
\end{lrbox}%
\marginpar{\usebox{\@tufte@margin@floatbox}}%
}

% Margin figure environment
\newenvironment{marginfigure}[1][-1.2ex]%
{\begin{@tufte@margin@float}[#1]{figure}%
\capstart\endgraf}% <-- Hyperlink jumps to start of 'marginfigure'
{\end{@tufte@margin@float}}

% Margin table environment
\newenvironment{margintable}[1][-1.2ex]%
{\begin{@tufte@margin@float}[#1]{table}%
\capstart\endgraf}% <-- Hyperlink jumps to start of 'margintable'
{\end{@tufte@margin@float}}

\makeatother
%   END MARGIN ENVIRONMENTS

%   BEGIN SOLUTIONS TO PROBLEMS
% open the answer files (short, long, and hints)
\Opensolutionfile{shortsolutions}
\Newassociation{shortsolution}{shortSoln}{shortsolutions}

% put titles in the solution files
\begin{Filesave}{shortsolutions}
% SHORT SOLUTIONS FILE
% Begin by (re-)setting the chapter counter to 0
% which is used for hyperlinks from solutions to questions
%
% This allows us to put Problem 1, 2, 3, etc in every chapter
% as the hyperlinks have the form \hypertarget{soln:#1\thechapter}{}
\setcounter{chapter}{0}

\end{Filesave}
%   END SOLUTIONS TO PROBLEMS

%   BEGIN CUSTOM THEOREMS (for problems, subproblems)
% set up showoddsolns and showEVEN
\newboolean{showoddsolns}
\setboolean{showoddsolns}{true}
\newboolean{showevensolns}
\setboolean{showevensolns}{true}

% this boolean is used in the problem and subproblem definition (don't change!)
\newboolean{showSolution}
\setboolean{showSolution}{true}

% PROBLEM environment
% \begin{problem}[1][6]
%   ...
% \end{problem}
%
%  [1]: description of the problem
%  [2]: special
%
% Both arguments are optional; the second argument
% can be left off, empty, or special. If it is non-empty
% and anything other than special (case-sensitive), it
% will be ignored.
\newcounter{problem}
\newcommand{\specialsymbol}{$\bigstar$ }
\newlength{\specialsymbollength}
\settowidth{\specialsymbollength}{\specialsymbol}
\newenvironmentx{problem}[2][1={},2={},usedefault]{%
\refstepcounter{problem}%
\Writetofile{shortsolutions}{\protect\hypertarget{soln:\theproblem:\thechapter}{}}%
\needspace{\baselineskip}%
\ifthenelse{\isodd{\theproblem}}%
{%
\ifthenelse{\boolean{showoddsolns}}%
{}% true (by default)
{\setboolean{showSolution}{false}}%
}%
{%
\ifthenelse{\boolean{showevensolns}}%
{}% true (by default)
{\setboolean{showSolution}{false}}%
}%
\ifthenelse{\equal{#2}{}}%
{%  NOT special problem
% if no second argument (special or not)
\ifthenelse{\equal{#1}{}}%
{% Problem withOUT description
\ifthenelse{\boolean{showSolution}}%
{%
{\hypertarget{prob:\theproblem:\thechapter}{}%
}%
{%
{\bfseries Problem \theproblem}\newline%
}%
}%
{% Problem with description
\ifthenelse{\boolean{showSolution}}%
{%
{\hypertarget{prob:\theproblem:\thechapter}{}%
}%
{%
{\bfseries Problem \theproblem\, (#1) }\newline%
}%
}%
}%
{%  special problem
\ifthenelse{\equal{#2}{special}}%
{%
% write problem number to specialfile
\ifthenelse{\equal{#1}{}}%
{%  special problem with no description
\ifthenelse{\boolean{showSolution}}%
{%
{\hypertarget{prob:\theproblem:\thechapter}{}%
}%
{%
\hspace{-\specialsymbollength}\specialsymbol{\bfseries Problem \theproblem}\newline%
}%
}%
{% special problem with description
\ifthenelse{\boolean{showSolution}}%
{\hypertarget{prob:\theproblem:\thechapter}{}%
}%
\hspace{-\specialsymbollength}\specialsymbol{\bfseries Problem \theproblem\, (#1) }\newline%
}%
}%
}{ \textbf{Problem} \theproblem \, (#1) {\bf\huge\color{red}special?}\par}%
}%
}%
{%
}%

% subproblem environment
\newcounter{subproblem}[problem]
\newboolean{specialproblemYesNo}
\setboolean{specialproblemYesNo}{false}
\newenvironment{subproblem}[1][]{%
\refstepcounter{subproblem}%
\ifthenelse{\isodd{\theproblem}}%
{%
\ifthenelse{\boolean{showoddsolns}}%
{}% true (by default)
{\setboolean{showSolution}{false}}%
}%
{%
\ifthenelse{\boolean{showevensolns}}%
{}% true (by default)
{\setboolean{showSolution}{false}}%
}%
\ifthenelse{\equal{#1}{special}}%
{%
\setboolean{specialproblemYesNo}{true}%
}%
{%
\setboolean{specialproblemYesNo}{false}%
}%
\ifthenelse{\boolean{specialproblemYesNo}}%
{% special problem
\ifthenelse{\boolean{showSolution}}%
\hypertarget{prob:{\theproblem.\thesubproblem}:\thechapter}{}%
\begin{enumerate}[label=\llap{$\bigstar$ }\bfseries\protect\hyperlink{soln:{\theproblem.\thesubproblem}:\thechapter}{\theproblem.\thesubproblem},ref=\theproblem.\thesubproblem,leftmargin=*]
\item%
}%
\begin{enumerate}[label=\llap{$\bigstar$ }\bfseries\theproblem.\thesubproblem,ref=\theproblem.\thesubproblem,leftmargin=*]
\item%
}%
}%
{% NOT special problem
\ifthenelse{\boolean{showSolution}}%
\hypertarget{prob:{\theproblem.\thesubproblem}:\thechapter}{}%
\item%
}%
\begin{enumerate}[label=\bfseries\theproblem.\thesubproblem,ref=\theproblem.\thesubproblem,leftmargin=*]
\item%
}%
}%
}{\end{enumerate}}

% definition
\theoremstyle{break}
\theoremsymbol{}
\theoremseparator{}
\theoremprework{\FloatBarrier}
\def\theoremframecommand{%
%   END CUSTOM THEOREMS (for examples, problems)

%   BEGIN special PROBLEMS
\newcounter{probSectCounter}
\setcounter{probSectCounter}{-1}
\newcounter{probCounter}
\setcounter{probCounter}{0}%
\newcounter{echo}

% redefine the \section command to increment probSectCounter
% note that this could also be done for \subsection if desired
\let\oldsection\section
\renewcommand\section{%
\stepcounter{probSectCounter}%
\oldsection}

\makeatletter

% need a command to bring the \contentsline
% into the problemlist environment
\let\pcc@contentslist\contentsline%
\newenvironment{problemlist}%
{%
% renew the \contentsline command so that it just gives
% the problem number as a hyperlink (and no page number)
%
% if we renewed the command outside of the environment, it would
% affect \tableofcontents, \minitoc, and perhaps more- bad!
\let\contentsline\pcc@contentslist%
\let\Contentsline\contentsline%
\renewcommand\contentsline[4]{%
{%
{%
\setcounter{echo}{1}%
\setcounter{probCounter}{0}%
}%
{%
\setcounter{echo}{0}%
}%
}%
{%
\ifthenelse{\equal{\theecho}{1}}%
{%
\stepcounter{probCounter}%
\ifthenelse{\equal{\theprobCounter}{1}}%
{%
% if we're at the beginning, no comma
Special problems in this section (\specialsymbol\unskip): \Contentsline{##1}{##2}{}{##4}%
}%
{%
% otherwise put a comma and a space
\unskip, \Contentsline{##1}{##2}{}{##4}%
}%
}%
{}%
}%
}%
}%
{}

\def\listspecialproblems{%
% open the appropriate file do everything in a
% new environment so that we can renew the
% \contentsline command locally
\begin{problemlist}
\par%
\openin\File=\jobname.prb%
\loop\unless\ifeof\File%
\fileline%
\repeat%
\closein\File%
\end{problemlist}
}%

% enable the \jobname.prb file
% (hacked from the ntheorem package)
\def\prb@enablelistofproblems{%
\begingroup%
\makeatletter%
\if@filesw%
\expandafter\newwrite\csname tf@prb\endcsname%
\immediate\openout \csname tf@prb\endcsname \jobname.prb\relax%
\fi%
\@nobreakfalse%
\endgroup}%

% enable the \jobname.prb<counter> files at the end
% of the document
\AtEndDocument{\prb@enablelistofproblems}

\makeatother

%   END special PROBLEMS

%   BEGIN TABLE STYLES
\renewcommand{\heavyrulewidth}{0.2em}
\renewcommand{\lightrulewidth}{0.1em}
\renewcommand{\cmidrulewidth}{0.1em}
% horizontal lines
\renewcommand{\aboverulesep}{0cm}
\renewcommand{\belowrulesep}{0cm}
%\newcommand*\normalline{\hline}
\newcommand*\normalline{}
\newcommand*\lastline{\bottomrule}
%   END TABLE STYLES

%   BEGIN CUSTOMIZE SECTIONS
% custom chapter
\titleformat{\chapter}[display]
{\normalfont\Large\filcenter\bf}
{\titlerule[1pt]%
\vspace{1pt}%
\titlerule
{1pc}
{\titlerule
\Huge}

% write to the solutions files to step the chapter counter
\let\oldchapter\chapter
\renewcommand{\chapter}{\Writetofile{shortsolutions}{\protect\stepcounter{chapter}}%
\oldchapter}

% From the titlesec package
% \titlespacing{command}{left spacing}{before spacing}{after spacing}[right]
% spacing: how to read {12pt plus 4pt minus 2pt}
%           12pt is what we would like the spacing to be
%           plus 4pt means that TeX can stretch it by at most 4pt
%           minus 2pt means that TeX can shrink it by at most 2pt
%       This is one example of the concept of, 'glue', in TeX

\titlespacing{\chapter}{0pt}{*4}{-0.1cm}
\titlespacing\section{0pt}{12pt plus 4pt minus 2pt}{-5pt plus 2pt minus 2pt}
\titlespacing\subsection{0pt}{12pt plus 4pt minus 2pt}{-6pt plus 2pt minus 2pt}
\titlespacing\subsubsection{0pt}{12pt plus 4pt minus 2pt}{-6pt plus 2pt minus 2pt}

%   END CUSTOMIZE SECTIONS

%====================================
%   BEGIN DOCUMENT
%====================================
\begin{document}

\renewcommand{\labelenumi}{(\alph{enumi})}

% needed for the mini-tableofcontents
\dominitoc
\faketableofcontents

\fancyhf{} % delete current header and footer

\pagestyle{fancy}
\include{polynomialfunctions}

%=======================
%   BEGIN SOLUTIONS
%=======================

% change to one-sided mode
% change the pagestyle to plain
% change the page geometry using \newgeometry
\setboolean{@twoside}{false}
\pagestyle{plain}
\newgeometry{left=1cm,right=1cm,showframe=true,
textheight=27cm,
top=1.5cm,bottom=1.5cm,bindingoffset=1cm}

% close the solutions files
\Closesolutionfile{shortsolutions}

% SHORT solution to problem (show only odd, even, all)
% Note: this renewenvironment needs to go here
%       so that the answers package can still
%       display correctly to the page if needed
\newboolean{oddproblemnumber}
\renewenvironment{shortSoln}[1]{%
\exploregroups % needed to ignore {}
% before the environment starts - this is a stretchable space
\vskip 0.1cm plus 2cm minus 0.1cm%
\fullexpandarg % need this line so that '.' are counted
%
% either problems, or subproblems, e.g: 3.1 or 3.1.4 respectively
% determine which one by counting the '.'
\StrCount{#1}{.}[\numberofdecimals]
%
% find the problem number by splitting the string
\ifthenelse{\numberofdecimals=0}%
{%
% problems, such as 4, 5, 6, ...
\def\problemnumber{#1}%
}%
{}%
\ifthenelse{\numberofdecimals=1}%
{%
% problems, such as 4.3, 1.2, 10.5
\StrBefore{#1}{.}[\problemnumber]%
}%
{}%
\ifthenelse{\numberofdecimals=2}%
{%
% subproblems such as 1.3.1, 1.2.4, 7.5.6
\StrBehind{#1}{.}[\newbit]%
\StrBefore{\newbit}{.}[\problemnumber]%
}%
{}%
%
% determine if the problem number is odd or even
% and depending on our choices above, display or not
\ifthenelse{\isodd{\problemnumber}}%
{%
% set a boolean that says the problem number is odd (used later)
\setboolean{oddproblemnumber}{true}%
% display or not
\ifthenelse{\boolean{showoddsolns}}%
{%
% if we want to show the odd problems
}%
{%
% otherwise don't show them!
\expandafter\comment%
}%
}%
{%
% even numbered problem, set the boolean (used later)
\setboolean{oddproblemnumber}{false}%
\ifthenelse{\boolean{showevensolns}}%
{%
% if we want to show the even problems
}%
{%
% otherwise don't show them!
\expandafter\comment%
}%
}%
}%
{%
% after the environment finishes
\ifthenelse{\boolean{oddproblemnumber}}%
{%
% odd numbered problems
\ifthenelse{\boolean{showoddsolns}}%
{%
% if we want to show the odd problems
% then the environment is finished
}%
{%
% otherwise we need to finish the comment
\expandafter\endcomment%
}%
}%
{%
% even numbered problems
\ifthenelse{\boolean{showevensolns}}%
{%
% if we want to show the even problems
% then the environment is finished
}%
{%
% otherwise we need to finish the comment
\expandafter\endcomment%
}%
}%
}

\clearpage

% set solution figure width
\newlength{\solutionfigurewidth}
\setlength{\solutionfigurewidth}{3cm}

% input the SHORT solutions file
\IfFileExists{shortsolutions.tex}{\input{shortsolutions.tex}}{}

%=======================
%   END SOLUTIONS
%=======================

\end{document}

-
I managed to compile your code in TeXShop by choosing the "LaTeX typesetting program". However, it does not compile under "XeLaTeX" or "LualaTeX" typesetting programs. This is the first time I encountered this. Usually it is the other way around. –  Sony Dec 21 '11 at 13:26
@Sony Interesting... I usually use latex=>dvips=>ps2pdf on this file because of the PSTricks. If you generate the graphs in something else (e.g TikZ) then you could use anything. –  cmhughes Dec 21 '11 at 17:13

Macro package: ConTeXt (ver: 2011.10.20)
Engine: LuaTeX
Category: Other

In \TEX\ \type{%} creates a line comment, i.e., \TEX\
ignores the material % CHECK: use text instead?
from \type{%} until the end of the line. As a result,
often % CHECK: use sometimes instead?
you have to bream lines just to comment some material.

% The line comment mechanism also makes it hard to comment
% blocks of text. A \TEX\ aware engine makes it easier to
% hide the fact that \TEX\ does not have block comments.


It is possible to define a macro for block comments. For example

\define[1]\hide{\removeunwantedspace}


works well for simple comments. However, the content of such a macro is parsed by TeX, so such a macro fails miserably on input like

blah blah \hide{\iffalse} blah blah


Another option is to use buffers for block comments. ConTeXt already defines a hiding buffer for this purpose. For example

blah blah \starthiding \iffalse \stophiding blah blah


works fine. (For non-ConTeXt users, ConTeXt buffer is roughly equal to the functionality of the LaTeX fileconent and comment packages but on steroids. For the purpose of hiding content, the comment package can be used, but IIRC, the \end{comment} statement must be on a line of its own, defeating its purpose a block comment marker). Nonetheless, using buffers for block comments is not ideal. For one, it is a lot of typing! But more importantly, buffers cannot be part of the argument of another comment. So,

\section{Will this work \starthiding of course, not \stophiding}


does not work.

With LuaTeX, it is possible to have true block comments in TeX. LuaTeX allows you to intercept and filter text before it is passed on to TeX. We can write an appropriate Lua code to implement block comments as such a filter. An example, is the m-translate module which allows for creative solution to text substitution questions. For example, see:

The code below grew out of a question about block contents on the ConTeXt mailing list. Save the block below as t-comments.mkvi. Yes, that's right, the extension must be mkvi. This allows for named arguments for TeX macros (See comments on code below).

%D \module
%D      version=2011.11.14,
%D        title=\CONTEXT\ User Module,
%D       author=Hans Hagen and Aditya Mahajan,
%D         date=\currentdate,

\startluacode
thirddata          = thirddata or { }
local comments     = { filters = { } }

local textlineactions = resolvers.openers.helpers.textlineactions
local sequencers      = utilities.sequencers
local constants       = interfaces.constants

local gsub, find, format = string.gsub, string.find, string.format

local empty_line = "%%" -- FIXME Make catcode independent!

local settings = utilities.parsers.settings_to_hash(settings)
local start = string.escapedpattern(settings[constants.start] or "")
local stop  = string.escapedpattern(settings[constants.stop] or "")
local any   = ".-"
if start ~= "" and stop ~= "" then
local strip_inline     = function(s) return gsub(s, start .. any .. stop, "", 1) end
\newcommand{\@leftorn}{}
\newcommand{\@rightorn}{}

% This is where the magic happens: the \discretionary hyphenation
% command is abused to provide a \@spacer only if the line is not
% breaking at this point, and a \@leftorn or \@rightorn if
% necessary. The @prevarg flag is to determine whether or not we are
% at the beginning of a list or after a line break (in which case we
% need a left ornament rather than a spacer).
\newcommand{\@spacerifneeded}{\if@prevarg%
\discretionary{\@rightorn}{\@leftorn}{\@spacer}\else\@leftorn\fi}

% The "new line break" command puts in a right ornament, executes the
% usual line break code, and then sets @prevarg to false.
\newcommand{\@newlb}{\@rightorn\@oldlb\@prevargfalse}

% This is the command used for each item in the list. We wrap it in a
% mbox to ensure that we don't get any genuine hyphenation (or
% breaking at spaces, which is not desirable in this case).
\newcommand{\ci}[1]{%
\@spacerifneeded\@prevargtrue%
\mbox{#1}\ignorespaces}

% And this is the environment that will surround the list. We abuse
% the list environment to provide wider margins if desired (specified
% by the optional argument), then define the @prevarg flag and add the
% hooks to the linebreaking code as redefined above. To finish the
% environment we add a final right ornament before closing the centre
% and list environments.
\newenvironment{centrelist}[1][0em]{%
\begin{list}{}{\leftmargin=#1\rightmargin=#1}\item%
\begin{center}\newif\if@prevarg%
\let\@oldlb=\\\let\\=\@newlb%
}
{\@rightorn\end{center}\end{list}}
\makeatother

\begin{document}

% A simple shopping list (?) with indented margins.
\sffamily
\begin{centrelist}[10em]
\ci{apples}
\ci{celery}
\ci{doughnuts}
\ci{eggplant}
\ci{french fries}
\ci{garlic}
\ci{hummous}
\ci{ice}
\ci{jellybeans}
\end{centrelist}

% Fancier, and demonstrating the line breaking feature: the family of
% James I of England.
\vspace{24pt}
\cspacer{\hspace{0.5em}\scalebox{0.85}{\decoone}\hspace{0.5em}}
\cleft{\leafright\hspace{0.3em}}
\cright{\hspace{0.3em}\leafleft}
\renewcommand{\baselinestretch}{1.5}\rmfamily

\begin{centrelist}
\Large\itshape
\ci{James I of England}
\ci{Anne of Denmark}\\
\normalsize\upshape
\ci{Henry, Prince of Wales}
\ci{Elizabeth of Bohemia}
\ci{Margaret Stuart}
\ci{Charles I of England}
\ci{Robert Stuart, Duke of Kintyre}
\ci{Mary Stuart}
\ci{Sophia Stuart}
\end{centrelist}

% Another fancier demonstration, this time with Christian III of Denmark.
\vspace{24pt}
\cspacer{\hspace{0.3em}\starredbullet\hspace{0.3em}}
\cleft{\decofourleft\hspace{0.6em}}
\cright{\hspace{0.6em}\decofourright}

\begin{centrelist}
\ci{Christian III of Denmark}
\ci{Dorothea of Saxe-Lauenburg}\\
\ci{Anna of Denmark}
\ci{Frederick II of Denmark}
\ci{Magnus, King of Livonia}
\ci{Johann II, Duke of Schleswig-Holstein-Sonderburg-Plon}
\ci{Dorothea of Denmark}
\end{centrelist}

\end{document}


gives

Not something most of us would use in day-to-day typesetting, but perhaps someone may find it useful for the occasional special effect. Enjoy!

(All royal family details straight from Wikipedia, with no expert knowledge - or indeed knowledge of any other sort - about these implied!)

-
I really like this, have you considered turning it into a CTAN package? –  doncherry Nov 25 '11 at 13:52
@doncherry: thank you! I had briefly considered this, but wondered whether it was too much of a one-off special effect to be really appropriate as a package. But I'll think again... –  Ant Nov 25 '11 at 14:57
Well, it seems your concept is pretty flexible in terms of which symbols you use, whether there are symbols at the beginning and the end of a line etc., so there could be verious uses for it. I can even imagine it for a table of contents. You could include some different setups or "styles" to choose from plus the option to specify personalized symbols. But most of all, this could be a great learning opportunity for you; but that's of course assuming you have the time to spare and the intention of going into this direction. –  doncherry Nov 25 '11 at 15:02

I created a document in which Rubik's cube is built from small cubes and demonstrated:

%Author: Count Zero
%*free to be reused both partially and integrally by anyone*

\documentclass{article}

\usepackage{pxfonts}% change the font from Computer Modern to Adobe Palatino
\usepackage{marvosym}% special characters used in the document :)
\usepackage{tikz}% that's what does to the 'nice' things, that is the drawings ;)
\usepackage{lipsum}% some random text, known as 'Lorem ipsum'

%Here the a command is defined to draw a cube (only the visible faces) in isometric view.
%The cube need not be in the origin, the distances of the bottom-behind corner from the origin are taken as parameters.
%It takes 7 (!) parameters:
%1 - length of an edge
%2 - color of the front face
%3 - color of the top face
%4 - color of the right face
%5 - x-position in space
%6 - x-position in space
%7 - x-position in space
\newcommand{\cubedxdydz}[7]{
\pgfmathparse{#1+#5}\let\dx\pgfmathresult% calculate the 'displacement' (distance from the origin) of the far corners of the cube along the x axis from the arguments
\pgfmathparse{#1+#6}\let\dy\pgfmathresult% calculate the 'displacement' (distance from the origin) of the far corners of the cube along the y axis from the arguments
\pgfmathparse{#1+#7}\let\dz\pgfmathresult% calculate the 'displacement' (distance from the origin) of the far corners of the cube along the z axis from the arguments
% draw the visible faces
\draw[ultra thick,fill=#2] (#5,#6,\dz) -- (\dx,#6,\dz) -- (\dx,\dy,\dz) -- (#5,\dy,\dz) -- cycle;%The thickest line was selected with the first option, then the color specified in the 2nd argument is used to fill the front face of the small cube. Finally the rectangle is drawn and filled. 'cycle' closes the path. The 'rectangle' command does not work with 3D coordinates, so this is the way to draw the squres with space coordinates
\draw[ultra thick,fill=#3] (#5,\dy,\dz) -- (\dx,\dy,\dz) -- (\dx,\dy,#7) -- (#5,\dy,#7) -- cycle;
\draw[ultra thick,fill=#4] (\dx,#6,\dz) -- (\dx,#6,#7) -- (\dx,\dy,#7) -- (\dx,\dy,\dz) -- cycle;
}

%another command to draw a solved Rubik's cube more easily. The arguments used are:
%1 - number of cubes along each side (e.g. 3 x 3 x 3 cube)
%2-4 - colors of the visible faces
\newcommand{\rubikcube}[4]{
\pgfmathparse{#1-1}\let\ncubes\pgfmathresult%the value 1 has to be subtracted from the given number of cubes/side to avoid the origin of the initial cube to be displaced
\foreach \x in {0,...,\ncubes}{%
\foreach \y in {0,...,\ncubes}{%
\foreach \z in {0,...,\ncubes}{%
\cubedxdydz{1}{#2}{#3}{#4}{\x}{\y}{\z}
}
}
}
}

\begin{document}

\title{Rubik's Cube}
\author{Me}
\maketitle

\abstract%The part of text I wrote and would like you to read. :)
Rubik's cube is a famous puzzle, known worldwide. Lots of enthusiastic fan communities exist around the world. It is amazing, how a simple mechanism like this can catch on and enjoy the attention of people for such long time.

%a hyperlink has been included to the site that inspired me
I found a \href{http://www.rubiks.com}{site} where solutions to Rubik's cube are given and I thought it could be fun to produce the solutions in \LaTeX. Unfortunately (or fortunately? \Smiley) I found no package on CTAN to draw it. So here is an attempt to do it, making use of TikZ' rather paltry 3D support and with possible reuse for other purposes, e.g. draw hypermatrices. I would like to further develop it into a package and upload it to CTAN.

One feature I really want to implement is 3D rotation to show how you actually have to rotate the cube itself.

If you like it, please vote for it! This is for me an opportunity to test the waters, and, independently of whether I win something or not \Smiley, if there are enough interested people, I will finalize the package. It's all up to you! Happy voting! \Smiley

(Below in an excerpt from the solution manual found on \href{http://www.rubiks.com}{Rubik's Official Site}.)

\section{Solution to Obtain the White Cross''}

Holding your cube with the white center piece on the top face, you must create a white cross as shown:

\begin{figure}[!htb]%placement of the figure preferably right here, on top of the page or on the bottom of the page, but not on a separate floats page
\centering%this way the figure will be centered across the page
\begin{tikzpicture}[line join=round,line cap=round,scale=0.75]%The lines do not join nicely if the end of the lines and the line caps are not rounded (first two options). The last option scales the whole picture created with TikZ.
%I renamed some colors to save time typing and to make the code less cluttered.
\colorlet{R}{red}
\colorlet{G}{green}
\colorlet{B}{blue}
\colorlet{Y}{yellow}
\colorlet{O}{orange}
\colorlet{W}{white}
\colorlet{X}{black!50}%grey is used if the color of the face does not matter

%drawing the cube
%top face
\cubedxdydz{1}{X}{X}{X}{0}{2}{0}
\cubedxdydz{1}{X}{W}{X}{1}{2}{0}

\cubedxdydz{1}{X}{W}{X}{0}{2}{1}
\cubedxdydz{1}{X}{W}{X}{1}{2}{1}

%%right face
\cubedxdydz{1}{X}{X}{X}{2}{0}{0}
\cubedxdydz{1}{X}{X}{X}{2}{0}{1}

\cubedxdydz{1}{X}{X}{X}{2}{1}{0}
\cubedxdydz{1}{X}{X}{B}{2}{1}{1}

\cubedxdydz{1}{X}{X}{X}{2}{2}{0}
\cubedxdydz{1}{X}{W}{B}{2}{2}{1}

%front face
\cubedxdydz{1}{X}{X}{X}{0}{0}{2}
\cubedxdydz{1}{X}{X}{X}{1}{0}{2}
\cubedxdydz{1}{X}{X}{X}{2}{0}{2}

\cubedxdydz{1}{X}{X}{X}{0}{1}{2}
\cubedxdydz{1}{R}{X}{X}{1}{1}{2}
\cubedxdydz{1}{X}{X}{X}{2}{1}{2}

\cubedxdydz{1}{X}{X}{X}{0}{2}{2}
\cubedxdydz{1}{R}{W}{X}{1}{2}{2}
\cubedxdydz{1}{X}{X}{X}{2}{2}{2}
\end{tikzpicture}
\label{fig:one}
\end{figure}

Now I'll just insert a bit of \emph{Lorem ipsum}... (I am too lazy to type the content and I cannot copy-paste... Apparently the source has been scanned without OCR.) So, here we go.

\lipsum[1]%first paragraph from the lipsum random text

\section{Get the White Corners''}

\lipsum[2]

\begin{figure}[!htb]
\centering
\begin{tikzpicture}[line join=round,line cap=round,scale=0.75]
\colorlet{R}{red}
\colorlet{G}{green}
\colorlet{B}{blue}
\colorlet{Y}{yellow}
\colorlet{O}{orange}
\colorlet{W}{white}
\colorlet{X}{black!50}

%top face
\cubedxdydz{1}{X}{W}{X}{0}{2}{0}
\cubedxdydz{1}{X}{W}{X}{1}{2}{0}

\cubedxdydz{1}{X}{W}{X}{0}{2}{1}
\cubedxdydz{1}{X}{W}{X}{1}{2}{1}

%%right face
\cubedxdydz{1}{X}{X}{X}{2}{0}{0}
\cubedxdydz{1}{X}{X}{X}{2}{0}{1}

\cubedxdydz{1}{X}{X}{X}{2}{1}{0}
\cubedxdydz{1}{X}{X}{B}{2}{1}{1}

\cubedxdydz{1}{X}{W}{B}{2}{2}{0}
\cubedxdydz{1}{X}{W}{B}{2}{2}{1}

%front face
\cubedxdydz{1}{X}{X}{X}{0}{0}{2}
\cubedxdydz{1}{X}{X}{X}{1}{0}{2}
\cubedxdydz{1}{X}{X}{X}{2}{0}{2}

\cubedxdydz{1}{X}{X}{X}{0}{1}{2}
\cubedxdydz{1}{R}{X}{X}{1}{1}{2}
\cubedxdydz{1}{X}{X}{X}{2}{1}{2}

\cubedxdydz{1}{R}{W}{X}{0}{2}{2}
\cubedxdydz{1}{R}{W}{X}{1}{2}{2}
\cubedxdydz{1}{R}{W}{B}{2}{2}{2}
\end{tikzpicture}
\label{fig:two}
\end{figure}

\lipsum[3]

\section{Cube Solved}

Here I used loops to speed up the creation of the box, since all faces are the same color:

\begin{figure}[!htb]
\centering
\begin{tikzpicture}[line join=round,line cap=round,scale=0.75]
\colorlet{R}{red}
\colorlet{G}{green}
\colorlet{B}{blue}
\colorlet{Y}{yellow}
\colorlet{O}{orange}
\colorlet{W}{white}
\colorlet{X}{black!50}

\rubikcube{3}{R}{G}{B}
\end{tikzpicture}
\hspace{1cm}
\begin{tikzpicture}[line join=round,line cap=round,scale=0.75]
\colorlet{R}{red}
\colorlet{G}{green}
\colorlet{B}{blue}
\colorlet{Y}{yellow}
\colorlet{O}{orange}
\colorlet{W}{white}
\colorlet{X}{black!50}

\rubikcube{3}{O}{W}{Y}
\end{tikzpicture}
\label{fig:three}
\caption{The solution}
\end{figure}

\lipsum[4]

And another one with cubes with another number of sides:

\begin{figure}[!htb]
\centering
\begin{tikzpicture}[line join=round,line cap=round,scale=0.75,rotate=-10]%the last option rotates the picture - unfortunately no 3D-rotation, only in the plane of the sheet
\colorlet{R}{red}
\colorlet{G}{green}
\colorlet{B}{blue}
\colorlet{Y}{yellow}
\colorlet{O}{orange}
\colorlet{W}{white}
\colorlet{X}{black!50}

\rubikcube{4}{R}{W}{G}
\end{tikzpicture}
\hspace{1cm}
\begin{tikzpicture}[line join=round,line cap=round,scale=0.75]
\colorlet{R}{red}
\colorlet{G}{green}
\colorlet{B}{blue}
\colorlet{Y}{yellow}
\colorlet{O}{orange}
\colorlet{W}{white}
\colorlet{X}{black!50}

\rubikcube{2}{B}{Y}{R}
\end{tikzpicture}
\label{fig:four}
\caption{The solution}
\end{figure}

\end{document}


And the output:

-
Nice.. How come the \colorlet were not defined in the preamble. I thought perhaps you were changing them for each figure, but that does not seem to be the case. Also minor suggestion: instead of \pgfmathparse{#1+#5}\let\dx\pgfmathresult you could just use \pgfmathsetmacro{\dx}{#1+#5}. –  Peter Grill Nov 18 '11 at 17:06
@PeterGrill: I was copy-pasting code snippets and was oblivious to this detail in the heat of the action... :) –  Count Zero Nov 18 '11 at 17:12
Is this a submission for academic or other? I'd say other? –  doncherry Nov 25 '11 at 14:33
That's right: I forgot to mention: it's OTHER. –  Count Zero Nov 25 '11 at 15:36