Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'd like to use namerefs within a sentence, and have the case of the resulting text match the position within the sentence. The section title is naturally title case, but is there some command to either a) force lowercase of namerefs (\lowercase{} doesn't work), or b) insert init-case, i.e., uppercase the initial word if it's at the beginning of a sentence, lowercase elsewhere?

Example:

\section{Object}
\label{sec:obj}
[definition of an object]
...
\nameref{sec:obj} instance variables are often called simply "\nameref{sec:obj}".

should produce:

Object
[definition of an object]
...
Object instance variables are often called simply "object".

Note case difference at the start and in the middle of the sentence.

share|improve this question
2  
An example would be useful here: from the description it is pretty hard to follow what is required. –  Joseph Wright Aug 13 '10 at 14:27
    
I don't think the <a href="tex.stackexchange.com/questions/tagged/…; tag is appropriate for this question; the other two articles with the tag are talking about the cases environment from amsmath... –  SamB Sep 27 '10 at 21:17
    
Whoops, apparently that's not the way to do a hyperlink in a comment. (Wishes comments were previewable...) –  SamB Sep 27 '10 at 21:24

1 Answer 1

I think that it would be hard for TeX to automatically know whether the \nameref should be title-case, lowercase, or init-case. But if you are prepared to tell TeX, then this can be done. I don't claim that this is the most elegant method, but it's the one that I use in a similar situation.

\documentclass{article}
\usepackage{hyperref}

\newcommand{\lnameref}[1]{%
\bgroup
\let\nmu\MakeLowercase
\nameref{#1}\egroup}
\newcommand{\fnameref}[1]{%
\bgroup
\def\nmu{\let\nmu\MakeLowercase}%
\nameref{#1}\egroup}


\newcommand{\nmu}{}

\begin{document}

\section{\nmu This \nmu Is a \nmu Section}
\label{sec}

\lnameref{sec} is a section.

\nameref{sec} is a section.

\fnameref{sec} is a section.

\nameref{sec} is a section.

\end{document}

Produces:

1 This Is a Section

this is a section is a section.
This Is a Section is a section.
This is a section is a section.
This Is a Section is a section.

(It makes a modicum more sense when the "this is a section" looks like a link since then it looks like '"this is a section" is a section'. Only when I transcribed it did I realise how daft it looked.)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.