aboutsummaryrefslogtreecommitdiff
path: root/exercisesheets.sty
diff options
context:
space:
mode:
authorSebastian Kuhnert2016-10-19 15:14:14 +0000
committerSebastian Kuhnert2016-10-19 15:14:14 +0000
commit9467b011517db19bab4d1bba53fe67c442bd4305 (patch)
tree880994b66141c2f8bb01b3b0b07247e00d73fc1d /exercisesheets.sty
parentb1c05c427af73fd29ac3605af4845fb97ccfbed4 (diff)
downloadexercisesheets-9467b011517db19bab4d1bba53fe67c442bd4305.tar.gz
exercisesheets-9467b011517db19bab4d1bba53fe67c442bd4305.tar.bz2
exercisesheets-9467b011517db19bab4d1bba53fe67c442bd4305.zip
automatically label exercises using the filename; allow references to \input'ed exercises in other sheets
Diffstat (limited to 'exercisesheets.sty')
-rw-r--r--exercisesheets.sty30
1 files changed, 26 insertions, 4 deletions
diff --git a/exercisesheets.sty b/exercisesheets.sty
index a99f0a8..b5a81c7 100644
--- a/exercisesheets.sty
+++ b/exercisesheets.sty
@@ -20,6 +20,9 @@
\RequirePackage{amsmath}
+\RequirePackage{currfile}
+\RequirePackage{catchfile}
+
% configuration keys
\newif\ifexsh@solutions
@@ -438,16 +441,24 @@
\ifstrequal{#1}{\begin}{\exsh@skipsheet@begin}{%
\ifstrequal{#1}{\end}{\exsh@skipsheet@end}{%
\ifstrequal{#1}{\label}{\exsh@skipsheet@label}{%
- \ifstrequal{#1}{\setcounter}{\expandafter\exsh@skipsheet\setcounter}{%
- \ifstrequal{#1}{\item}{\ifdef{\@enumctr}{\@hyper@itemtrue\refstepcounter{\@enumctr}}{}}{}%
- \exsh@skipsheet}}}}%
+ \ifstrequal{#1}{\input}{\exsh@skipsheet@input}{%
+ \ifstrequal{#1}{\exsh@skipsheet@endfile}{\currfile@pop\exsh@skipsheet}{%
+ \ifstrequal{#1}{\setcounter}{\expandafter\exsh@skipsheet\setcounter}{%
+ \ifstrequal{#1}{\item}{\ifdef{\@enumctr}{\@hyper@itemtrue\refstepcounter{\@enumctr}}{}}{}%
+ \exsh@skipsheet}}}}}}%
}
\def\exsh@skipsheet@end#1{%
\ifstrequal{#1}{sheet}{\end{sheet}}{\endgroup\exsh@skipsheet}%
}
\def\exsh@skipsheet@begin#1{%
\begingroup
- \ifstrequal{#1}{exercise}{\refstepcounter{section}}{}%
+ \ifstrequal{#1}{exercise}{\refstepcounter{section}%
+ % automatic label for the first exercise in every included file
+ \ifthenelse{\equal{\jobname}{\currfilebase}}{}{%
+ \ifcsdef{exsh@autolabel@\currfilebase}{}{%
+ \csdef{exsh@autolabel@\currfilebase}{}%
+ \label{ex:\currfilebase}}}%
+ }{}%
\ifinlist{#1}{\exsh@enums}{%
\exsh@skipsheet@beginenum
}{%
@@ -474,6 +485,12 @@
\def\exsh@skipsheet@label#1{%
\label{#1}\exsh@skipsheet
}
+\def\exsh@skipsheet@input#1{%
+ \CatchFileDef{\exsh@inputfilecontent}{#1}{}%
+ \currfile@push
+ \currfile@set{#1}%
+ \expandafter\exsh@skipsheet\exsh@inputfilecontent\exsh@skipsheet@endfile
+}
\def\exsh@sheethead{%
\pgfkeysgetvalue{/exsh/title}{\exsh@tmp}%
@@ -600,6 +617,11 @@
\pgfkeysvalueof{/exsh/strings/exercise}~\arabic{section}\exsh@exname\exsh@firstline\expandonce\exsh@points}%
\unskip\vskip\pgfkeysvalueof{/exsh/below exercise title skip}\relax
\@afterindentfalse
+ % automatic label for the first exercise in every included file
+ \ifthenelse{\equal{\jobname}{\currfilebase}}{}{%
+ \ifcsdef{exsh@autolabel@\currfilebase}{}{%
+ \csdef{exsh@autolabel@\currfilebase}{}%
+ \label{ex:\currfilebase}}}%
% Use \leavevmode to ensure proper distances above environments that start
% with a new \par. Make sure that a \label does not mess up the layout.
\@ifnextchar\label{\exsh@label}{\leavevmode\ignorespaces}%