1

I would like to customise the way \ref command appears on my output. When i use the \ref{reference_to_something} to some equation, the outcome is the number of the equation, or the definition with the label "reference_to_something", but I want it to appear between round parentheses. For instance if I have:

and referring to equation 4.3.2 [...]

my purpose is to add, automatically, without writing every time (),

and referring to equation (4.3.2) [...]

I tried with \renewcommand but it did not work for me. Any suggestions?

Mico
  • 506,678
GiuTeX
  • 1,309

2 Answers2

4

A solution without any further packages, by redefinition of \p@equation, which 'gobbles' \csname theequation\endcsname first (the usual cross-reference format) and then uses (\theequation) -- this requires \defin order to make use of the \csname theequation\endcsname as an argument delimiter -- \newcommand would not work here.
Since @ is involved, a \makeatletter...\makeatother pair is needed in a normal document file.

\documentclass{article}

\makeatletter
\def\gobblesomething#1\csname theequation\endcsname{(\theequation)}
\renewcommand{\p@equation}{\gobblesomething}
\makeatother

\begin{document}

\setcounter{equation}{17}

\begin{equation}
  E = mc^{2} \label{Einstein}
\end{equation}

See \ref{Einstein}
\end{document}

enter image description here

Here is a similar question: https://tex.stackexchange.com/a/407421/31729

And another similar question can be found here about gobbling some text: Reference appendix objects within texts as 'A. 1', but not 'Appendix A. 1'

3

For equations, you can use \eqref from amsmath package. So, instead of \ref{reference_to_something}, you write \eqref{reference_to_something} and get (equation_number).

Mico
  • 506,678