# How to get upright parentheses in the whole document?

My question is, basically, the same as the one in Upright parentheses in italic text: how do I force all parentheses in my document to be upright, without replacing them with some commands "by hand"?

Unlike the linked question, my main concern are slanted environments (i.e., theorems). At the moment, I'm dealing with elsarticle, which uses \itshape which is not covered by the solutions on above link (and I don't see how I could modify them to do so), nor by the embrac package (explicitly stated in Section 9).

MWE:

\documentclass{article}

\newtheorem{theorem}{Theorem}

\begin{document}

\begin{theorem}
I want parenthesis (around this text) to be upright.
\end{theorem}

\end{document}


I can, of course, write

I want parenthesis {\rm (}around this text{\rm )} to be upright.


or define some commands for the upright parentheses and use them. However, changing the parentheses in the LaTeX code can lead to errors (for example, missing some of them and introducing inconsistency) and puts a burden of focusing on that detail, instead of the text I'm writing, so I'd prefer some automated way (like the one shown for \emph in the linked document).

-
Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – henrique Dec 8 '12 at 16:38
@henrique: I apologize. I thought the question was fairly obvious. I've added it now and I hope it's ok now. – Vedran Šego Dec 8 '12 at 16:48
I'm afraid that the only really robust solution is to have italic fonts with upright parentheses. I tend to avoid parentheses in italics contexts or use \textup(...\textup). – egreg Dec 8 '12 at 16:56

As egreg warned, the following will probably break many things. But it works in simple situations. [code edited following egreg's advice]

[update: at the bottom of this answer I edit the answer to be compatible with \label and \ref]

\documentclass{article}

\newtheorem{theorem}{Theorem}

\catcode1=12
\catcode2=12
\mathcode1=\the\mathcode$$\delcode1=\the\delcode\( \mathcode2=\the\mathcode$$
\delcode2=\the\delcode\)

\catcode$$=\active \catcode$$=\active

\everymath{\let(^^A\let)^^B}
\everydisplay{\let(^^A\let)^^B}

%%\def({\begingroup\upshape\char$$\endgroup} %%\def){\begingroup\upshape\char$$\endgroup}
\def({\textup{\char$$}} \def){\textup{\char$$}}

\begin{document}

\begin{theorem}
I want parenthesis (around this text) to be upright. Of course, parentheses in
math mode are already upright: $\Bigg((E = mc^2)\Bigg)$, and we don't want to
fiddle with them.
\end{theorem}
$\Bigg((E = mc^2)\Bigg)$
I want parenthesis (around this text) to be upright.
\emph{I want parenthesis (around this text) to be upright. }
\end{document}


with egreg's suggestion the spacing appears to be better:

Code for (hopefully...) compatibility with \label and \ref (with or without hyperref used in the document):

\documentclass{article}
\usepackage{hyperref}
\newtheorem{theorem}{Theorem}

\def\makeparenletter{\catcode$$=11 \catcode$$=11 }
\def\makeparenother{\catcode$$=12 \catcode$$=12 }
\def\makeparenactive{\catcode$$=\active\catcode$$=\active}

\catcode1=12
\catcode2=12
\mathcode1=\the\mathcode$$\delcode1=\the\delcode\( \mathcode2=\the\mathcode$$
\delcode2=\the\delcode\)

\makeparenactive
\everymath{\let(^^A\let)^^B}
\everydisplay{\let(^^A\let)^^B}
\def({\textup{\char$$}} \def){\textup{\char$$}}
\makeparenother

\AtBeginDocument{% this is at begin document as it must be done
% after hyperref does its things
\makeparenactive
\let\zzzlabel\label
\let\zzzref\ref
\let\zzznewlabel\newlabel

\def\label{\makeparenletter\wwwlabel}
\def\ref{\makeparenletter\wwwref}
\def\newlabel{\makeparenletter\wwwnewlabel}

\def\wwwlabel#1{\makeparenactive\zzzlabel{#1}}
\def\wwwref#1{\makeparenactive\zzzref{#1}}
\def\wwwnewlabel#1{\makeparenactive\zzznewlabel{#1}}}

\begin{document}\thispagestyle{empty}

\begin{theorem}\label{(thm:1)}
I want parenthesis (around this text) to be upright. Of course, parentheses in
math mode are already upright: $\Bigg((E = mc^2)\Bigg)$, and we don't want to
fiddle with them.
\end{theorem}
$\Bigg((E = mc^2)\Bigg)$
I want parenthesis (around this text) to be upright.
\emph{I want parenthesis (around this text) to be upright. \textbf{I want parenthesis (around this text) to be upright. }}

Theorem \ref{(thm:1)}
\end{document}


-
Try \def){\textup{\char\)}} and you'll see an improvement. – egreg Dec 8 '12 at 17:31
@egreg thanks, modified the code. The spacing appears to be better, why is that? (I have to leave now) – jfbu Dec 8 '12 at 17:42
Thank you both, this seems to do a great job! For anyone else reading this, one of the things that breaks are labels and references with parentheses in them. These are, of course, easily edited if one knows what to looks for. – Vedran Šego Dec 8 '12 at 17:53
@jfbu \textup has heuristics for deciding whether to add an italic correction, which \upshape` hasn't. – egreg Dec 8 '12 at 18:46
@egreg ok, didn't know that. – jfbu Dec 8 '12 at 23:20