Saturday, September 4, 2010

How to typeset crosswords (with Lyx)


If you want to compile a nice collection of crosswords (or other variations, or sudoku f.e.) you can use an ad hoc software, or you can use a typesetting software properly configured. I'm speaking of Lyx, which someone described as a frontend to Latex -the typesetting language used in many scientific publications-, but it's a powerful WYSIWYM editor. Using a module named from CTAN (you'll find it at http://www.let.rug.nl/alfa/tex/tetex30/help/Catalogue/entries/cwpuzzle.html), we can write a nice set of games.
If downloaded from CTAN the package (named cwpuzzle), you need to compile the file using "tex cwpuzzle.ins", and copy the resulting ".sty" file in the texmf directory of your installation -on Ubuntu you copy it into /usr/share/texmf/tex/latex/cwpuzzle, mkdir the directory with sudo-. Next the layout file must be put into the /home/{user}/.lyx/layouts/ directory (in the file attached, we had modified the book layout file).
After opening Lyx, the first step is to create a new file and change the document class (Document->Settings) to "Puzzles".
Now is time to write Evil Red Text, cause a proper layout doesn't exist.
Using the example in the documentation, we now show how to make a simple crossword puzzle

-This is the code that produces the schema.
The begin macro has 2 arguments which represent horizontal and vertical dimensions of the puzzle.
Each cell has the format: |[n]x where [n] represent the number (optional) and x represent the letter or the * (which produces a black box), obviously, if not specified, the letter will be hidden; when the row is complete, it must be inserted the |.

\begin{Puzzle}{5}{3}%
|* |* |[1]E|X |* |.
|[2]A|[3]S|T |* |[4]T|.
|* |[5]P|A |R |T |.
\end{Puzzle}

-This code produces the definitions

\begin{PuzzleClues}{\textbf{Across}}\newline
\Clue{1}{EX}{unit of measure}\\*
\Clue{2}{AST}{\(\ast\)}\\*
\Clue{5}{PART}{sectioning unit}\\*
\end{PuzzleClues}%
\begin{PuzzleClues}{\textbf{Down}}\newline
\Clue{1}{ETA}{\(\eta\)}\\*
\Clue{3}{SP}{unit of measure}\\*
\Clue{4}{TT}{nonproportional font}\\*
\end{PuzzleClues}%


-Lastly, this code produces the solution: note that it's equal to the first presented except for the macro \PuzzleSolution.

\PuzzleSolution\begin{Puzzle}{5}{3}%
|* |* |[1]E|X |* |.
|[2]A|[3]S|T |* |[4]T|.
|* |[5]P|A |R |T |.
\end{Puzzle}




In the documentation there's a lot of examples on how to create different schemas and games.

Here's the compressed package including all the files described in the article and the examples (with source)

No comments:

Post a Comment