1

I'm trying to refer to the name of an amsthm theorem* environment using cleveref's namecref command.

However

\documentclass{article}
\usepackage{amsthm}
\usepackage{cleveref}
\newtheorem*{note}{Note}

\begin{document}
    \section{Test}

    \begin{note}\label{myNote}
        Lorem ipsum...
    \end{note}

    In the previous \lcnamecref{myNote}...
\end{document}

yields

In the previous section...

rather than

In the previous note...

as the last line. Is there any way to change this behaviour?

Any help would be much appreciated.

5
  • 1
    \newtheorem* defines an unnumbered theorem environment, so it does not call \refstepcounter and label data is not set, thus \label happens to get whatever was set last, in this case, the section. In theory, you could set the \@currentcounter for this, but it would be a stretch, and other reference data would not be meaningful for that label. You could use \label[note]{myNote}. But the same problem arises, if you forget and try to use \cref{myNote} you get "weird" results (a "note" reference, but the number will come from the section...).
    – gusbrs
    Commented Mar 21 at 20:49
  • LaTeX associates the argument of \label with the most recently incremented LaTeX counter. As you've defined the note environment not to receive a number, no counter is incremented when \begin{note} is executed. LaTeX therefore has no choice but to associate myNote with the the most recently incremented counter, which happens to be the section counter; it's also why \lcnameref generates "section" rather than "note". You ask, 'Is there any way to change this behaviour?' Answer: Start generaiting numbered note environments.
    – Mico
    Commented Mar 21 at 20:53
  • Many thanks for both of your detailed explanations and suggestions. I think \label[note]{myNote} probably best fits my current use case; I don't want to number this particular environment, but wanted the below sentence to change were I to use, for instance, "Remark" instead of "Note". Since the label is right next to the environment, I'm sure I'll remember to update that also were I to change the environment.
    – Dave
    Commented Mar 21 at 21:13
  • @Dave As I've said, the use of \label[note]{myNote} has some pitfalls. Bad use of label/ref automation, I'd say. If the reference is "right next to the environment", just write "in the previous note"... Better be explicit about something which is manual, than to pretend it is "automatic" and let it bite you on the slightest deviation from this particular use... But, of course, if you want, you can. To each their own. ;-)
    – gusbrs
    Commented Mar 21 at 21:22
  • Thanks for the advice @gusbrs, just to clarify the actual reference isn't right next to the note in my document, only the label is next to the environment, I'm trying to get the name of an unnumbered environment as one part of something more complex I'm trying in my document, the minimal example I've given was only really to illustrate the question!
    – Dave
    Commented Mar 21 at 23:41

1 Answer 1

1

I find this pretty useless. Anyway, you can define a numbered theorem and suppress showing the number.

\documentclass{article}
\usepackage{amsthm}
\usepackage{cleveref}

% see https://tex.stackexchange.com/a/17555/4427
\newtheoremstyle{unnumbered}
  {\topsep}   % ABOVESPACE
  {\topsep}   % BELOWSPACE
  {\itshape}  % BODYFONT
  {0pt}       % INDENT (empty value is the same as 0pt)
  {\bfseries} % HEADFONT
  {.}         % HEADPUNCT
  {5pt plus 1pt minus 1pt} % HEADSPACE
  {\thmname{#1}\thmnote{ (#3)}} % CUSTOM-HEAD-SPEC
\theoremstyle{unnumbered}
\newtheorem{note}{Note}

\begin{document}

\section{Test}

\begin{note}\label{myNote}
Lorem ipsum...
\end{note}

In the previous \lcnamecref{myNote}...

\end{document}

enter image description here

You must log in to answer this question.

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