2

I know that there have been some similar questions, but in neither did I find any answer that can work for me.

I'm writing a philosophy paper, and want to reference claim I make as I write in a numbered manner, similar to how you would reference theorems, claims, or equations in a math paper.

The setting would be something like this:

This is a paragraph I'm writing, and {here is a claim I'd like to reference} \label{clm:claim1}
...
Some other paragraph I'm writing, and I reference \ref{clm:claim1}.

In the \ref{clm:claim1} I want instead to either appear (I), (1), or Claim 1

Can anyone give me pointers on how to do this? I'm using Overleaf with XeLatex.

Thanks!

  • 1
    Welcome to tex.sx. A linked cross-reference must have an "anchor" that it can be associated with. That is usually provided by an automatically numbered environment, like a section heading or equation or theorem number. But your example has no such anchor point. This question should help: Link to arbitrary part of text? – barbara beeton Sep 16 '19 at 00:32
  • Hey barbara, thanks for the reply. I actually checked out that question before, but decided against using the hyper link because I needed the counter. So, from what I understand, the best way is to define a custom environment that continues writing inline (and then in the rendering I'll see no difference, but I can the reference that environment with the counter and everything) - is my understanding correct? – Eytan Chamovitz Sep 19 '19 at 17:53
  • My understanding is that a link with an unnumbered anchor can only be referenced with \pageref, and then when that page is brought up with the link, it will be at the top of the page, which in the case shown in your example isn't very specific. I'm very uncertain that a visibly unnumbered inline statement can be unambiguously accessed with a hyperlink. (Maybe somebody else can prove me wrong.) – barbara beeton Sep 19 '19 at 19:33

2 Answers2

1

You can have LaTeX allocate a new counter whose name is NewCounter for counting whatever things via \newcounter{NewCounter}[<name of superordinate counter whose incrementing will reset NewCounter to the value 0>].
You can have LaTeX increment the counter NewCounter via \stepcounter{NewCounter} and via \refstepcounter{NewCounter}.
When you use \refstepcounter, then it is possible to place a command \label{MyLabel} somewhere between that \refstepcounter-directive and the next \refstepcounter-directive. When you do that, then

  • you can via \pageref{MyLabel} reference the number of the page which LaTeX was about to construct when encountering the \refstepcounter-directive
  • you can via \ref{MyLabel} obtain those things which you could obtain via \p@NewCounter\theNewCounter at the time right after LaTeX carried out the \refstepcounter-directive. (\p@NewCounter is intended to provide a standard-prefix which will be prepended to each reference via \ref. Usually \p@-macros are defined empty.)

Be aware that all this referencing is possible even when the value of NewCounter was never printed via \theNewCounter after "refstepping" NewCounter.

When the hyperref-package is loaded, then

  • \refstepcounter will also trigger placing a destination/an anchor into the .pdf-file whose name is derived from the value of NewCounter by means of the macro \theHNewCounter.
  • \ref/\pageref do not only deliver textual phrases but will deliver the textual phrases turned into hyperlinks which can be clicked for scrolling/navigating to that section of the document which is referenced.
  • you can use \hyperref[<name of referencing-label>]{<custom phrase>} in order to obtain customized phrases turned into hyperlinks which can be clicked for scrolling/navigating to that section of the document. Within the <custom phrase>-argument you can use the starred variants \ref*/\pageref*.

Example:

\documentclass[landscape, a4paper]{article}

\makeatletter
%
% Layout of this example
%
\@ifundefined{pdfpagewidth}{}{\pdfpagewidth=\paperwidth}
\@ifundefined{pdfpageheight}{}{\pdfpageheight=\paperheight}
\@ifundefined{pagewidth}{}{\pagewidth=\paperwidth}
\@ifundefined{pageheight}{}{\pageheight=\paperheight}
\oddsidemargin=1cm
\textwidth=\paperwidth
\advance\textwidth-2\oddsidemargin
\advance\oddsidemargin-1in
\advance\oddsidemargin-\hoffset
\evensidemargin=\oddsidemargin
\topmargin=1cm
\textheight=\paperheight
\advance\textheight-2\topmargin
\advance\topmargin-1in
\advance\topmargin-\voffset
\headheight=0pt
\headsep=0pt
\footnotesep=.75cm
\marginparwidth=5mm
\marginparsep=2.5mm
\parindent=0ex
\parskip=.66\baselineskip
\pagestyle{plain}
\makeatother


\usepackage{soul}
\usepackage[expand]{gettitlestring}
\usepackage{nameref}
\usepackage{refcount}
%\usepackage{nohyperref}
\usepackage{hyperref}


\makeatletter
\GetTitleStringDisableCommands{\let\ul\@firstofone}%
\newcounter{claim}
\renewcommand\theclaim{\arabic{claim}}
\ifx\hyper@anchor\ltx@gobble\else\@ifundefined{hyper@anchor}{}{\renewcommand\theHclaim{\arabic{claim}}}\fi
\@ifdefinable\claim{%
  \DeclareRobustCommand\claim[1]{%
    \@ifundefined{NR@gettitle}{\def\@currentlabelname{#1}}{\NR@gettitle{#1}}%
    \refstepcounter{claim}%
    \ifx\hyper@anchor\ltx@gobble\else\@ifundefined{hyper@anchor}{}{\noexpand}\fi#1%
  }% the \nobreak is to ensure that the box with the anchor will be tied to the following box.
}%
\makeatother

\newcommand\claimref[2]{\hyperref[{#1}]{#2}}

\begin{document}

This is a paragraph I'm writing, and \claim{\ul{here is a claim I'd like to reference.}}\label{clm:claim1}%

\newpage

\verb|Some other paragraph I'm writing, and \claimref{clm:claim1}{here I reference my claim}.| yields:

Some other paragraph I'm writing, and \claimref{clm:claim1}{here I reference my claim}.

\verb|\nameref{clm:claim1}| yields: \nameref{clm:claim1}

\verb|\nameref*{clm:claim1}| yields: \nameref*{clm:claim1}


\verb|\hyperref[clm:claim1]{\expandafter\expandafter\expandafter\MakeUppercase\getrefbykeydefault{clm:claim1}{name}{??}}| yields:

\hyperref[clm:claim1]{\expandafter\expandafter\expandafter\MakeUppercase\getrefbykeydefault{clm:claim1}{name}{??}}

\end{document}

enter image description here

enter image description here

Ulrich Diez
  • 28,770
1

You wrote,

I'm writing a philosophy paper, and want to reference claim[s] I make as I write in a numbered manner, similar to how you would reference theorems, claims, or equations in a math paper.

The amsthm and ntheorem packages can be used to create numbered theorem-like environments. These environments needn't be theorems, lemmas, corollaries in the usual mathematical sense; they can be "claims" too. The following code shows how to (a) set up an environment called claim and (b) how to cross-reference instances of this environment via the usual \label-\ref mechanism.

\documentclass{article}
\usepackage{lipsum}
\usepackage{amsthm} % for \theoremstyle and \newtheorem macros
\usepackage[colorlinks,allcolors=blue]{hyperref} % optional
\usepackage[nameinlink]{cleveref}

\theoremstyle{definition} % for a non-flashy, even somewhat subdued 'look'
\newtheorem{claim}{Claim}
\renewcommand\theclaim{(\Roman{claim})} % set as needed
\crefname{claim}{Claim}{Claims}


\begin{document}

\lipsum[1-2] % filler text

\begin{claim}\label{clm:claimX}
Here is a claim I'd like to reference.
\end{claim} 

\lipsum[3-6] % more filler text

Some other paragraph I'm writing, in which I cross-reference \cref{clm:claimX}. 

\end{document}
Mico
  • 506,678