Sunday, June 12, 2011

LaTeX exam package

I am currently participating in an OCJP study group at work and have decided to try to come up with some questions for the study sessions. I've decided to use the LaTeX exam package for writing the questions. It is very easy to create simple multiple choice style questions and answers can be included in the generated file through the inclusion of an optional flag in the LaTeX source file. A very simple example follows: \documentclass[answers]{exam} % use for controlling margins \usepackage{anysize} \marginsize{2cm}{2cm}{2cm}{2cm} % use for code listings \usepackage{textcomp} \usepackage{listings} \lstset{basicstyle=\ttfamily} \lstset{showspaces=false} \lstset{upquote=true} \begin{document} \begin{questions} \question Given the following, what is the result? \lstinputlisting[numbers=left]{ch01_code/unicodeVariable.java} \begin{choices} \choice Compilation failure on line 3 \choice Compilation failure on line 4 \choice { `h', `e', `l', `l', `o' } \CorrectChoice hello \end{choices} \begin{solution} Variable names can be declared using unicode naming formats \end{solution} \end{questions} \end{document} And the content of ch01_code/unicodeVariable.java is: class Foo { public static void main(String[] args) { int a, b, \u1234; char [] thisIsAString = { 'h', 'e', 'l', 'l', 'o'}; System.out.println(thisIsAString); } } That's all there is to it. Of course, more advanced operations are available, but this is enough for my purposes.

No comments:

Post a Comment