[tex4ht-commits] [SCM] tex4ht updated: r964 - trunk/lit

Michal Hoftich INVALID.NOREPLY at gnu.org.ua
Wed Jun 30 13:14:18 CEST 2021


Author: michal_h21
Date: 2021-06-30 11:14:18 +0000 (Wed, 30 Jun 2021)
New Revision: 964

Modified:
   trunk/lit/ChangeLog
   trunk/lit/tex4ht-4ht.tex
Log:
Fixed cleveref support for \refstepcounter and amsthm theorems

Modified: trunk/lit/ChangeLog
===================================================================
--- trunk/lit/ChangeLog	2021-06-27 15:11:41 UTC (rev 963)
+++ trunk/lit/ChangeLog	2021-06-30 11:14:18 UTC (rev 964)
@@ -1,3 +1,9 @@
+2021-06-30  Michal Hoftich  <michal.h21 at gmail.com>
+
+	* tex4ht-4ht.tex (cleveref-hooks.4ht, cleveref.4ht): fixed support for
+	\refstepcounter and amsthm theorems.
+	https://tex.stackexchange.com/a/603194/2891
+
 2021-06-27  Karl Berry  <karl at freefriends.org>
 
 	* tex4ht-4ht.tex (mwbk.4ht, natbib.4ht, report.4ht,

Modified: trunk/lit/tex4ht-4ht.tex
===================================================================
--- trunk/lit/tex4ht-4ht.tex	2021-06-27 15:11:41 UTC (rev 963)
+++ trunk/lit/tex4ht-4ht.tex	2021-06-30 11:14:18 UTC (rev 964)
@@ -3394,14 +3394,37 @@
 %%%%%%%%%%%%%%%%%%
 \Section{cleveref}
 
-This is basic support for the cleveref package. 
-\Link[https://tex.stackexchange.com/a/220345/2891]{}{}Source.\EndLink
 
 \<cleveref.4ht\><<<
 % cleveref.4ht (|version), generated from |jobname.tex
-% Copyright 2018-2019 TeX Users Group
+% Copyright 2018-2021 TeX Users Group
 |<TeX4ht license text|>
 
+|<cleveref refstepcounter|>
+|<cleveref links|>
+|<cleveref amsthm|>
+
+\Hinput{cleveref}
+
+\endinput
+>>> \AddFile{8}{cleveref}
+
+This is basic support for the cleveref package. 
+\Link[https://tex.stackexchange.com/a/220345/2891]{}{}Source.\EndLink
+
+\<cleveref refstepcounter\><<<
+
+% orig:refstepcounter is saved in cleveref-hooks.4ht
+\let\cref at old@refstepcounter\orig:refstepcounter%
+\def\refstepcounter{%
+  \@ifnextchar[{\refstepcounter at optarg}{\refstepcounter at noarg}%]
+}%
+
+% fix for TeX4ht label mechanism
+\def\cref:currentlabel#1{|<def :currentlabel for refstepcounter|>%
+  \anc:lbl r{#1}%
+}
+
 \def\refstepcounter at noarg#1{%
   \cref at old@refstepcounter{#1}%
   \cref at constructprefix{#1}{\cref at result}%
@@ -3411,6 +3434,7 @@
   \protected at xdef\cref at currentlabel{%
     [\@tempa][\arabic{#1}][\cref at result]%
     \csname p@#1\endcsname\csname the#1\endcsname}
+    \cref:currentlabel{#1}%
     }%
 \def\refstepcounter at optarg[#1]#2{%
   \cref at old@refstepcounter{#2}%
@@ -3418,16 +3442,13 @@
   \@ifundefined{cref@#1 at alias}%
     {\def\@tempa{#1}}%
     {\def\@tempa{\csname cref@#1 at alias\endcsname}}%
-  \protected at edef\cref at currentlabel{%
+  \protected at xdef\cref at currentlabel{%
     [\@tempa][\arabic{#2}][\cref at result]%
-    \csname p@#2\endcsname\csname the#2\endcsname}}%
-\Hinput{cleveref}
+    \csname p@#2\endcsname\csname the#2\endcsname}
+    \cref:currentlabel{#2}%
+  }%
+>>>
 
-|<cleveref links|>
-\endinput
->>> \AddFile{8}{cleveref}
-
-
 Support for links from the \Verb|\cref| command. 
 \Link[https://tex.stackexchange.com/a/475664/2891]{}{}More information.\EndLink
 
@@ -3445,7 +3466,25 @@
 \HLet\@@@setcref=\:tempa
 >>>
 
+Fixes for the amsthm cleveref redefinitions.
+\Link[https://tex.stackexchange.com/q/491933/2891]{}{}More information.\EndLink
 
+\<cleveref amsthm\><<<
+\@ifpackageloaded{amsthm}{
+  \let\cref at thmnoarg\@thm%
+  \def\@thm{\@ifnextchar[{\cref at thmoptarg}{\cref at thmnoarg}}%]
+  \def\:tempb[#1]#2#3#4{%
+   % call original amsthm theorem definition, but
+   % disable \:thm in order to prevent infinite loop
+   \let\:thm\:gobble
+   \cref at thmnoarg{#2}%
+   \o:cref at thmoptarg:[#1]{#2}{#3}{#4}
+  }%
+  \HLet\cref at thmoptarg\:tempb
+}{}%
+>>>
+
+
 Cleveref depends on internal Hyperref macro when Hyperref is loaded. It causes crash,
 because Hyperref exits before this macro is defined.
 \Link[https://tex.stackexchange.com/a/540277/2891]{}{}More information\EndLink.
@@ -3456,9 +3495,14 @@
 
 \<cleveref-hooks.4ht\><<<
 % cleveref-hooks.4ht (|version), generated from |jobname.tex
-% Copyright 2020 TeX Users Group
+% Copyright 2020-2021 TeX Users Group
 |<TeX4ht license text|>
 \let\HyOrg at addtoreset\@addtoreset
+% fixes for \refstepcounter
+\let\orig:refstepcounter\refstepcounter
+\:AtEndOfPackage{%
+\let\refstepcounter\orig:refstepcounter
+}
 >>> \AddFile{9}{cleveref-hooks}
 
 %%%%%%%%%%%%%%%%%%



More information about the tex4ht-commits mailing list.