6

I was suggested by my thesis referee that parenthesizes () and citation brackets [] (I only use square brackets generated by biblatex)should always be in upright.

This is indeed the same question as Upright parentheses in italic text and How to get upright parentheses in the whole document?.

But the solution (embrac) there is not fully satisfactory. First, it produces errors for \emph{\(math\) not work!}; second, it does not work for italic texts in theorem environment.

Since this is a style problem, I hope that there is no need to modify the code of the main file manually.

Ma Ming
  • 2,306

3 Answers3

4

What about this:

\def\adef#1{\catcode`#1=13 \bgroup \lccode`\~=`#1\lowercase{\egroup\def~}}
\let\emphOri=\emph
\def\emph{\bgroup\adef({\ifmmode(\else{\rm(}\fi}\adef){\ifmmode)\else{\/\rm)}\fi}\emphA}
\def\emphA#1{\emphOri{#1}\egroup}

\emph{text (text) $\bigl( f(x) + y\bigr)$ text}

If you need to redefine \ithsape too, add the lines:

\long\def\addto#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}}
\addto\itshape{\adef({\ifmmode(\else{\rm(}\fi}\adef){\ifmmode)\else{\/\rm)}\fi}}

{\itshape text (text) $\bigl( f(x) + y\bigr)$ text}

I mean that this code is more compact and more readable than embrac.sty.

Edit: If you need to give the same behaviour to another braces [square baces, for example], you can try this:

\def\adef#1{\catcode`#1=13 \bgroup \lccode`\~=`#1\lowercase{\egroup\def~}}
\long\def\addto#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}}
\def\activebraces#1#2{\adef#1{\ifmmode#1\else{\rm#1}\fi}\adef#2{\ifmmode#2\else{\/\rm#2}\fi}}
\let\emphOri=\emph
\def\emph{\bgroup\activebraces()\activebraces[]\emphA}
\def\emphA#1{\emphOri{#1}\egroup}
\addto\itshape{\activebraces()\activebraces[]}

But I warn: this will not probably work with automatically generated braces (aka from biblatex) because these braces are already tokenized in the macro. I didn't try it but I assume this behavior. You need to find the braces in the package and replace them by \rm version or use some package option (for setting the type of braces). I don't know, sorry, I am not LaTeX specialist.

wipet
  • 74,238
  • This doesn't work for \itshape since it relies on the usage of \emph. – Werner Jun 07 '14 at 04:05
  • @Werner OK, I've added two next lines for \itshape. But this was not required by the question. – wipet Jun 07 '14 at 05:21
  • The question states: "second, it does not work for italic texts in theorem environment." I assumed this references some form of \itshape. – Werner Jun 07 '14 at 05:32
  • It seems nice! Could you modify your code that handles square brackets as well? I only use square brackets generated by biblatex. – Ma Ming Jun 07 '14 at 15:26
  • 1
    @MaMing You can try to set \def\bibleftbracket{{\rm[}} \def\bibrightbracket{{\rm]}}. This is a result from my little reverse engineering of biblatex. This is not mentioned in 300 pages manual. And this is without warranty because I didn't try it with real data because I never use such unnecessarily complicated macro packages. – wipet Jun 09 '14 at 06:45
  • @MaMing Would you tell me if the idea from my previous comment works with biblatex? – wipet Jun 12 '14 at 14:31
  • @wipet I am using \renewcommand{\mkbibbrackets}[1]{\textup{[}#1\textup{]}} to manipulate the square brackets. – Ma Ming Jun 12 '14 at 14:39
  • @wipet It tested for simple cases, it does work too. – Ma Ming Jun 12 '14 at 14:45
2

Since v0.8 embrac provides \embparen for cases like theorem-like environments. The error from the question with math mode cannot be reproduced…

\documentclass{article}
\usepackage{embrac}[2019-10-01] % v0.8
\newtheorem{theorem}{Theorem}

\begin{document}

\emph{$(x^2)$ not work!}% no error here

\begin{theorem}
  Text \embparen{text} text
\end{theorem}

\end{document}

enter image description here

cgnieder
  • 66,645
1

The [] brackets in citations can be fixed using the cite package:

\usepackage{cite}

\def\citeleft{\begingroup\rm[}
\def\citeright{]\endgroup}

This doesn't help with the remaining brackets ()'s in the document. FWIW, I always put mine in math mode.