I've formulated this question inline inside my SSCCE:
\documentclass[12pt,oneside,onecolumn,a4paper]{article}
\usepackage{amssymb,amsmath,amsthm}
\usepackage{imakeidx}
% NOTE: Hyperref should typically be loaded last of all the packages.
\usepackage{hyperref}
% Add a label and an index entry at the same time.
\newcommand{\idxlabel}[2]{\label{#1}\index{#2}}
\makeindex
% Various theorem environments. Only one variety included here.
\theoremstyle{plain} % just in case the style had changed
\newcommand{\thistheoremname}{}
\newtheorem{thm}{Theorem}[section] % the main one
\newtheorem{thm}{Theorem} % unnumberedtheorem
% there are generic theorems used to construct the environments below:
\newtheorem{genericthm}{\thistheoremname}
\newenvironment{namedthm}[1]
{\renewcommand{\thistheoremname}{#1}%
\begin{genericthm}}
{\end{genericthm*}}
\title{How do I select a named theorem name as a label reference using nameref?}
\begin{document}
\maketitle
\section{This is the first section}
\begin{namedthm*}{Some Theorem}[book-I-found-it-in]
\idxlabel{my-theorem}{Some Theorem}
Here, I define a theorem I would like to refer to later. I would like the
text form to display ``Some Theorem" rather than a section or page number.
It would be nice if \idxlabel could interpret the theorem name from the
namedthm environment, but I would also like to know how to override
that and provide my own just in case.
It may need to differ from the index, because the index supports nested
terms such as Latex!Cross-referencing.
\end{namedthm*}
\section{This is the second section}
Here I would like to talk about \nameref{my-theorem} (and this should say
``Some Theorem"", ideally.
\clearpage
\printindex
\end{document}
To compile this you should probably use a tool like latexmk or rubber (I use the former) in order that the links are picked up. The problem is as follows:
What I would really like is for that "book-I-found-it-in" to correctly pick up the theorem name. I would also like to know if I can control what appears there. I have tried moving around the label statement including inside the theorem definition, and it picks up nothing or variously the section title or something preceding the theorem.
I understand from other answers on this site how such labels make their way to the aux file, and now I would like to control their display.
