LaTeX forum ⇒ LyXHow 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?

Postby StarValkyrie » Fri Feb 20, 2015 5:19 pm

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

Yes, I know. I explained this in the download post above...
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

Postby 87234asdffdd » Mon Jul 06, 2015 4:51 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

Postby StarValkyrie » Mon Jul 06, 2015 6:27 pm

I've attached a template.
Attachments
ExamTemplate.lyx
(7.18 KiB) Downloaded 272 times
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

Postby 87234asdffdd » Tue Jul 07, 2015 4:30 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

Postby StarValkyrie » Tue Jul 07, 2015 5:44 pm

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

Postby 87234asdffdd » Tue Jul 07, 2015 10:43 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 :D
Attachments
exam.txt
exam.layout (must change extension)
(15.78 KiB) Downloaded 169 times

StarValkyrie
Posts: 89
Joined: Fri Jan 24, 2014 12:42 am

Postby StarValkyrie » Tue Jul 07, 2015 11:55 pm

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

Postby 87234asdffdd » Wed Jul 08, 2015 3:31 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

Postby StarValkyrie » Wed Jul 08, 2015 5:27 pm

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
(15.77 KiB) Downloaded 189 times

87234asdffdd
Posts: 7
Joined: Mon Jul 06, 2015 4:46 pm

Postby 87234asdffdd » Sun Jul 19, 2015 3:37 am

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).

  1. InsetLayout "Flex:1. Questions"
  2. LabelFont
  3. Family Sans
  4. Series Bold
  5. EndFont
  6. Decoration Conglomerate
  7. BgColor insetbg
  8. LyxType Custom
  9. LatexName questions
  10. LatexType Environment
  11. LabelString "Questions block"
  12. ResetsFont true
  13. End
  14.  
  15. InsetLayout "Flex:1.1. Question Parts"
  16. CopyStyle "Flex:1. Questions"
  17. LatexName parts
  18. LabelString "Question Parts block"
  19. End
  20.  
  21. InsetLayout "Flex:1.1.1. Question Subparts"
  22. CopyStyle "Flex:1. Questions"
  23. LatexName subparts
  24. LabelString "Question Subparts block"
  25. End
  26.  
  27. InsetLayout "Flex:1.1.1.1. Question Subsubparts"
  28. CopyStyle "Flex:1. Questions"
  29. LatexName subsubparts
  30. LabelString "Question subsubparts block"
  31. End
  32.  
  33. InsetLayout "Flex:Multiple Choice Answers"
  34. CopyStyle "Flex:1. Questions"
  35. LatexName choices
  36. # to manage no page breaks
  37. LeftDelim \nopagebreak\noindent\begin{minipage}[]{\linewidth}
  38. RightDelim \end{minipage}\pagebreak[3]
  39. LabelString "Multiple Choice Answers block (no page breaks)"
  40. End
  41.  
  42. InsetLayout "Flex:Inline Multiple Choice Answers"
  43. CopyStyle "Flex:1. Questions"
  44. LatexName oneparchoices
  45. LabelString "Inline Multiple Choice Answers block"
  46. 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:
  1. Style ExperimentQuestion
  2. CopyStyle Enumerate
  3. LatexType Command
  4. LeftMargin "MM"
  5. LatexName question
  6. ParSkip 0.4
  7. Align Left
  8. LabelType Static
  9. LabelCounter questionnumber
  10. LabelString "\arabic{questionnumber}."
  11. Category Questions
  12. Argument 1
  13. LabelString "Points"
  14. Tooltip "Number of points, e.g., 1, 2, 5"
  15. AutoInsert 1
  16. LeftDelim "["
  17. RightDelim "]"
  18. EndArgument
  19. # the following argument is a hack to get spaces and a new line after the \question or \question[n] instance
  20. # unfortunately, the question text is always nested inside {}, which is how LatexType Command styles work
  21. # I'm not sure what the impact of that is, however. My PDF results seem fine.
  22. Argument 2
  23. LabelString "skip"
  24. LeftDelim "<br/>"
  25. RightDelim " "
  26. PresetArg " "
  27. EndArgument
  28. End


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.


Return to “LyX”

Who is online

Users browsing this forum: No registered users and 6 guests