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\expandafter{\the\everymath\let(^^A\let)^^B}
\everydisplay\expandafter{\the\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\expandafter{\the\everymath\let(^^A\let)^^B}
\everydisplay\expandafter{\the\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}
Make a copy of alpha.bst
and call it myalpha.bst
. In myalpha.bst
, search for
FUNCTION {format.title}
{ title empty$
{ "" }
{ title "t" change.case$ }
if$
}
and replace it with
FUNCTION {format.title}
{ title empty$
{ "" }
{ title emphasize "t" change.case$ }
if$
}
Note that addition of emphasize
.
Now search for
FUNCTION {article}
{ output.bibitem
format.authors "author" output.check
new.block
format.title "title" output.check
new.block
crossref missing$
{ journal emphasize "journal" output.check
format.vol.num.pages output
format.date "year" output.check
}
{ format.article.crossref output.nonnull
format.pages output
}
if$
new.block
note output
fin.entry
}
and replace with
FUNCTION {article}
{ output.bibitem
format.authors "author" output.check
new.block
format.title "title" output.check
new.block
crossref missing$
{ journal "journal" output.check
format.vol.num.pages output
format.date "year" output.check
}
{ format.article.crossref output.nonnull
format.pages output
}
if$
new.block
note output
fin.entry
}
Here, emphasize
is removed from the line: journal emphasize "journal" output.check
to prevent journal title from becoming emphasized.
Don't forget to use \bibliographystyle{myalpha}
.
Code:
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{Master.bib}
@book {Bre89,
AUTHOR = {Bressoud, David M.},
TITLE = {{Factorization and Primality Testing}},
SERIES = {Undergraduate Texts in Mathematics},
PUBLISHER = {Springer-Verlag},
ADDRESS = {New York},
YEAR = {1989},
}
@article {CEP83,
AUTHOR = {Canfield, E. R. and Erd{\H{o}}s, Paul and Pomerance, Carl},
TITLE = {On a problem of {O}ppenheim concerning ``factorisatio
numerorum''},
JOURNAL = {J. Number Theory},
FJOURNAL = {Journal of Number Theory},
VOLUME = {17},
YEAR = {1983},
NUMBER = {1},
PAGES = {1--28},
}
\end{filecontents*}
\begin{document}
I cite ~\cite{Bre89}.
\nocite{*}
\bibliography{Master}
\bibliographystyle{myalpha}
\end{document}
Follow the same strategy to add/remove emphasizing/removing emphasis as your wish.
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
.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 latestxparse
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 turnsemph~
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).