## LaTeX forum ⇒ LyX ⇒ How to add "exam" to document class?

Information and discussion about LyX, a WYSIWYM editor, available for Linux, Windows and Mac OS X systems.
StarValkyrie
Posts: 89
Joined: Fri Jan 24, 2014 12:42 am

### Re: How to add "exam" to document class?

QBO wrote:I have noticed that the errors are happening because the command which begins a question or another entity is getting concatenated to the question itself, e.g
\question
Show that ....
becomes
\questionShow ...
This could be a simple matter to fix in the layout file, but I do not know enough about layouts to be able to solve this problem. Second problem is that the class does not show itself up even after copying it to AppData\Roaming\LyX2.1. Any hints would be appreciated on this.

Best Regards

at the beginning of each question/partno/subpart/subsubpart/bonuses you must either put an ERT with the point value in square brackets or start the line with a protected space. Failing to do one or the other will throw up errors instead of compiling.

This solution is the only way to keep the option of entering points so I can't just fix it but you can easily type a protected space in LyX by holding the control key while you press the spacebar.

As to the second problem, did you Reconfigure Lyx (Tools Menu> Reconfigure)? You always have to do that to add any new document class to LyX.

Tags:

87234asdffdd
Posts: 7
Joined: Mon Jul 06, 2015 4:46 pm
Hi - would it be possible to post an example exam (in LyX) as well? It would help to understand how it should be formatted using the .style file. Thanks!

StarValkyrie
Posts: 89
Joined: Fri Jan 24, 2014 12:42 am
I've attached a template.
Attachments
ExamTemplate.lyx
Last edited by StarValkyrie on Thu Jul 09, 2015 4:13 am, edited 5 times in total.

87234asdffdd
Posts: 7
Joined: Mon Jul 06, 2015 4:46 pm
Thanks very much for the sample exam. It's a huge help. I was able to get my complex final exam up in a matter of hours. The documentation for the exam class is a huge help, too.

I have now one problem. Whenever I want to insert an itemize bullet list in LyX using the sample exam, it has no effect. I can see an error saying "Layout Itemize not known" in the lower left corner of the LyX window.

If I insert LaTeX codes, I can do a \begin{itemize}, etc. and it works fine when the PDF is generated. Just wondering why Exam is breaking the Layout Itemize functionality in LyX. Can you verify on your environment?

By the way, if I open a new document with default layout, I'm able to create a bullet list naturally.

StarValkyrie
Posts: 89
Joined: Fri Jan 24, 2014 12:42 am
You can add itemize back by opening your layout file and typing a % at the start of the line that says "NoStyle Itemize". I disabled a bunch of the basic styles that didn't seem likely to come up in an exam document so there'd be less to have to scroll through in the pulldown menu to find the class-related ones - I probably should have kept Itemize through so I'll add it back in the above txt too.

87234asdffdd
Posts: 7
Joined: Mon Jul 06, 2015 4:46 pm
Thanks again. That should be a # character to comment out something in the .layout file.

I turned on the Progress/Debug window in LyX and found there are other small syntactic probs with the .layout file, and I corrected them. I attached here.

Have you though about creating a (git) repository for your exam.layout and contributing it to the list of user-maintained layouts for LyX? See http://wiki.lyx.org/Layouts/Layouts#toc2 for a list...

I may have already convinced someone else at my school to do exams this way
Attachments
exam.txt
exam.layout (must change extension)

StarValkyrie
Posts: 89
Joined: Fri Jan 24, 2014 12:42 am
I looked at your file but I only spotted a few stylistic preferences you'd changed, nothing that should have caused an error. What errors were you getting?

I feel like most people Google for new layout files and it's just as easy to find the file here as it is on the wiki and here they can ask questions so I haven't bothered with the lyx wiki.

87234asdffdd
Posts: 7
Joined: Mon Jul 06, 2015 4:46 pm
StarValkyrie wrote:I looked at your file but I only spotted a few stylistic preferences you'd changed, nothing that should have caused an error. What errors were you getting?

Here are the errors that show in LyX when I open a document using the exam.layout (I've corrected all these errors in the version above):

LyX Process/Debug Messages wrote:delete style Chapter'
Cannot delete style Chapter*'
LyX: Unknown counter tag Witin' [around line 70 of file ~\AppData\Local\Temp\lyx_tmpdir.PJLaiFgH8932\convert_layout.TXQaPLFE8932 current token: 'Witin' context: '']
LyX: Unknown counter tag questionnumber' [around line 71 of file ~\AppData\Local\Temp\lyx_tmpdir.PJLaiFgH8932\convert_layout.TXQaPLFE8932 current token: 'questionnumber' context: '']
LyX: Missing quote [around line 85 of file ~\AppData\Local\Temp\lyx_tmpdir.PJLaiFgH8932\convert_layout.TXQaPLFE8932 current token: '\Alph{answers}
' context: '']

StarValkyrie
Posts: 89
Joined: Fri Jan 24, 2014 12:42 am
The Chapter thing's a silent error that doesn't stop lyx from removing it from the pulldown list which is the point of all the NoStyle lines so not really a problem.

I am annoyed with myself for that extra a and that missing close ". Thanks for pointing them out.

But you also changed the Alph for the answer lists to alph though and that needs to be changed back so it mimics the default output as closely as possible. I also just realized that the subpart and subsubpart counters weren't implemented right. I don't have the greek language for LyX installed though so I think I've fixed subsubpart but I can't be sure - it just displays as arabic numbers for me. I've fixed all the rest of the above in the layout attached here though.
Attachments
exam.txt

87234asdffdd
Posts: 7
Joined: Mon Jul 06, 2015 4:46 pm
I did a lot more experimenting and learning about layout files. I think it's possible to do away with the Question_Lists and Answers "--begin--" and "--end--" separators by using Flex insets for the corresponding environments.

The cool thing I learned is that you can experiment/debug a layout using LyX Document > Settings > Local Layout. Put the experimental stuff there, and the "Validate" button followed by "Apply" allows you to try things out without having to restart LyX and/or reload the document.

Here are the Flex Insets I have come up with so far (you can paste them in a Local Layout for a file you've set up with your exam.layout).

InsetLayout	"Flex:1. Questions"LabelFontFamily SansSeries Bold	EndFontDecoration	ConglomerateBgColor	insetbgLyxType	CustomLatexName	questionsLatexType	EnvironmentLabelString	"Questions block"ResetsFont trueEnd InsetLayout	"Flex:1.1. Question Parts"CopyStyle	"Flex:1. Questions"LatexName	partsLabelString	"Question Parts block"End InsetLayout	"Flex:1.1.1. Question Subparts"CopyStyle	"Flex:1. Questions"LatexName	subpartsLabelString	"Question Subparts block"End InsetLayout	"Flex:1.1.1.1. Question Subsubparts"CopyStyle	"Flex:1. Questions"LatexName	subsubpartsLabelString	"Question subsubparts block"End InsetLayout	"Flex:Multiple Choice Answers"CopyStyle	"Flex:1. Questions"LatexName	choices# to manage no page breaksLeftDelim	\nopagebreak\noindent\begin{minipage}[]{\linewidth}RightDelim	\end{minipage}\pagebreak[3]LabelString	"Multiple Choice Answers block (no page breaks)"End InsetLayout	"Flex:Inline Multiple Choice Answers"CopyStyle	"Flex:1. Questions"LatexName	oneparchoicesLabelString	"Inline Multiple Choice Answers block"End

• To find the Insets, they're in the menu Insert > Custom Insets.
• You can nest them, as in LaTeX. E.g.:
• Insert first a "1. Questions" inset, then change the first paragraph in the Inset to Question style (defined in your exam.layout)
• To define a (nested) question part, type return after the Question, and insert a "1.1. Question Parts" block, then change its first paragraph to QuestionPart.
• etc.
• Multiple choice answers are placed using the Multiple Choice Answers inset, with Choice or CorrectChoice styles inside the inset. I did some hacking of the environment to prevent page breaks within the list of choices. I tested this a lot and I think it's pretty robust.
One thing that is broken in LyX (only, LaTeX is fine) is the Multiple Choice Answers are incorrectly numbered, since the "Within" definition of the counter is reset only using the counter defined in the "--begin--" label for MC answers. In theory, the counter needs to be reset for any instance of question (part, subpart, subsubpart, bonus, etc.), but I don't think "Within" supports multiple counters (although I didn't try!)

I'm curious to get your feedback on this approach.

Another thing I tried to improve was how Points are defined (or optionally left out) of the various Question styles. The main difference was that I used LatexType Command with an argument, rather than the simple LatexType Paragraph. The following doesn't require the non-breaking space hack. Note: Because I define this as a copy of the Enumerate style, it can't be defined in Local Layout and so has to go into the exam.layout file:
Style ExperimentQuestion     CopyStyle       Enumerate     LatexType       Command     LeftMargin      "MM"     LatexName       question     ParSkip         0.4     Align           Left     LabelType       Static     LabelCounter    questionnumber     LabelString     "\arabic{questionnumber}."     Category        Questions             Argument        1         LabelString "Points"         Tooltip     "Number of points, e.g., 1, 2, 5"         AutoInsert  1         LeftDelim "["         RightDelim "]"     EndArgument# the following argument is a hack to get spaces and a new line after the \question or \question[n] instance# unfortunately, the question text is always nested inside {}, which is how LatexType Command styles work# I'm not sure what the impact of that is, however. My PDF results seem fine.     Argument 2         LabelString "skip"         LeftDelim  "<br/>"         RightDelim  " "         PresetArg " "     EndArgumentEnd

If you don't like the Points on this kind of question, you just delete the label in LyX. You can add it later with a right-click on the question. However, a (bug?) in LyX is such that the Argument will re-appear wherever the cursor is in the paragraph.