如何完全控制引用标题首字母的大小写确实如此,但在我看来,一个命令就可以完成
*emphasized text*\documentclass[11pt]{book}
\usepackage{xparse}
\usepackage{tcolorbox}
\usepackage{hyperref}
\usepackage{cleveref}
\makeatletter
\def\first@up#1#2\relax{\uppercase{#1}#2}%
\newcommand{\FirstUpcase}[1]%
{\expandafter\expandafter\expandafter\first@up#1\relax}%
\makeatother
\makeatletter
\def\first@low#1#2\relax{\lowercase{#1}#2}%
\newcommand{\FirstLowcase}[1]%
{\expandafter\expandafter\expandafter\first@low#1\relax}%
\makeatother
\NewDocumentCommand%
{\TitleRef}{sm}%
{%begin definition
\IfBooleanTF{#1}%
{%
\FirstUpcase{\getrefbykeydefault{#2}{name}{-1}}%
}%
{%
\IfRefUndefinedExpandable{#2}{}%
{% begin label is defined, now get hyperlink
\hyperlink{\getrefbykeydefault{#2}{anchor}{-1}}%creates the link
{\FirstUpcase{\getrefbykeydefault{#2}{name}{-1}}}%error otherwise
}% end label is defined, now get hyperlink
}%
}%end definition
\NewDocumentCommand%
{\titleRef}{sm}%
{%begin definition
\IfBooleanTF{#1}%
{%
\FirstLowcase{\getrefbykeydefault{#2}{name}{-1}}%
}%
{%
\IfRefUndefinedExpandable{#2}{}%
{% begin label is defined, now get hyperlink
\hyperlink{\getrefbykeydefault{#2}{anchor}{-1}}%
{\FirstLowcase{\getrefbykeydefault{#2}{name}{-1}}}%
}% end label is defined, now get hyperlink
}% end if false
}%definition
\newcommand{\cfbox}[2]%
{%
\colorlet{currentcolor}{.}%
{\color{#1}%
\fbox{\color{currentcolor}#2}}%
}%
\begin{document}
\chapter{ONE}\label{1}
\section{lower}\label{1-1}
\section{Upper}\label{1-2}
Here are what the two commands I have, courtesy of Christian Hufner, do:
TitleRef on lower: \hspace{5mm} \TitleRef{1-1}\hspace{5mm} (lower changed to Lower)
TitleRef on Upper: \hspace{5mm} \TitleRef{1-2}\hspace{5mm} (Not changed)
titleRef on Upper: \hspace{5mm} \titleRef{1-2}\hspace{5mm} (Upper changed to upper)
titleRef on lower: \hspace{5mm} \titleRef{1-1}\hspace{5mm} (Not changed)
\hspace{-6mm}Here is what I would like one command, TtitleRef, to do:
TtitleRef on Upper: \hspace{5mm} \cfbox{red}{upper}\hspace{5mm} (Upper changed to upper)
TtitleRef on lower:\hspace{5mm} \cfbox{red}{Lower}\hspace{5mm} (lower changed to Lower)
\end{document}
以下是 PDF 版本: