From de50d575e7a6f6d766e486c12f063e00219b03e9 Mon Sep 17 00:00:00 2001
From: Sebastian Kuhnert
Date: Mon, 11 Dec 2017 11:33:06 +0100
Subject: fix labels in skipped sheets after the last printed sheet; fix
 incomplete \ifx errors

---
 exercisesheets.sty | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

(limited to 'exercisesheets.sty')

diff --git a/exercisesheets.sty b/exercisesheets.sty
index a016940..33ce1f1 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.5j}
-\def\exsh@date{2017/04/27}
+\def\exsh@version{0.5k}
+\def\exsh@date{2017/12/11}
 
 \ProvidesPackage{exercisesheets}[\exsh@date\space\exsh@version\space Typesetting of exercise sheets]
 \message{`Typesetting of exercise sheets' \exsh@version\space <\exsh@date>}
@@ -503,14 +503,25 @@
     \edef\@enumctr{enum\romannumeral\the\@enumdepth}%
     \setcounter{\@enumctr}{0}%
   \fi
-  \ifx\@enumlabel@\relax
+  \@ifundefined{@enumlabel@}{%
     \exsh@skipsheet
-  \else
+  }{%
     \@ifnextchar[{\@enumlabel@{\exsh@skipsheet}[}{\exsh@skipsheet}%
-  \fi
+  }%
 }
 \def\exsh@skipsheet@label#1{%
-  \label{#1}\exsh@skipsheet
+  % Locally modify \protected@write to use \immediate\write instead.
+  % This is needed to include labels after the last shipout in the aux file.
+  \begingroup
+  \def\protected@write##1##2##3{%
+    \begingroup
+    \let\protect\@unexpandable@protect
+    \immediate\write##1{##3}%
+    \endgroup
+  }%
+  \label{#1}%
+  \endgroup
+  \exsh@skipsheet
 }
 \def\exsh@skipsheet@input#1{%
   \CatchFileDef{\exsh@inputfilecontent}{#1}{}%
-- 
cgit v1.2.3

