I am writing a textbook in Lyx that includes (a) exercises throughout the text of the chapters and (b) additional exercises at the end of each chapter. The end-of-chapter exercises will be formatted as numbered lists like the ones found in regular textbooks. In order not to lose the connection between each exercise and its solution, I want to write the solution to both types of exercises right after the corresponding exercise. However, I want the solutions of (a) and (b) to be printed at the end of the book.
xsim
seems to be the most up-to-date Latex package for what I want. I plan to use the default
layout for exercises intermingled with the text of each chapter. For the end-of-chapter exercises, Clemens, the author of xsim
, advised me to define a template
that mimics the enumerate
environment:
\documentclass{book}
\usepackage{xsim}
\usepackage{kantlipsum}% dummy text
\DeclareExerciseType{xrcs}{
exercise-env = xrcs ,
solution-env = sltn ,
exercise-name = \XSIMtranslate{exercise} ,
exercises-name = \XSIMtranslate{exercises} ,
solution-name = \XSIMtranslate{solution} ,
solutions-name = \XSIMtranslate{solutions} ,
exercise-template = enumerate ,
solution-template = enumerate ,
% counter = exercise % if a shared counter is wanted
}
\DeclareExerciseEnvironmentTemplate{enumerate}
{\begin{itemize}\item[\GetExerciseProperty{counter}.]}
{\end{itemize}}
\begin{document}
\chapter{My chapter}
\section{Heading One}
\kant[1]
\begin{exercise}
First exercise
\end{exercise}
\section{Heading Two}
\kant[2]
\section{Exercises}
\begin{xrcs}
Exercise One
\end{xrcs}
\begin{xrcs}
Exercise Two
\end{xrcs}
\begin{xrcs}
Exercise Three
\end{xrcs}
\end{document}
I would like to know the following:
- Is
xsim
supported by or at least compatible with Lyx? - Will I be able to write and see formulas within the environments of this package in the usual Lyx UI way?
- Are there other better alternative solutions for what I need?
- How do I install the required packages in Lyx?
Many thanks, Rodolfo
First edit Many thanks for the detailed answer!
Everything worked as expected in the LyX GUI. But I had problems when trying to compile.
I checked TexLife and the xsim package was in the list. However, it was reported as missing while trying to compile. I installed the package and this problem was solved.
Still I can't compile: I will make toy examples to report the error messages for each.
First toy example: Including only the xsimExercises and sximSolutions I get the following errors on compilation: TO BE CONTINUED.
From the code provided by Clemens, I plan to copy only the following in the Preamble:
\usepackage{xsim}
\DeclareExerciseType{xrcs}{
exercise-env = xrcs ,
solution-env = sltn ,
exercise-name = \XSIMtranslate{exercise} ,
exercises-name = \XSIMtranslate{exercises} ,
solution-name = \XSIMtranslate{solution} ,
solutions-name = \XSIMtranslate{solutions} ,
exercise-template = enumerate ,
solution-template = enumerate ,
% counter = exercise % if a shared counter is wanted
}
\DeclareExerciseEnvironmentTemplate{enumerate}
{\begin{itemize}\item[\GetExerciseProperty{counter}.]}
{\end{itemize}}
I guess that the rest corresponds to the document he created. Any mistakes?
In the Style xsimExercise that you wrote, I cannot see an instruction that connects with the command exercise
of the xsim package to begin an exercise. All that I see is LatexName xrcs
Doing small changes, to the exercise environments I included the following:
Counter xsimSolution # adaptation
Within section
End
Counter solution # adaptation
Within section
End
Style xsimSolution # adaptation
Category Reasoning
Margin First_Dynamic
LatexType Environment
LatexName sltn # adaptation
NextNoIndent 1
ResetArgs 1
Argument 1
LabelString "(string)"
Decoration Minimalistic
EndArgument
# AddToToc Exercises # adaptation
# IsTocCaption 1 # adaptation
LabelSep xx
ParIndent MMM
ParSkip 0.4
ItemSep 0.2
TopSep 0.7
BottomSep 0.7
ParSep 0.3
Align Block
AlignPossible Left
LabelType Static
LabelCounter xsimSolution # adaptation
LabelString "xsimSolution \thexsimSolution" # adaptation
Font
Shape Up
Size Normal
EndFont
LabelFont
Shape Up
Series Bold
EndFont
RefPrefix sltn # adaptation
Requires xsim # idem
End
Style Solution
Category Reasoning
Margin First_Dynamic
LatexType Environment
LatexName solution # adaptation
ParagraphGroup 1
NextNoIndent 1
ResetArgs 1
Argument 1
LabelString "(string)"
Decoration Minimalistic
EndArgument
# AddToToc Exercises # adaptation
# IsTocCaption 1 # adaptation
LabelSep xx
ParIndent MMM
ParSkip 0.4
ItemSep 0.2
TopSep 0.7
BottomSep 0.7
ParSep 0.3
Align Block
AlignPossible Left
LabelType Static
LabelCounter solution # adaptation
LabelString "solution \thesolution" # adaptation
Font
Shape Up
Size Normal
EndFont
LabelFont
Shape Up
Series Bold
EndFont
RefPrefix sol # adaptation
End