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).
Code: Select all
InsetLayout "Flex:1. Questions"
LabelFont
Family Sans
Series Bold
EndFont
Decoration Conglomerate
BgColor insetbg
LyxType Custom
LatexName questions
LatexType Environment
LabelString "Questions block"
ResetsFont true
End
InsetLayout "Flex:1.1. Question Parts"
CopyStyle "Flex:1. Questions"
LatexName parts
LabelString "Question Parts block"
End
InsetLayout "Flex:1.1.1. Question Subparts"
CopyStyle "Flex:1. Questions"
LatexName subparts
LabelString "Question Subparts block"
End
InsetLayout "Flex:1.1.1.1. Question Subsubparts"
CopyStyle "Flex:1. Questions"
LatexName subsubparts
LabelString "Question subsubparts block"
End
InsetLayout "Flex:Multiple Choice Answers"
CopyStyle "Flex:1. Questions"
LatexName choices
# to manage no page breaks
LeftDelim \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 oneparchoices
LabelString "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:
Code: Select all
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 " "
EndArgument
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.