Re: Referencing a piece of text



Ulrich Diez wrote:

Afaik the \tag-macro is used for providing numbering/naming of
equations different from what would automatically be provided by
(AMS)LaTeX.

\label, \ref and \pageref are used for referencing material
which usually is automatically generated by LaTeX during
compilation (and which usually is not typed by you explicitly)
and which usually is used for automatically structuring your
document (e.g. page-numbers, sectioning-numbers,
equation-numbers/names, enumerate-item-numbers).

Just "a piece of text" is not an automatically generated means
of structuring your document. It is something which's content
is decided upon by you and by you alone (more or less) and
which's content needs be typed explicitly by you.
So why do you want to use the \ref-macro?

A tag is a tag ("something used for identification or location"). Label
has the same sence. I do not see why it is important that the tag
should be automatically generated to be used for referencing.

If you seek an easy way of placing the same piece/bit of text
into your document more than once without having to type the
whole bit explicitly several times, just define a macro which
expands to your piece of text. Something like this:

\documentclass{minimal}
\begin{document}
bla bla \newcommand*{\abckey}{ABC}\abckey is
a great method.\\
Do you know \abckey?
\end{document}

Or better have the macro-definition already performed in
preamble:

\documentclass{minimal}
\newcommand*{\abckey}{ABC}%
\begin{document}
bla bla \abckey is
a great method.\\
Do you know \abckey?
\end{document}

If you still insist in (ab?)using the \ref- and \label-mechanism,

Thank you for your suggestion. It is obvious. Also, \savebox could be
used. I wanted to know how to do true references.

I'd like to know about your reason for doing so.

I am sorry for not providing the reason at once.

In case you don't have a reason but curiosity,

This is not curiosity. For example, in mathematics it is common to tag
assumptions/axioms. (A1) or similar. This is like labelling equations,
but instead of equation some text is labelled. I need this for a book.

I can tell you a
way of referencing a piece of text instead of e.g. a section-
number or the like. But first you need to know about how
\label and \ref work:

Whenever a \label occurs, sectioning-number and page-number get
written to the aux-file. For doing so,
- information about the page-number is gathered from the
page-counter.
- information about the current sectioning-number is gathered
from the \@currentlabel-macro which gets redefined by each
sectioning-command to expand to the value of the corresponding
sectioning-construct's number/counter-value-output (plus
prefix).

\ref and \pageref regain this info by means of the aux-file.

So what you could do is redefining \@currentlabel to expand to
your bit of text right before placing a label. You could also
create another macro to do that job:

\makeatletter
\newcommand\texttag[2]{%
\begingroup
\def\@currentlabel{#2}%
\label{#1}%
\endgroup
}%
\makeatother

But I cannot recommend this as you might run into all kinds of
trouble:
- If the text-argument is not full expandable e.g. due to
containing some definitions/assignments, problems might
arise.
- If the text-argument contains other calls of \label, problems
might arise.
- If \texttag appears within an area of your source-code where
category-codes are changed, problems might arise as catcodes
usually are not yet changed while reading the aux-file.
- When using the hyperref-package, your text will be colored/
underlined or whatever. When mouse clicks on it, you will be
navigated to the place which corresponds to the source-location
where the corresponding \texttag/\label is placed.
- You need at least two LaTeX-runs until your texttag will be
visible in the resulting document.

Yes, I understand this. But I need this \tag-like behavior. hyperref
could be customize not to color/underline referenses.

\documentclass{article}
%\usepackage{hyperref}

\makeatletter
\newcommand\texttag[2]{%
\begingroup
\def\@currentlabel{#2}%
\label{#1}%
\endgroup
}%
\makeatother

\begin{document}

\section{Test section}

text text \label{sometext}

text text \texttag{sometag}{This some test.}
Refer to sometag: \ref{sometag}

text text \texttag{sometagA}{This is reference to sometext: \ref{sometext}.}
Refer to sometagA: \ref{sometagA}

Thank you. This is nice. Currently I'm in the process of using this in
my document.

\section{Raising errors}

% Placing labels into tags will raise errors:

%text text \texttag{sometagB}{This example test. Let's place another
% label into it. \label{sometagB-1}}%
%Refer to sometagB: \ref{sometagB}
%Refer to sometagB-1: \ref{sometagB-1}

% Defining within tags will raise errors:

%text text \texttag{sometagA}{\def\test{hello}This example test.}
%\ref{sometagA}

\end{document}

Yes, I see the problem.

.



Relevant Pages

  • Re: AdvancedSearch and recipients email address
    ... I thought I saw another post from you referencing that tag, ... think that it is the senders email, not the recipients. ...
    (microsoft.public.outlook.program_vba)
  • Re: TRM - Morbidity has set in, or not?
    ... values for the domain and everything referencing the same date ... would refer to the same value. ... But exhaustive enumeration isn't the only way one can ... "billions and billions" of bits when considering modern data stores. ...
    (comp.databases.theory)
  • Re: Data Validation - reference to another workbook
    ... You can refer to another file but the other file *must* be open for it to ... See this for instructions: ... I have created a NAME referencing a list of customer codes ... list, using the Data Validation, but it would not allow me to select this ...
    (microsoft.public.excel.worksheet.functions)
  • RE: Array Manipulation with VBA coding
    ... Rangerefers to cell A1 ... Just don't confuse this method of referencing a range w/the Offset method. ... would refer to cell A2. ... The VBA Language reference End ...
    (microsoft.public.excel.misc)