From 7129360f731039335dc8ef6af12c365d4ac6ea75 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sun, 27 Feb 2022 21:32:23 +0000 Subject: crefthe (27feb22) (branch) git-svn-id: svn://tug.org/texlive/branches/branch2021.final@62247 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/doc/latex/crefthe/crefthe-doc.pdf | Bin 112174 -> 115616 bytes .../texmf-dist/doc/latex/crefthe/crefthe-doc.tex | 21 ++++-- Master/texmf-dist/tex/latex/crefthe/crefthe.sty | 80 +++++++++++++++------ 3 files changed, 75 insertions(+), 26 deletions(-) (limited to 'Master') diff --git a/Master/texmf-dist/doc/latex/crefthe/crefthe-doc.pdf b/Master/texmf-dist/doc/latex/crefthe/crefthe-doc.pdf index 4e1a55b9d58..7f4f6ea5e02 100644 Binary files a/Master/texmf-dist/doc/latex/crefthe/crefthe-doc.pdf and b/Master/texmf-dist/doc/latex/crefthe/crefthe-doc.pdf differ diff --git a/Master/texmf-dist/doc/latex/crefthe/crefthe-doc.tex b/Master/texmf-dist/doc/latex/crefthe/crefthe-doc.tex index 04051d0f60a..70cdc89d92d 100644 --- a/Master/texmf-dist/doc/latex/crefthe/crefthe-doc.tex +++ b/Master/texmf-dist/doc/latex/crefthe/crefthe-doc.tex @@ -77,19 +77,23 @@ \newenvironment{demo}{% \LocallyStopLineNumbers% \begin{tcolorbox}[enhanced jigsaw,pad at break*=1mm,breakable, - left=4mm,right=4mm,top=0.5mm,bottom=0mm, + left=2.5mm,right=3mm,top=0.5mm,bottom=0mm, colback=gray!5!paper,boxrule=0pt,frame hidden, - borderline west={1.5mm}{0mm}{gray!55!paper},arc=.7mm]% + borderline west={1.2mm}{0mm}{gray!55!paper},arc=.7mm]% }{\end{tcolorbox}\ResumeLineNumbers} +\newcommand{\packageoption}[1]{\texttt{\textcolor{black!67!green}{#1}}} +\newcommand{\commandoption}[1]{\texttt{\textcolor{black!67!cyan}{#1}}} + + \newcommand{\crefthepackage}{\textsf{crefthe}} \begin{document} -\title{\crefthepackage{} - cross referencing with proper definite articles} +\title{\crefthepackage{}\\\smallskip\itshape Cross referencing with proper definite articles} \author{Jinwen XU} -\thanks{Corresponding to: \texttt{\crefthepackage{} 2022/02/20}} +\thanks{Corresponding to: \texttt{\crefthepackage{} 2022/02/27}} \date{February 2022, in Paris} \maketitle @@ -231,7 +235,7 @@ To place hyperlinks at the right place, \lstinline|\crefthename| touches the cor \crefthepackage{} loads \textsf{cleveref} automatically and pass all the options to it. All its commands, used without optional arguments, degenerate to those in \textsf{cleveref}. For example, \lstinline|\crefthe{...}| is the same as \lstinline|\cref{...}|, and \lstinline|\crefthename| is the same as \lstinline|\crefname| if the definite articles are not specified. That said, you can safely use the command \lstinline|\crefthe| everywhere in your document without causing extra trouble. -With the option \texttt{overwrite}, user commands in \textsf{cleveref} will be replaced by those offered here, thus you can simply write \lstinline|\cref| for \lstinline|\crefthe| -- and similarly with \lstinline|\Cref|, \lstinline|\crefname| and \lstinline|\Crefname|. +With the package option \packageoption{overwrite}, user commands in \textsf{cleveref} will be replaced by those offered here, thus you can simply write \lstinline|\cref| for \lstinline|\crefthe| -- and similarly with \lstinline|\Cref|, \lstinline|\crefname| and \lstinline|\Crefname|. \section{Known issues} @@ -241,5 +245,12 @@ With the option \texttt{overwrite}, user commands in \textsf{cleveref} will be r \item The names of theorem-like environments are not provided here, you need to define them by yourself. However, users are encouraged to use the \ProjLib{} toolkit (more specifically, the internal package \textsf{create-theorem}), which already handles everything for you. \end{itemize} +\medskip +If you run into any issues or have ideas for improvement, feel free to discuss on: +\begin{center} + \url{https://github.com/Jinwen-XU/crefthe/issues} +\end{center} +or email me via \href{mailto:ProjLib@outlook.com}{\texttt{ProjLib@outlook.com}}. + \end{document} diff --git a/Master/texmf-dist/tex/latex/crefthe/crefthe.sty b/Master/texmf-dist/tex/latex/crefthe/crefthe.sty index 7edf7e1788d..213f3d2e609 100644 --- a/Master/texmf-dist/tex/latex/crefthe/crefthe.sty +++ b/Master/texmf-dist/tex/latex/crefthe/crefthe.sty @@ -13,7 +13,7 @@ \RequirePackage{l3keys2e} \ProvidesExplPackage {crefthe} - {2022/02/20} {} + {2022/02/27} {} {Cross referencing with proper definite articles} \keys_define:nn { crefthe } @@ -26,6 +26,7 @@ \ProcessKeysOptions { crefthe } \RequirePackage { cleveref } +\RequirePackage { regexpatch } \NewCommandCopy \crefthe_cref_original:w \cref \NewCommandCopy \crefthe_Cref_original:w \Cref @@ -41,20 +42,28 @@ \tl_new:N \l__crefthe_prep_once_tl \tl_new:N \l__crefthe_prep_each_tl -\bool_new:N \l__crefthe_uppercase_bool +\bool_new:N \g__crefthe_uppercase_bool +\bool_new:N \g__crefthe_has_prep_bool \NewDocumentCommand \crefthe { s t- t+ O{} m } { - \bool_set_false:N \l__crefthe_uppercase_bool + \bool_gset_false:N \g__crefthe_uppercase_bool \__crefthe_cref_general:NNNnnN #1 #2 #3 { #4 } { #5 } \crefthe_cref_original:w } \NewDocumentCommand \Crefthe { s t- t+ O{} m } { - \bool_set_true:N \l__crefthe_uppercase_bool + \bool_gset_true:N \g__crefthe_uppercase_bool \__crefthe_cref_general:NNNnnN #1 #2 #3 { #4 } { #5 } \crefthe_Cref_original:w } -\cs_new_protected:Npn \__crefthe_cref_general:NNNnnN #1 #2 #3 #4 #5 #6 +\cs_new_protected:Nn \__crefthe_cref_general:NNNnnN { + \tl_if_blank:eTF #4 + { + \bool_gset_false:N \g__crefthe_has_prep_bool + } + { + \bool_gset_true:N \g__crefthe_has_prep_bool + } \bool_if:NTF #2 { \tl_set:Nn \l__crefthe_prep_once_tl { #4 } } { @@ -78,7 +87,7 @@ } % \__crefthe_prep_mode: defines the default mode for supported languages -\cs_new:Npn \__crefthe_prep_mode: +\cs_new:Nn \__crefthe_prep_mode: { \str_case:Vn \languagename { @@ -94,51 +103,80 @@ { \__crefthe_name_general:nnnnnn { #1 } { #2 } { #3 } { #4 } { #5 } { c } } + \NewDocumentCommand \Crefthename { m O{} m O{} m } { \__crefthe_name_general:nnnnnn { #1 } { #2 } { #3 } { #4 } { #5 } { C } } -\cs_new_protected:Npn \__crefthe_name_general:nnnnnn #1 #2 #3 #4 #5 #6 + +\cs_new_protected:Nn \__crefthe_name_general:nnnnnn { % #6 is c or C \tl_if_blank:nTF { #2 } { - \cs:w crefthe_#6refname_original:w \cs_end: { #1 } { #3 } { #5 } - \cs_set:cn { #6ref_#1_format:nnn } { ##2 #3 ~ ##1 ##3 } - \cs_set:cn { #6ref_#1_format_first:nnn } { ##2 #5 ~ ##1 ##3 } + \__crefthe_name_general_do:nnnnnn { #1 } {} { #3 } {} { #5 } { #6 } } { - \cs:w crefthe_#6refname_original:w \cs_end: { #1 } { \crefthemark { #2 } #3 } { \crefthemark { #4 } #5 } - \cs_set:cn { #6ref_#1_format:nnn } { \crefthemark { #2 } ##2 #3 ~ ##1 ##3 } - \cs_set:cn { #6ref_#1_format_first:nnn } { \crefthemark { #4 } ##2 #5 ~ ##1 ##3 } + \__crefthe_name_general_do:nnnnnn { #1 } { \crefthemark { #2 } } { #3 } { \crefthemark { #4 } } { #5 } { #6 } } + } + +\cs_new_protected:Nn \__crefthe_name_general_do:nnnnnn + { + \use:c { crefthe_#6refname_original:w } { #1 } { #2 #3 } { #4 #5 } \hook_gput_code:nnn { begindocument } { crefthe } { - \cs_set_eq:cc { #6ref@ #1 @format } { #6ref_#1_format:nnn } - \cs_set_eq:cc { #6ref@ #1 @format@first } { #6ref_#1_format_first:nnn } + \crefthe_patch_format:nnnnn { 2 } { #6ref@#1@format } { #6ref@#1@name } { #2 } { #3 } + \crefthe_patch_format:nnnnn { 2 } { #6ref@#1@format@first } { #6ref@#1@name@plural } { #4 } { #5 } + \crefthe_patch_format:nnnnn { 3 } { #6refrange@#1@format } { #6ref@#1@name@plural } { #4 } { #5 } + \crefthe_patch_format:nnnnn { 3 } { #6refrange@#1@format@first } { #6ref@#1@name@plural } { #4 } { #5 } + } + } + +\seq_new:N \g__crefthe_already_patched_seq + +\cs_new_protected:Nn \crefthe_patch_format:nnnnn + % #1 = the # number for the beginning mark of hyperlink + % #2 = name of the format command + % #3 = name of the command after hyperlink mark + % #4 = new content before the mark + % #5 = new content after the mark + { + \seq_if_in:NnF \g__crefthe_already_patched_seq { #2 - #3 } + { + \makeatletter + \tl_set:Nn \l_tmpa_tl { #4 } + \tl_set:Nn \l_tmpb_tl { #5 } + \exp_args:Nc \regexpatchcmd { #2 } + { \cP. #1 \c{ #3 } } + { \u{l_tmpa_tl} \cP\# #1 \u{l_tmpb_tl} } + { } { \PatchFailed } + \makeatother + \seq_gput_right:Nn \g__crefthe_already_patched_seq { #2 - #3 } } } + \cs_generate_variant:Nn \text_lowercase:n { V } \NewDocumentCommand \crefthemark { m } { \crefthe_contraction:Ve \l__crefthe_prep_each_tl { \crefthe_contraction:Vn \l__crefthe_prep_once_tl { #1 } } \tl_gclear:N \l__crefthe_prep_once_tl - \tl_set:Nx \l__crefthe_prep_each_tl + \tl_gset:Nx \l__crefthe_prep_each_tl { \text_lowercase:V \l__crefthe_prep_each_tl } \str_if_eq:eeF { \str_tail:n { #1 } } { ' } { ~ } - \bool_set_false:N \l__crefthe_uppercase_bool + \bool_gset_false:N \g__crefthe_uppercase_bool } \prg_generate_conditional_variant:Nnn \str_case_e:nn { nv } { T, F, TF } -\cs_new:Npn \crefthe_contraction:nn #1#2 +\cs_new:Nn \crefthe_contraction:nn { \exp_args:Ne \__crefthe_contraction:nnn { \text_lowercase:n { #2 } } { #1 } { #2 } } \cs_generate_variant:Nn \crefthe_contraction:nn { V, Ve } -\cs_new:Npn \__crefthe_contraction:nnn #1 #2 #3 +\cs_new:Nn \__crefthe_contraction:nnn { % #1 is \text_lowercase:n { #3 } % #2 is the preposition @@ -157,9 +195,9 @@ { #2~#3 } } } -\cs_new:Npn \__crefthe_conditional_uppercase:n #1 +\cs_new:Nn \__crefthe_conditional_uppercase:n { - \bool_if:NTF \l__crefthe_uppercase_bool + \bool_if:NTF \g__crefthe_uppercase_bool { \text_titlecase_first:n } { \use:n } { #1 } -- cgit v1.2.3