4

I use this before \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

and then in document

\labelText{Sample with holes}{label:text}

and

The \nameref{label:text} features extensive number of...

What I want is to obtain sentence: The sample with holes features extensive number of....

I need the fist letter of the word sample in the sentence to be lower-case (minuscule), and the first letter in \labelText{Sample with holes} upper-case (majuscule)... so I need to use \MakeLowercase for the command \nameref{label:text}...

Can anybody help me?

Thank you very much!

3
  • You can just replace \unexpanded{#1} by \unexpanded{\MakeLowercase{#1}}, but this may be not the best approach. This feels like an XY problem. What is the aim? Mar 18, 2018 at 10:49
  • When using code from other posts you could at least refer to the answerer (in this it is me ;-): tex.stackexchange.com/a/271064/31729
    – user31729
    Mar 18, 2018 at 10:56
  • Thank you very much, it works with \unexpanded{\MakeLowercase{#1}} ... and I´m sorry that I didn´t refer to the answerer - I don´t know very well how everything works here..
    – Lucie
    Mar 18, 2018 at 11:01

2 Answers 2

1

Here is a version with some modifications from my crossreftools package, the code will be added to that package as well.

Use either \labelText or \labelText* in order to show the text or just hide it and then apply \lnameref or \unameref for lower or upper case reference of the referenced text.

\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}

Much shorter version with the updated crossreftools (version 0.6) package (until the package appears on CTAN/TeXLive/MikTeX) you could use this DropBox link

\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}
0
1

You can insert \lowercase processing just before \immediate\write:

   \lowercase{\def\tmp{#1}}%
   \immediate\write\@auxout{%
        \string\newlabel{#2}{{1}{\thepage}{{\unexpanded\expandafter{\tmp}}}{mylabelcounter.\number\value{mylabelcounter}}{}}%
   }%

But I warn you. Your code is bad. If you will need to use page reference then you cannot use \immediate\write, because \thepage is expanded at the time of \immediate, i. e. at the time when TeX is not sure about right page number.

1
  • Děkuji za odpověď!
    – Lucie
    Mar 18, 2018 at 18:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .