3

The object of my question is learning how to remove the numbering that lies adjacent to a new environment after its been called while being able to reference the counter number later using \ref. I've been looking for answers but it seems that everyone wants this numbering while I don't. I understand that I can use \addtocounter{Problem}, but I'd like something automated so that I don't have to worry about that every section or chapter. Any help would be greatly appreciated.

\documentclass{book}

\usepackage{nameref}
\newcounter{Problem}[chapter]
\renewcommand{\theProblem}{\thechapter.\arabic{homework}}
  \newenvironment{Problem}[1][]{
    \refstepcounter{Problem}
    \paragraph{PROBLEM \theProblem~ #1}%
    }
    {
(end of problem)
    }%
\begin{document}

\chapter{New Chapter}

\begin{Problem}[A]

\label{Issue}
I want the problem number on the left to be hidden when using \nameref.
\end{homework}

I'm trying to hide the number when using \nameref{Issue}
\end{document}

I'm sorry, I forgot to include that I am trying to hide the problem number when using \nameref.

  • 2
    Welcome to TeX.SX! If you remove the number, how can a reader know what you're referring to with \ref? – egreg Jan 21 '15 at 21:57
  • 1
    It seems as simple as removing \theProblem from your Problem environment definition... But there is little value in referencing something that doesn't have a corresponding number. Unless, of course, you might be interested in referencing the problem by some literal description. – Werner Jan 21 '15 at 21:58
  • Please complete your code to form a complete, small document we can compile. That's much more useful than a mere code fragment. In this case, it might also help us to understand what you are actually trying to do. – cfr Jan 21 '15 at 22:56
2

If you want that \nameref{Issue} just prints “PROBLEM A”, you have to redefine \@currentlabelname before \label is seen:

\documentclass{book}

\usepackage{nameref}
\newcounter{Problem}[chapter]
\renewcommand{\theProblem}{\thechapter.\arabic{Problem}}

\makeatletter
\newenvironment{Problem}[1][]
  {\refstepcounter{Problem}%
   \paragraph{PROBLEM \theProblem~#1}%
   \def\@currentlabelname{PROBLEM~#1}}
  {(end of problem)}
\makeatother

\begin{document}

\chapter{New Chapter}

\begin{Problem}[A]
\label{Issue}
I want the problem number on the left to be hidden when using \texttt{\string\nameref}.
\end{Problem}

I'm trying to hide the number when using \nameref{Issue}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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