From 988d1c5db5d01e9506672e0430a11b314bf6c525 Mon Sep 17 00:00:00 2001 From: Frank Fuhlbrück Date: Fri, 11 Feb 2022 22:14:01 +0100 Subject: ver 0.11 - local references --- examples/exshexample.tex | 6 ++-- exercisesheets.sty | 73 +++++++++++++++++++++++++++++++----------------- exercisesheets.tex | 54 +++++++++++++++++++++++++++++++++-- 3 files changed, 103 insertions(+), 30 deletions(-) diff --git a/examples/exshexample.tex b/examples/exshexample.tex index 85b726a..bc4d3ec 100644 --- a/examples/exshexample.tex +++ b/examples/exshexample.tex @@ -60,7 +60,7 @@ only={-} \item\points[pointsfloatright]{2}pgf (for pgfkeys) \item enumitem and similar \points[abbrev,bonus]{1} \begin{enumerate} - \item paralist + \item paralist \thesubex \item \begin{enumerate} \item varioref @@ -153,7 +153,9 @@ only={-} \end{exercise} Loading varioref enables you to refer to sub-exercises, like - this: Did you do \ref{subex:man2}? + this: Did you do \ref{subex:man2}? It is the subexercise + \subexnref{subex:man2} and has label \subexlref{subex:man2}. + \begin{exercise}[points={many, many}, firstline={Play around with the options.}] diff --git a/exercisesheets.sty b/exercisesheets.sty index 6616f9a..9c8c502 100644 --- a/exercisesheets.sty +++ b/exercisesheets.sty @@ -18,8 +18,8 @@ %\NeedsTeXFormat{LaTeX2e}[1994/12/01] % don't forget to update the version and date in exercisesheets.tex -\def\exsh@version{0.10+git} -\def\exsh@date{2022/01/12} +\def\exsh@version{0.11} +\def\exsh@date{2022/02/11} \ProvidesPackage{exercisesheets}[\exsh@date\space\exsh@version\space Typesetting of exercise sheets] \message{`Typesetting of exercise sheets' \exsh@version\space <\exsh@date>} @@ -43,6 +43,9 @@ \RequirePackage{currfile} \RequirePackage{catchfile} +%we need getrefnumber +\RequirePackage{refcount} + % configuration keys \newif\ifexsh@beamer @@ -877,8 +880,9 @@ {\csname the#1\endcsname\autodot\enskip}}% }{} -%Do nout use \let here as \label may change before its use +%Do not use \let here as \label may change before its use \def\exsh@autolabel{\label} +\def\inexlabel{\label} \newcounter{exsh@pts@cur} \newcounter{exsh@ptsbonus@cur} @@ -1088,6 +1092,7 @@ %auto labelling is still allowed, but other labels are forbidden %here we may use \let as the definition is close to its use \let\exsh@autolabel\label + \let\inexlabel\label \def\label##1{% \PackageError{exercisesheets}{\string\label{##1}\space inside \string\includeexercise*}{}% @@ -1153,9 +1158,23 @@ \labelformat{section}{\pgfkeysvalueof{/exsh/strings/exercise}~\arabic{section}} } + +\let\exsh@subexn\getrefnumber + \ifexsh@patchenumerate \AfterPackage*{varioref}{ \labelformat{enumi}{\arabic{section}.\alph{enumi}} + \def\exsh@afterdot#1.#2{#2}%x.y -> y + \def\exsh@subexn#1{% + \if\getrefnumber{#1}0% + 0% + \else%x.y->y, then inverse \@alph + \the\numexpr(\expandafter\expandafter\expandafter% + \expandafter\expandafter\expandafter% + \expandafter`\expandafter\expandafter\expandafter% + \exsh@afterdot\getrefnumber{#1}-`a+1)\relax% + \fi% + } } \AfterPackage*{paralist}{ \setdefaultenum{(a)}{(1)}{i.}{A.} @@ -1182,6 +1201,29 @@ }% \fi +\newcommand{\subexnref}[1]{\exsh@subexn{#1}} +\newcommand{\subexlref}[1]{(\@alph{\exsh@subexn{#1}})} + +%for now this is not part of the public interface +\exshset{subtask counter/.initial={enumi}} +\exshset{subtask environment/.initial={enumerate}} +\exshset{subtask item/.initial={item}} +\edef\exsh@subtaskctr{\pgfkeysvalueof{/exsh/subtask counter}} +\def\exsh@subtaskenv{\pgfkeysvalueof{/exsh/subtask environment}} +\def\exsh@subtaskitm{\pgfkeysvalueof{/exsh/subtask item}} + +%define subex as an alias for enumi +\expandafter\let\expandafter\c@subex% + \csname c@\exsh@subtaskctr\endcsname +\expandafter\let\expandafter\p@subex% + \csname p@\exsh@subtaskctr\endcsname +\expandafter\let\expandafter\thesubex% + \csname the\exsh@subtaskctr\endcsname +\expandafter\let\expandafter\theHsubex% + \csname theH\exsh@subtaskctr\endcsname +\expandafter\let\expandafter\cl@subex% + \csname cl@\exsh@subtaskctr\endcsname + % reset equation numbering for each exercise \@addtoreset{equation}{section} @@ -1197,25 +1239,6 @@ \ignorespaces }{} -%we ignore everything before the frist item -%and process everything afterwards -\long\def\exsh@processsubtasks#1\item#2\item{% -\ifstrequal{#2}{}{}{% -\item #2% -\csgdef{exsh@restatetask\arabic{enumi}}{#2}% -\exsh@processsubtasks\item%new "frist" \item to ignore -}%no whitespace here is crucial for end detecttion -} - -\long\def\exsh@collectedsubtasks#1{ -\begin{enumerate} -\exsh@processsubtasks#1\item\item -\end{enumerate}% -} - -\def\exsh@subtaskenv{enumerate} -\def\exsh@subtaskitm{item} -\def\exsh@subtaskctr{enumi} \newenvironment{subtasks}[1][]{% \pgfkeys{exsh,#1}% \begin{\exsh@subtaskenv} @@ -1308,7 +1331,7 @@ \pgfkeysvalueof{/exsh/solution title font}% \pgfkeysvalueof{/exsh/strings/solution} % (\pgfkeysvalueof{/exsh/strings/exercise} \arabic{section}% - \ifnum\@enumdepth>0\alph{enumi}\fi)% + \ifnum\@enumdepth>0\alph{subex}\fi)% \end{alertblock} }{ \begin{beamercolorbox}[rounded=true,wd={#1}]% @@ -1316,7 +1339,7 @@ \pgfkeysvalueof{/exsh/solution title font}% \pgfkeysvalueof{/exsh/strings/solution} % (\pgfkeysvalueof{/exsh/strings/exercise} \arabic{section}% - \ifnum\@enumdepth>0\alph{enumi}\fi)% + \ifnum\@enumdepth>0\alph{subex}\fi)% \end{beamercolorbox} } } @@ -1367,7 +1390,7 @@ % \pgfkeysvalueof{/exsh/solution title font}% % \pgfkeysvalueof{/exsh/strings/solution} % % (\pgfkeysvalueof{/exsh/strings/exercise} \arabic{section}% -% \alph{enumi})% +% \alph{subex})% % \endblock \ifbool{exsh@framed}{\exsh@defersolutiontitletrue}{} \ifbool{exsh@defersolutiontitle}{}{% diff --git a/exercisesheets.tex b/exercisesheets.tex index 688482d..ea02e92 100644 --- a/exercisesheets.tex +++ b/exercisesheets.tex @@ -39,7 +39,7 @@ breakatwhitespace, columns=flexible, escapeinside={(*}{*)}, - mathescape, + mathescape=false, } \usepackage[pdfusetitle,colorlinks]{hyperref} @@ -53,7 +53,7 @@ \usepackage[english,iso]{isodate} \title{The \exsh Package} \author{Sebastian Kuhnert\and Frank Fuhlbrück} -\date{Version 0.10, \printdateTeX{2022/01/12}} +\date{Version 0.11, \printdateTeX{2022/02/11}} \begin{document} \maketitle @@ -110,6 +110,7 @@ Frank Fuhlbrück \item \texttt{ifthen} \item \texttt{amsmath} (for \verb|\numberwithin|) \item \texttt{iflualatex} + \item \texttt{refcount} (for \verb|\getrefnumber|) \end{itemize} @@ -480,6 +481,35 @@ if sub-exercises are not simply \verb|\item|s in \end{exercise} \end{lstlisting} +\subsection{Labels and References within an Exercise} +While the global reference labels set via varioref (if loaded) +are nice for references to subexercises far away, always mentioning +the exercise number seems superfluous. Furthermore, for usage in indices etc. you might want to use the arabic representation instead. This is what the commands \verb|\subexnref| and +\verb|\subexlref| are designed for. However, both of them still +require an ordinary label, which is not allowed in +exercises loaded with \verb|\loadexercise*|. +For this purpose \verb|\locallabel| can be used which is just a +normal label that is not redefined to produce an error. +Furthermore, we define a counter \verb|subex| (which is +currently just an alias for enumi, but this might change). You can +use this counter (alias) with common commands like +\verb|\arabic| or \verb|\alph|. + +\begin{lstlisting} +\begin{exercise} + \begin{enumerate} + \item \locallabel{subex:xisseven} Let $x_{\thesubex}=7$. + \item Compute $x_{\subexnref{subex:xisseven}}+3$. + \begin{solution} + From \subexlref{subex:xisseven} %(a) + we know that $x_{\subexnref{subex:xisseven}}$ is $7$ and + thus the sum is $10$. + \end{solution} + \end{enumerate} +\end{exercise} +\end{lstlisting} + + \section{Advanced Usage} @@ -735,7 +765,7 @@ Since version 0.11 there is a Lua interface for the exercise environment. This interface will offer roughly the same features. Its main purpose will be allowing to reorder sub-exercises more easily and to offer more dynamic options for the display of -solutions (one combined solution or single after each sub- +solutions (one combined solution or single after each sub-% exercise). %TODO finish \begin{lstlisting} @@ -775,6 +805,24 @@ with solutions. This also works well in combination with a make file that generates \texttt{solutions.tex}. + + +\section{Changelog} +\label{sec:changelog} + +\begin{itemize} + \item[v. 0.11:] 2022-02-11 + \begin{itemize} + \item Local references and the subex counter + \item Lua interface (not documented yet, see example and example file) + \item Framed solutions can now be fragile, however this + also require Lua\LaTeX (but not using the Lua Interface). + \item beamer version is now included (no separate package) + \item some bug fixes + \end{itemize} +\end{itemize} + + \end{document} %%% Local Variables: -- cgit v1.2.3