我以前用过这个\begin{document}
:
\newcounter{mylabelcounter}
\makeatletter
\newcommand{\labelText}[2]{%
#1\refstepcounter{mylabelcounter}%
\immediate\write\@auxout{%
\string\newlabel{#2}{{1}{\thepage}{{\unexpanded{#1}}}{mylabelcounter.\number\value{mylabelcounter}}{}}%
}%
}
\makeatother
然后在文档中
\labelText{Sample with holes}{label:text}
和
The \nameref{label:text} features extensive number of...
我想要的是得到句子:有孔的样本具有大量的....
我需要句子中单词 sample 的首字母为小写(minuscule),首字母为\labelText{Sample with holes}
大写(majuscule)......所以我需要使用\MakeLowercase
命令\nameref{label:text}
...
有谁能够帮助我?
非常感谢!
答案1
这是我的包中经过一些修改的版本crossreftools
,代码也将添加到该包中。
使用\labelText
或\labelText*
来显示文本或仅隐藏它,然后应用或\lnameref
作为所引用文本的案例引用。\unameref
lower
upper
\documentclass{article}
\usepackage{blindtext}
\usepackage{hyperref}
\usepackage{crossreftools}
\makeatletter
\def\first@up#1#2\relax{\uppercase{#1}#2}%
\def\first@low#1#2\relax{\lowercase{#1}#2}
\newcommand{\firstupper}[1]{\expandafter\expandafter\expandafter\first@up#1\relax}%
\newcommand{\firstlower}[1]{\expandafter\expandafter\expandafter\first@low#1\relax}%
\def\labelText{%
\@ifstar{\@labeltextstarred}{\@labeltext}
}
\newcommand{\@labeltextstarred}[2]{%
\crtcrossreflabel*{#1}[#2]%
}
\newcommand{\@labeltext}[2]{%
\crtcrossreflabel{#1}[#2]%
}
\def\@lowercasesplitter#1#2#3#4#5\@nil{%
\firstlower{#3}% get the 3rd argument
}
\def\@uppercasesplitter#1#2#3#4#5\@nil{%
\firstupper{#3}% Get the 3rd. argument
}
\newcommand{\lowercasesplitter}[1]{%
\expandafter\@lowercasesplitter#1\@nil%
}
\newcommand{\uppercasesplitter}[1]{%
\expandafter\@uppercasesplitter#1\@nil%
}
\newcommand{\lnameref}[1]{%
\crtifdefinedlabel{#1}{%
\expandafter\lowercasesplitter\csname r@#1\endcsname%
}{}%
}
\newcommand{\unameref}[1]{%
\crtifdefinedlabel{#1}{%
\expandafter\uppercasesplitter\csname r@#1\endcsname%
}{}%
}
\makeatother
\begin{document}
\labelText{Sample with holes}{label:text} \labelText*{and now for something completely different}{other:text}
In \lnameref{label:text} or \unameref{other:text} we have
\end{document}
更短的版本更新后的crossreftools
(版本 0.6)软件包(直到软件包出现在 CTAN/TeXLive/MikTeX 上),您可以使用它DropBox 链接
\documentclass{article}
\usepackage{blindtext}
\usepackage{hyperref}
\usepackage{crossreftools}
\makeatletter
\def\labelText{%
\@ifstar{\@labeltextstarred}{\@labeltext}
}
\newcommand{\@labeltextstarred}[2]{%
\crtcrossreflabel*{#1}[#2]%
}
\newcommand{\@labeltext}[2]{%
\crtcrossreflabel{#1}[#2]%
}
\makeatother
\begin{document}
\labelText{Sample with holes}{label:text} \labelText*{and now for something completely different}{other:text}
In \crtlnameref{label:text} or \crtunameref{other:text} we have
\end{document}
答案2
您可以\lowercase
在之前插入处理\immediate\write
:
\lowercase{\def\tmp{#1}}%
\immediate\write\@auxout{%
\string\newlabel{#2}{{1}{\thepage}{{\unexpanded\expandafter{\tmp}}}{mylabelcounter.\number\value{mylabelcounter}}{}}%
}%
但是我警告你。你的代码很糟糕。如果你需要使用页面引用,那么你不能使用\immediate\write
,因为\thepage
在的时候被扩展了\immediate
,即在 TeX 不确定正确的页码的时候。