2

I want my equations to be labelled with the ordinary counter, but also additional text, but where later reference uses its own customized text. Something like

We have

        (a+b)^2 = a^2 + 2ab + b^2     (18, a, b)

From (18, 2x, -y) we get (2x-y)^2=4x^2-4xy+y^2.

(assuming we have reached the 18th labelled equation)

produced by somthing like

\documentclass{article}
\usepackage{amsmath}

% Insert definition of \labelWithArgument and \eqrefWithArgument here

\begin{document}

We have
\begin{equation}
\labelWithArgument{some_eq}{$,a,b$}
(a+b)^2 = a^2 + 2ab + b^2
\end{equation}

From \eqrefWithArgument{some_eq}{$,2x,-y$} we get $(2x-y)^2=4x^2-4xy+y^2$.

\end{document}

The idea is to add a, b as "variables" in the equation, and 2x, -y as "parameters" at later reference. How do I define \labelWithArgument and \eqrefWithArgument?

1 Answer 1

0

I think that the best solution is to use \newtagform from mathtools to define a new "tag form" for the equation numbers. For any given equation the label and reference "arguments" are static text that does not need to be processed by the macro (just by TeX). Therefore, the new tag form can be defined as:

\newtagform{argumenttag}{(}{, \tagargument)}

where the macro \tagargument is the label "arguments". To use this we define

\newcommand\labelWithArgument[2]{%
    \usetagform{argumenttag}% use the new tag form
    \def\tagargument{#2}\label{#1}% set label and `\tagargument
}

Of course, you also need a \eqrefWithArgument command, but this is easy enough (see below). With all of this in place, here is your output:

enter image description here

...and here is the full code:

\documentclass{article}
\usepackage{amsmath}
\usepackage{refcount}
\usepackage{mathtools}

\newtagform{argumenttag}{(}{, \tagargument)}% define new form for tags
\newcommand\labelWithArgument[2]{%
    \usetagform{argumenttag}% use the new tag form
    \def\tagargument{#2}\label{#1}% set tag arguments and label
}
\newcommand\eqrefWithArgument[2]{%
\def\myref{\getrefnumber{#1}}% extract the reference number
(\myref, \mbox{#2})% print the reference number with argument
}

\begin{document}

We have
\begin{equation}\labelWithArgument{some_eq}{$a,b$}
    (a+b)^2 = a^2 + 2ab + b^2
\end{equation}

From \eqrefWithArgument{some_eq}{$2x,-y$} we get $(2x-y)^2=4x^2-4xy+y^2$.

\end{document}

I have used the refcount package to extract the references and put it into the desired form. This is not strictly necessary but it has the advantage that the code will work without change with hyperref and friends.

2
  • Your solution with mathtools does excactly what I want, thanks a lot!!! For your information, the second solution does not, the reference becomes (1,a,b,2x,-y), apparently the entire tag becomes "1,a,b". Aug 25, 2015 at 11:49
  • @RogerJohnsson Funny, as it definitely was working....will delete it. If the solution works you can up-vote it and then assign a tick to the best answer.
    – user30471
    Aug 25, 2015 at 12:15

You must log in to answer this question.

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