[Tex/LaTex] Place parentheses around a cross-reference

cross-referencinghyperref

Is possible to surround a cross-reference with brackets or parentheses? For example when I write a command like some text \ref{some label} then when compiled the output was some text (12) without manually placing parentheses in latex command, like some text (\ref{some label}).

Best Answer

You could renew the reference command, perhaps something like:

\let\oldref\ref
\renewcommand{\ref}[1]{(\oldref{#1})}

Here's a complete MWE to play with:

% arara: pdflatex
% arara: pdflatex
\documentclass{article}

\let\oldref\ref
\renewcommand{\ref}[1]{(\oldref{#1})}
\begin{document}

\section{Section heading}\label{sec:testlabel}

Reference: \ref{sec:testlabel}
\end{document}

Note: as mentioned by @Mico, this solution isn't compatible with hyperref package.

Related Question