From cdbf5b2c845ca6b373fff9043f2e00b14807950a Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Sun, 25 Sep 2016 21:05:03 +0000
Subject: ctex

git-svn-id: svn://tug.org/texlive/trunk@42148 c570f23f-e606-0410-a88d-b1316a301751
---
 Master/texmf-dist/tex/latex/ctex/ctex-book.def | 184 +++++++++++++++++++------
 1 file changed, 141 insertions(+), 43 deletions(-)

(limited to 'Master/texmf-dist/tex/latex/ctex/ctex-book.def')

diff --git a/Master/texmf-dist/tex/latex/ctex/ctex-book.def b/Master/texmf-dist/tex/latex/ctex/ctex-book.def
index 7a2400e2e55..86392ce643d 100644
--- a/Master/texmf-dist/tex/latex/ctex/ctex-book.def
+++ b/Master/texmf-dist/tex/latex/ctex/ctex-book.def
@@ -26,10 +26,10 @@
 %% 
 %% ------------------------------------------------------------------------------
 %% 
-\GetIdInfo$Id: ctex.dtx e653f84 2016-08-27 11:05:06 +0800 Qing Lee <sobenlee@gmail.com> $
+\GetIdInfo$Id: ctex.dtx b7f83de 2016-09-21 21:27:31 +0800 Qing Lee <sobenlee@gmail.com> $
   {Heading modification for book (CTEX)}
 \ProvidesExplFile{ctex-book.def}
-  {\ExplFileDate}{2.4.3}{\ExplFileDescription}
+  {\ExplFileDate}{2.4.4}{\ExplFileDescription}
 \seq_new:N \c__ctex_section_headings_seq
 \seq_gset_from_clist:Nn \c__ctex_section_headings_seq
   { section , subsection , subsubsection , paragraph , subparagraph }
@@ -88,6 +88,9 @@
         #1 / afterindent .bool_set:N = \exp_not:c { CTEX@#1@afterindent } ,
         #1 / fixskip     .bool_set:N = \exp_not:c { CTEX@#1@fixskip } ,
         #1 / runin       .bool_set:N = \exp_not:c { CTEX@#1@runin } ,
+        #1 / break         .tl_set:N = \exp_not:c { CTEX@#1@break } ,
+        #1 / break+          .code:n =
+          { \tl_put_right:Nn \exp_not:c { CTEX@#1@break } { ####1 } } ,
         #1 / format+         .code:n =
           { \tl_put_right:Nn \exp_not:c { CTEX@#1@format } { ####1 } } ,
         #1 / nameformat+     .code:n =
@@ -135,9 +138,6 @@
     \group_end:
     \keys_define:nn { ctex } { \exp_not:o { \l__ctex_tmp_tl } }
   }
-\cs_new_protected_nopar:Npn \CTEX@makeheadinganchor { }
-\ctex_at_end_package:nn { hyperref }
-  { \cs_gset_protected_nopar:Npn \CTEX@makeheadinganchor { \phantomsection } }
 \cs_new_protected_nopar:Npn \CTEX@fixtopskip
   {
     \CTEX@fixheadingskip
@@ -154,12 +154,15 @@
 \cs_new_protected_nopar:Npn \CTEX@setheadingskip
   { \skip_set:Nn \l__ctex_heading_skip }
 \cs_new_eq:NN \CTEX@headingskip \l__ctex_heading_skip
+\ProvideDocumentCommand \partmark { m }
+  { \markboth { } { } }
+\cs_new_eq:NN \CTEXifname \use_i:nn
+\cs_new_protected_nopar:Npn \CTEX@ifnametrue
+  { \cs_set_eq:NN \CTEXifname \use_i:nn }
+\cs_new_protected_nopar:Npn \CTEX@ifnamefalse
+  { \cs_set_eq:NN \CTEXifname \use_ii:nn }
 \renewcommand\part{%
-  \if@openright
-    \cleardoublepage
-  \else
-    \clearpage
-  \fi
+  \CTEX@part@break
   \thispagestyle{\CTEX@part@pagestyle}%
   \if@twocolumn
     \onecolumn
@@ -174,16 +177,20 @@
 \def\@part[#1]#2{%
   \ifnum \c@secnumdepth >-2\relax
     \ifodd \CTEX@part@numbering
+      \CTEX@ifnametrue
       \refstepcounter{part}%
       \addcontentsline{toc}{part}{\CTEXthepart\hspace{1em}#1}%
     \else
-      \CTEX@makeheadinganchor
+      \CTEX@ifnamefalse
+      \CTEX@makeanchor{part*}%
       \addcontentsline{toc}{part}{#1}%
     \fi
   \else
+    \CTEX@ifnamefalse
+    \CTEX@makeanchor@part{part*}%
     \addcontentsline{toc}{part}{#1}%
   \fi
-  \markboth{}{}%
+   \partmark{#1}%
   {\interlinepenalty \@M
    \normalfont \CTEX@part@format
    \ifnum \c@secnumdepth >-2\relax \ifodd \CTEX@part@numbering
@@ -193,6 +200,8 @@
    \CTEX@part@aftertitle}%
   \@endpart}
 \def\@spart#1{%
+    \CTEX@ifnamefalse
+    \CTEX@makeanchor@spart{part*}%
     {\interlinepenalty \@M
      \normalfont \CTEX@part@format
      \CTEX@part@titleformat{#1}%
@@ -213,7 +222,8 @@
               \if@tempswa
                 \twocolumn
               \fi}
-\renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
+\renewcommand\chapter{%
+                    \CTEX@chapter@break
                     \thispagestyle{\CTEX@chapter@pagestyle}%
                     \global\@topnum\z@
                     \ifodd \CTEX@chapter@afterindent
@@ -226,18 +236,24 @@
   \ifnum \c@secnumdepth >\m@ne
     \if@mainmatter
       \ifodd \CTEX@chapter@numbering
+        \CTEX@ifnametrue
         \refstepcounter{chapter}%
         \typeout{\CTEXthechapter}%
         \addcontentsline{toc}{chapter}
           {\protect\numberline{\CTEXthechapter\hspace{0.3em}}#1}%
       \else
-        \CTEX@makeheadinganchor
+        \CTEX@ifnamefalse
+        \CTEX@makeanchor{\Hy@chapapp*}%
         \addcontentsline{toc}{chapter}{#1}%
       \fi
     \else
+      \CTEX@ifnamefalse
+      \CTEX@makeanchor@chapter{\Hy@chapapp*}%
       \addcontentsline{toc}{chapter}{#1}%
     \fi
   \else
+    \CTEX@ifnamefalse
+    \CTEX@makeanchor@chapter{\Hy@chapapp*}%
     \addcontentsline{toc}{chapter}{#1}%
   \fi
   \chaptermark{#1}%
@@ -249,19 +265,22 @@
     \@makechapterhead{#2}%
   \@afterheading
   \fi}
+\def\@schapter#1{%
+  \CTEX@ifnamefalse
+  \CTEX@makeanchor@schapter{\Hy@chapapp*}%
+  \if@twocolumn
+    \@topnewpage[\@makeschapterhead{#1}]%
+  \else
+    \@makeschapterhead{#1}%
+    \@afterheading
+  \fi}
 \def\@makechapterhead#1{%
   \CTEX@setheadingskip \CTEX@chapter@beforeskip
   \ifodd \CTEX@chapter@fixskip \CTEX@fixtopskip \fi
   \vspace*{\CTEX@headingskip}%
   {\normalfont \parindent \dimexpr \CTEX@chapter@indent \relax
    \CTEX@chapter@format
-   \ifnum \c@secnumdepth >\m@ne
-     \if@mainmatter
-       \ifodd \CTEX@chapter@numbering
-         \CTEX@chaptername \CTEX@chapter@aftername
-       \fi
-     \fi
-   \fi
+   \CTEXifname{\CTEX@chaptername\CTEX@chapter@aftername}{}%
    \interlinepenalty\@M
    \CTEX@chapter@titleformat{#1}%
    \CTEX@chapter@aftertitle
@@ -296,25 +315,30 @@
   \if@nobreak
     \everypar{}%
   \else
-    \addpenalty\@secpenalty
+    \csname CTEX@#1@break\endcsname
     \CTEX@setheadingskip{#4}%
     \ifodd \CTEX@fixskip \CTEX@fixheadingskip \fi
     \addvspace \CTEX@headingskip
   \fi
   \@ifstar
-    {\@ssect{#3}{#4}{#5}{#6}}%
+    {\CTEX@makeanchor@ssect{#1*}\@ssect{#3}{#4}{#5}{#6}}%
     {\@dblarg{\@sect{#1}{#2}{#3}{#4}{#5}{#6}}}}
 \def\@seccntformat#1{%
-  \csname CTEX@#1name\endcsname \csname CTEX@#1@aftername\endcsname}
+  \csname CTEX@#1name\endcsname
+  \csname CTEX@#1@aftername\endcsname}
 \def\@sect#1#2#3#4#5#6[#7]#8{%
   \ifnum #2>\c@secnumdepth
+    \CTEX@ifnamefalse
+    \CTEX@makeanchor@sect{#1*}%
     \let\@svsec\@empty
   \else
     \ifodd \csname CTEX@#1@numbering\endcsname
+      \CTEX@ifnametrue
       \refstepcounter{#1}%
       \protected@edef\@svsec{\@seccntformat{#1}\relax}%
     \else
-      \CTEX@makeheadinganchor
+      \CTEX@ifnamefalse
+      \CTEX@makeanchor{#1*}%
       \let\@svsec\@empty
     \fi
   \fi
@@ -328,11 +352,7 @@
     \endgroup
     \csname #1mark\endcsname{#7}%
     \addcontentsline{toc}{#1}{%
-      \ifnum #2>\c@secnumdepth \else
-        \ifodd \csname CTEX@#1@numbering\endcsname
-          \protect\numberline{\csname CTEXthe#1\endcsname}%
-        \fi
-      \fi
+      \CTEXifname{\protect\numberline{\csname CTEXthe#1\endcsname}}{}%
       #7}%
   \else
     \def\@svsechd{%
@@ -342,15 +362,12 @@
       \csname CTEX@#1@aftertitle\endcsname}%
     \csname #1mark\endcsname{#7}%
     \addcontentsline{toc}{#1}{%
-      \ifnum #2>\c@secnumdepth \else
-        \ifodd \csname CTEX@#1@numbering\endcsname
-          \protect\numberline{\csname CTEXthe#1\endcsname}%
-        \fi
-      \fi
+      \CTEXifname{\protect\numberline{\csname CTEXthe#1\endcsname}}{}%
       #7}}%
   \fi
   \@xsect{#5}}
 \def\@ssect#1#2#3#4#5{%
+  \CTEX@ifnamefalse
   \unless \ifodd \CTEX@runin
     \begingroup
       #4{%
@@ -435,6 +452,48 @@
     \gdef \CTEX@postchapter { \CTEX@postappendix }
     \gdef \CTEX@chapter@numbering { \CTEX@appendix@numbering }
   }
+\cs_new_protected_nopar:Npn \CTEX@makeanchor #1
+  { }
+\seq_new:N \c__ctex_headings_cs_seq
+\seq_gset_from_clist:Nn \c__ctex_headings_cs_seq
+  { part , spart , chapter , schapter , sect , ssect }
+\seq_map_inline:Nn \c__ctex_headings_cs_seq
+  {
+    \cs_new_eq:cc { CTEX@ #1 } { @ #1 }
+    \cs_new_eq:cN { CTEX@makeanchor@ #1 } \CTEX@makeanchor
+  }
+\cs_new_protected_nopar:Npn \CTEX@hyperheadinghook
+  {
+    \group_begin:
+      \ifHy@implicit
+        \cs_set_eq:NN \H@old@chapter \Hy@org@chapter
+        \seq_map_inline:Nn \c__ctex_headings_cs_seq
+          {
+            \cs_if_eq:ccT { H@old@ ##1 } { CTEX@ ##1 }
+              {
+                \cs_gset_eq:cc { @ ##1 } { CTEX@ ##1 }
+                \cs_gset_eq:cN { CTEX@makeanchor@ ##1 } \CTEX@makeanchor
+              }
+          }
+      \else:
+        \seq_map_inline:Nn \c__ctex_headings_cs_seq
+          { \cs_gset_eq:cN { CTEX@makeanchor@ ##1 } \CTEX@makeanchor }
+      \fi:
+    \group_end:
+  }
+\ctex_at_end_package:nn { hyperref }
+  {
+    \cs_gset_protected_nopar:Npn \CTEX@makeanchor #1
+      {
+        \Hy@MakeCurrentHrefAuto {#1}
+        \Hy@raisedlink
+          {
+            \hyper@anchorstart { \@currentHref }
+            \hyper@anchorend
+          }
+      }
+    \CTEX@hyperheadinghook
+  }
 \cs_new_protected_nopar:Npn \ctex_titlesec_hook:
   {
     \@ifpackagewith { titlesec } { explicit }
@@ -502,6 +561,29 @@
           { \ctex_titlesec_hook: }
       }
   }
+\ctex_at_end_package:nn { titlesec }
+  {
+    \tl_set:Nn \ttl@chapterout { \typeout { \CTEXthechapter } }
+    \cs_if_free:NF \ttl@tocpart
+      {
+        \cs_set_protected_nopar:Npn \ttl@tocpart
+          { \tl_set:Nn \ttl@a { \CTEXthepart \hspace { 1em } } }
+      }
+    \seq_map_inline:Nn \c__ctex_headings_seq
+      {
+        \cs_if_exist:cF { ttl@toc #1 }
+          {
+            \cs_new_protected_nopar:cpx { ttl@toc #1 }
+              {
+                \tl_set:Nn \exp_not:N \ttl@a
+                  {
+                    \exp_not:N \protect
+                    \exp_not:N \numberline { \exp_not:c { CTEXthe #1 } }
+                  }
+              }
+          }
+      }
+  }
 \group_begin:
 \char_set_catcode_other:N \#
 \cs_new_protected_nopar:Npn \ctex_titleps_hook:
@@ -539,6 +621,18 @@
 \ctex_at_end_package:nn { titlesec }
   { \cs_if_free:NF \ttl@settopmark { \ctex_titleps_hook: } }
 \ctex_at_end_package:nn { titleps } { \ctex_titleps_hook: }
+\ctex_at_end_package:nn { titleps }
+  {
+    \cs_set_protected_nopar:Npn \ttl@setifthe #1
+      {
+        \exp_args:Nco \cs_set_nopar:Npn { ifthe #1 }
+          {
+            \CTEXifname
+              { \protect \@firstoftwo }
+              { \protect \@secondoftwo }
+          }
+      }
+  }
 \cs_new_protected:Npn \CTEX@toc@width@n #1
   {
     \hbox_set:Nn \l__ctex_tmp_box {#1}
@@ -571,21 +665,25 @@
       }
   }
 \ctex_patch_cmd:Nnn \ps@headings
-  { \@chapapp\ \thechapter.~\ }
-  { \ifodd \CTEX@chapter@numbering \CTEXthechapter \quad \fi }
+  {
+    \ifnum \c@secnumdepth > \m@ne \if@mainmatter
+      \@chapapp \ \thechapter . ~ \
+    \fi \fi
+  }
+  { \CTEXifname { \CTEXthechapter \quad } { } }
 \if@twoside
   \ctex_patch_cmd:Nnn \ps@headings
-    { \thesection.~\ }
-    { \ifodd \CTEX@section@numbering \CTEXthesection \quad \fi }
+    { \ifnum \c@secnumdepth > \z@ \thesection . ~ \ \fi }
+    { \CTEXifname { \CTEXthesection } { } }
 \fi:
 \ctex_at_end_package:nn { fancyhdr }
   {
     \ctex_patch_cmd:Nnn \ps@fancy
-      { \@chapapp\ \thechapter.~\ }
-      { \if@mainmatter \ifodd \CTEX@chapter@numbering \CTEXthechapter \quad \fi \fi }
+      { \ifnum \c@secnumdepth > \m@ne \@chapapp \ \thechapter . ~ \ \fi }
+      { \CTEXifname { \CTEXthechapter \quad } { } }
     \ctex_patch_cmd:Nnn \ps@fancy
-      { \thesection.~\ }
-      { \ifodd \CTEX@section@numbering \CTEXthesection \quad \fi }
+      { \ifnum \c@secnumdepth > \z@ \thesection . ~ \ \fi }
+      { \CTEXifname { \CTEXthesection } { } }
   }
 \cs_new_protected_nopar:Npn \CTEX@setcurrentlabel@n #1
   {
-- 
cgit v1.2.3

