如何完全控制引用标题首字母的大小写

如何完全控制引用标题首字母的大小写

如何控制引用标题首字母的大小写,我最终不知怎么地要求一个宏来将首字母从 更改为lower caseupper case然后\NameRefChristian Hupfer 就用他的 做到了这一点。

但是,回到巨著,我很快就想起我还需要一个宏,可以将首字母从 更改upper caselower case。那么,是否可以修改 Hupfer 宏\NameRef,使其根据首字母是lower case还是进行更改upper case

他的代码是:

\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

\NewDocumentCommand{\NameRef}{sm}{%
  \IfBooleanTF{#1}{%
    \FirstUpcase{\getrefbykeydefault{#2}{name}{-1}}%
  }{%
    \IfRefUndefinedExpandable{#2}{}{%
      % label is defined, now get hyperlink
      \hyperlink{\getrefbykeydefault{#2}{anchor}{-1}}{\FirstUpcase{\getrefbykeydefault{#2}{name}{-1}}}
    }
  }%
}

\newcounter{abc}%
\newtcolorbox%
[%beginForReferences
use counter= abc,
number within=chapter,
number freestyle={\noexpand\thechapter.\noexpand\arabic{\tcbcounter}~\noexpand\mytitleagree},%Used to make for LONG titles in the references.
crefname={alert}{alerts},
Crefname={Alert}{Alerts},
]%endForReferences
{greement}
[2][]%
{%
detach title,
coltitle=black,
nameref={#2},%
before upper={\tcbtitle\quad},
code={\gdef\mytitleagree{#2}},%Used to make for LONG titles in the references.
title=ALERT \thetcbcounter,%
#1,%Required for references.
}%

\begin{document}
\chapter{ONE}\label{1-0-0}
\section{One}\label{1-1-0}
\subsection{one}\label{1-1-1} 
\emph{Relative to the title of the tcolorbox}
\begin{greement}[label={abc:3-1}]{infinity}
  is not a number
\end{greement}
\emph{nameref  gives}

We can see \nameref{abc:3-1} 

\emph{Hupfer's NameRef gives}

 \NameRef{abc:3-1} can be seen.

\emph{Similarly, relative to the title of the subsection, nameref gives}

Since \nameref{1-1-1} is a number,  ...

\emph{and Hupfer's NameRef gives}

\NameRef{1-1-1} being a number


\textbf{all of which is what I asked for.} 
\subsection{Two}\label{1-1-2}
But with
\begin{greement}[label={abc:3-2}]{Infinity}
  is not everything
\end{greement}

\emph{I would like }

``We can see that infinity is not everything''

but \emph{nameref  gives} 

We can see that \nameref{abc:3-2} is not everything

and

\emph{NameRef also gives}

We can see that \NameRef{abc:3-2} is not everything.


\emph{Similarly, relative to the title of the subsection, nameref gives}

\nameref{1-1-2} is a number

but I would also like

Since two is a number

while, at this time, Hupfer's NameRef gives

Since \NameRef{1-1-2} is a number

\end{document}

代码结果如下:

在此处输入图片描述

相关内容