# Upright parentheses in italic text

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?

-
Making [] active will break optional arguments. Same for () and picture environments. – Martin Scharrer Mar 9 '11 at 13:46
@Martin Scharrer: making [( active but \let to themselves would not break \futurelet parsing. Then, they can be redefined to grab the corresponding closing brace inside \emph. – Bruno Le Floch Mar 9 '11 at 14:57
The issue that brought me to this page was the extra space that appears after the parenthesis and before the emphasised text when you write (\emph{Very low}): There is too much space between the ( and the V. The simplest and quickest solution I decided to use is just to take the space away with \! as ($\!$\emph{Very low}). – user14960 May 25 '12 at 13:27
Interestingly enough Bringhurst doesn't seem to follow his own advice: in chapter 1 "The Grand Design" of The Elements Of Typographic Style on the first page he cites a bill "[...] high heeled shoes [or] bolstered hips [...]" using sloped square brackets. Or is "[or]" part of the original text...? – clemens Jul 18 '12 at 16:04
Just a note: the Chicago Manual of Style recommends that the parentheses too are in italics, if the word they enclose is in italics. – Mårten Aug 28 '13 at 14:38

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).

-
This has the problem I allude to in my answer: if you embed it inside another \emph you will get italic parentheses within your upright text, which is probably not what you want! – Alan Munn Mar 9 '11 at 14:46
If you replace the \emph{(} with \textup{(}, it should work. – Michel Mar 9 '11 at 14:51
@Alan: thank you, I fixed it essentially as @Michel is saying. – Bruno Le Floch Mar 9 '11 at 14:54
This looks like what I meant indeed, it has the advantage of not needing a command to parenthesise something. I'll have to read up on LaTeX3 syntax, because I see a lot of unknown stuff here :D – Michel Mar 9 '11 at 15:05
@Bruno this is a really nice solution altogether. You should turn it into a fixemph package and submit it to CTAN. – Alan Munn Mar 9 '11 at 17:57

I would agree not messing with catcodes (although doing so just within an \emph command itself probably wouldn't have too many issues.) But here's a relatively simple solution with a slightly more transparent semantics than Yiannis's solution:

\documentclass{article}

\newcommand{\bemph}[1]{{\upshape#1}} % define how emphasised brackets should look
\newcommand{\ep}[1]{\bemph{(}#1\bemph{)}} % parentheses
\newcommand{\eb}[1]{\bemph{[}#1\bemph{]}} % square brackets

\begin{document}

This is \emph{a \ep{simple} example}.
\emph{This is \emph{a \ep{simple} example}.} % also works embedded in another emph

\end{document}


The advantage of doing things this way is that if you ever need to change what \emph does, you have independent control over what emphasised brackets are. For example if you redefine \emph as underlining or \textbf you can adjust the brackets accordingly.

-

I would keep it simple and not mess up with catcodes and the like. I would define a small macro as follows (you can use a shorter name if you like).

\documentclass{article}
\usepackage{xspace}
\def\bracketemphasis#1#2{(\emph{#1})\xspace\emph{#2}\xspace}
\begin{document}
\bracketemphasis{simple}{example}.
\end{document}


The xspace would correctly handle spacing after punctuation and that is why I included it. \xspace should be used at the end of a macro designed to be used mainly in text. It adds a space unless the macro is followed by punctuation characters.

-
@Yiannis: Can you please expand on the spacing after punctuation? What could go wrong without the \xspace? – Hendrik Vogt Mar 9 '11 at 14:42
@Hendrik thanks, I added a short note as requested. – Yiannis Lazarides Mar 9 '11 at 14:57
@Yiannis: I'm confused about who of the two of us is confused now. Where and why would you get a space if you don't use \xspace? (I only know that \xspace is useful for macros that don't take arguments.) – Hendrik Vogt Mar 9 '11 at 15:00
@Hendrik Vogt I added it primarily to handle as for example This is an \bracketemphasis{example}{text}\bracketemphasis{test}{test}. I modified the explanation to make it more clear, or I hope so:) – Yiannis Lazarides Mar 9 '11 at 17:26
@Yiannis: Ah, it's from the manual, I see. Thanks for the explanation! Maybe the abstract of the manual should indeed say more clearly "at the end of a (parameterless) macro" (of course without the emphasis). That's my point: Your use of \xspace in a macro with parameters seems rather unusual, and this should be explicated in the answer. – Hendrik Vogt Mar 15 '11 at 7:33

This is a fairly different method than the previous one, so I'm posting it separately. The idea here is to make (, ), [, ] active in the whole document. Of course, that breaks everything, so we need to repair it by redefining the interface of every command that we use which takes optional arguments. I chose the syntax to be as close to xparse as possible. For instance,

\ChangeCommandInterface {\section} {t*d[]m} {s{#1}, o{#2}, m{#3}}%


will redefine \section to take three arguments: an optional star (t*), an optional argument delimited by active brackets (d[]), and a mandatory argument (m). Then the argument is reconstructed with the correct catcodes (we could also use that to swap arguments): in xparse, s means optional star, and here we put a star if and only if #1 is true (meaning that there was initially a star). Similarly, o{#2} will mean "put #2 as an optional argument, enclosed in (normal) brackets", and if there was no argument #2, then put no optional argument.

The example document, followed by the code.

% We put the body of the file here, and call it later using \input.
% Of course you can put the rest of this code in a style file
% and \usepackage{...} it in a normal document.
\begin{filecontents}{\jobname-body.tex}
\documentclass{article}
\usepackage{amsthm}
\usepackage{amsmath}
\newtheorem{theorem}{Theorem}
\begin{document}

\tableofcontents
\section[Short title]{Long title}

\begin{theorem}
Test theorem (yes, I'm not inspired \textbf{(at all)}).
\begin{align*}
a\left[ \frac{ \sqrt[3]{c} }{ \sqrt[2]{d} } \right] \\
\end{align*}
\end{theorem}

\end{document}
\end{filecontents}

\RequirePackage{xparse}
\ExplSyntaxOn

% We define functions to store the arguments into a token list
% for use later. Each type of argument has its own "put" function
%
\tl_new:N \l_PWparse_args_tl

\cs_new:Npn \PWparse_put_cmd:N #1 {
\tl_set:Nn \l_PWparse_args_tl {#1} }
\cs_generate_variant:Nn \PWparse_put_cmd:N {c}
\cs_new:Npn \PWparse_put_saved_cmd:N #1 {
\PWparse_put_cmd:c {PWparse_saved_cmd_ \cs_to_str:N #1} }
\cs_new:Npn \PWparse_save_cmd:N #1 {
\cs_new_eq:cN {PWparse_saved_cmd_ \cs_to_str:N #1} #1}

\cs_new:Npn \PWparse_put_arg:n #1 {
\tl_put_right:Nn \l_PWparse_args_tl {#1}}

\cs_new:Npn \PWparse_put_targ:Nn #1 #2 {
\IfBooleanT {#2} { \exp_args:No \PWparse_put_arg:n {\token_to_str:N #1} }
}
\cs_new:Npn \PWparse_put_sarg:n #1 { \PWparse_put_targ:Nn * {#1} }

\cs_new:Npn \PWparse_put_Darg:NNnn #1 #2 #3 #4 {
\IfNoValueTF {#4} {
\PWparse_put_Darg_aux:oon {\token_to_str:N #1} {\token_to_str:N #2} {#3}
}{
\PWparse_put_Darg_aux:oon {\token_to_str:N #1} {\token_to_str:N #2} {#4}
}
}
\cs_new:Npn \PWparse_put_Darg_aux:nnn #1 #2 #3 {
\PWparse_put_arg:n {#1 #3 #2} }
\cs_generate_variant:Nn \PWparse_put_Darg_aux:nnn {oo}
\cs_new:Npn \PWparse_put_Oarg:nn #1 #2 {\PWparse_put_Darg:NNnn [ ] {#1} {#2} }

\cs_new:Npn \PWparse_put_darg:NNn #1 #2 #3 {
\IfNoValueF {#3} { \PWparse_put_Darg:NNnn #1 #2 {} {#3} } }
\cs_new:Npn \PWparse_put_oarg:n #1 {\PWparse_put_darg:NNn [ ] {#1} }
\cs_new:Npn \PWparse_put_uarg:nn #1 #2 {
\PWparse_put_arg:n { #2 #1 } }
\cs_new:Npn \PWparse_put_marg:n #1 {
\PWparse_put_arg:n { {#1} }}
\cs_new_eq:NN \PWparse_put_larg:n \PWparse_put_arg:n
\cs_new:Npn \PWparse_put_garg:n #1 {
\IfNoValueF {#1} {\PWparse_put_marg:n {#1}} }
\cs_new:Npn \PWparse_put_Garg:nn #1 #2 {
\IfNoValueTF {#2} {
\PWparse_put_marg:n {#1}
} {
\PWparse_put_marg:n {#2}
}
}
\cs_new_eq:NN \PWparse_put_Darg:w \PWparse_put_Darg:NNnn
\cs_new_eq:NN \PWparse_put_darg:w \PWparse_put_darg:NNn
\cs_new_eq:NN \PWparse_put_garg:w \PWparse_put_garg:n
\cs_new_eq:NN \PWparse_put_larg:w \PWparse_put_larg:n
\cs_new_eq:NN \PWparse_put_marg:w \PWparse_put_marg:n
\cs_new_eq:NN \PWparse_put_oarg:w \PWparse_put_oarg:n
\cs_new_eq:NN \PWparse_put_Oarg:w \PWparse_put_Oarg:nn
\cs_new_eq:NN \PWparse_put_sarg:w \PWparse_put_sarg:n
\cs_new_eq:NN \PWparse_put_targ:w \PWparse_put_targ:Nn
\cs_new_eq:NN \PWparse_put_uarg:w \PWparse_put_uarg:nn
\cs_new:Npn \PWparse_put_one_arg:N #1 {\use:c{PWparse_put_ #1 arg:w}}

% To change the interface of a command, we save it (equivalent
% of the primitive \let), and then treat arguments one at a time).
%
\cs_new:Npn \ChangeCommandInterface #1 #2 #3 {
\PWparse_save_cmd:N #1
\DeclareDocumentCommand{#1}{#2}{%
\PWparse_put_saved_cmd:N #1
\clist_map_inline:nn {#3} {\PWparse_put_one_arg:N ####1}
\l_PWparse_args_tl
}
}
\ExplSyntaxOff

\begingroup
\catcode$=13\catcode$=13\relax
\catcode$$=13\catcode$$=13\relax
\AtBeginDocument{%
\catcode$=13\catcode$=13\relax
\catcode$$=13\catcode$$=13\relax
\def[{\ifmmode\string [\else\textup{\string [}\fi}%
\def]{\ifmmode\string ]\else\textup{\string ]}\fi}%
\def({\ifmmode\string (\else\textup{\string (}\fi}%
\def){\ifmmode\string )\else\textup{\string )}\fi}%
%
% Complete the list below with your own commands.
\ChangeCommandInterface {\section}    {t*d[]m} {s{#1}, o{#2}, m{#3}}%
\ChangeCommandInterface {\subsection} {t*d[]m} {s{#1}, o{#2}, m{#3}}%
\ChangeCommandInterface {\sqrt}       {d[]m}   {o{#1}, m{#2}}%
}
\endgroup

\input\jobname-body.tex

-

My 2 cents: amslatex has \textup (equivalent to \rom), which is designed precisely for that (of course, you have to put it manually in all needed places).

Also, I am pretty sure that this should be easily doable in luatex.

-
\textup is a standard LaTeX 2e command. amsart does define \upn as shorthand for \textup. You can use \rom for \textup in amsart only if you're in compatibility mode. – MSC Apr 9 '14 at 15:33