[Tex/LaTex] Upright parentheses in italic text

embracfontsitalicpunctuationtypography

This question led to a new package:
embrac

Bringhurst, in Elements of Typographic Style, recommends to use upright parentheses in italic text (i.e., write 'a (simple) example' as opposed to 'a (simple) example'). I tend to agree, it looks nicer. But, how do I achieve this using LaTeX? One could of course write \emph{a \emph{(}simple\emph{)} example}, but that would get old real soon.

Two approaches I've thought of:

  • Make () (and possibly []) active characters, and ensure that they're always typeset upright, or
  • Do some wizardry with virtual fonts or somesuch.

I might be able to implement the first suggestion with my knowledge, but my gut tells me the second option is more elegant. Unfortunately, my knowledge of (virtual) fonts in LaTeX is even more limited than my knowledge of (in)active characters and catcodes and such. Any ideas on how to go about this?

Best Answer

A LaTeX3 solution. I chose to simply do what you said, replacing every ( by \textup{(}, every ) with \textup{)}, and similarly for brackets, prior to passing the result to the old version of \emph for typesetting.

At the end of the day, xparse allows us to easily define \emph to do what you asked for, and \emph* to do the old version of \emph.

\documentclass{article}
\usepackage{expl3,xparse}
\ExplSyntaxOn
\cs_new_eq:Nc \emph_old:n { emph~ } % Copying the old definition of `\emph`
\cs_new_protected:Npn \emph_braces:n #1 % Set up how braces should be typeset.
  { \mode_if_math:TF {#1} { \textup{#1} } }
\cs_new:Npn \emph_new:n #1 {
  \tl_set:Nn \l_emph_tl {#1}
  \tl_replace_all:Nnn \l_emph_tl {(}{\emph_braces:n{(}}
  \tl_replace_all:Nnn \l_emph_tl {)}{\emph_braces:n{)}}
  \tl_replace_all:Nnn \l_emph_tl {[}{\emph_braces:n{[}}
  \tl_replace_all:Nnn \l_emph_tl {]}{\emph_braces:n{]}}
  \exp_args:NV \emph_old:n \l_emph_tl
}
\RenewDocumentCommand {\emph} {sm} {
  \IfBooleanTF {#1} {\emph_old:n {#2}} {\emph_new:n {#2}}
}
\ExplSyntaxOff
\begin{document}
A \emph{(simple) example}, and \emph*{another one (with no correction)}.
Also some math \emph{\((x+y)^2\) and text (again)}.
\end{document}

EDIT: Alan Munn pointed out a mistake in a comment. Thanks.

EDIT2: An update to expl3 renamed \tl_replace_all_in:Nnn to \tl_replace_all:Nnn.

EDIT3: Barbara Beeton pointed out that I should be using \textup rather than \emph to set parentheses upright. She also mentioned that "it was suggested at one time to create a 'theorem font' in which the alphabet is italic and fences (parens, brackets, braces) are upright", but this font was never made. See comments below.

EDIT4: I had been sloppy when copying the definition of \emph, and this got revealed by the latest xparse update. LaTeX2e's \emph (like many other commands) uses \emph  to hold the real code of \emph (note the trailing space). The line below \ExplSyntaxOn was thus changed to \cs_new_eq:Nc ... { emph~ }: the "c" argument specifier turns emph~ into the appropriate command \emph .

EDIT5: I've added code to avoid changing braces in math mode. Or rather the command used to typeset braces is now math aware (this is much simpler than trying to detect math when doing the replacement).

Related Question