2

I would like to see the following in my latex file: once I use the \textit{...} command, I would like to see that this text does not only get the italics font, but also gets the colour blue. I want to apply this on the whole document. Instead of having to specify it for every part of text that should get this font, is there a way I can specify it in the beginning of the document such that it is applied to the whole doc? Basically I want to change the default properties of the \textit{...} command.

2
  • 5
    Well you can. But it would be better to define a semantic command, e.g. \myemph which sets its argument in italic and blue and to use this than to redefine \textit. Feb 19, 2018 at 10:05
  • In case you really, really want to redefine \textit which I strongly advise against, see: tex.stackexchange.com/questions/47351/… Feb 19, 2018 at 10:15

2 Answers 2

2

This is very easy with (Xe|Lua)LaTeX:

\documentclass{article}

\usepackage{fontspec}
\usepackage{xcolor}

\setmainfont{Latin Modern Roman}[
  ItalicFeatures={Color=blue},
]

\begin{document}

Some text \emph{emphasized} and \textit{in italic}.

\end{document}

enter image description here

With pdflatex it's a bit more complicated:

\documentclass{article}

\usepackage{xcolor}

\makeatletter
\DeclareRobustCommand{\itshape}{%
  \not@math@alphabet\itshape\mathit
  \fontshape\itdefault\selectfont
  \color{blue}%
}
\makeatother

\begin{document}

Some text \emph{emphasized} and \textit{in italic}.

\end{document}

Be careful of not using \itshape between paragraphs, though.

0
1

Here's a command, called \coloremph, which builds on the \emph to allow the emphasized material to be rendered in a color. The default color is blue, but that this may be overridden by providing a different color in the optional argument of \coloremph.

With this setup, any "inner" emphasized material will be rendered in the upright font shape, but with the color of the surrounding emphasized material. Uncomment the directive

%\renewcommand\eminnershape{\upshape\color{black}} % optional

if you want the inner emphasized material to be typeset in black.

Here's the full MWE (minimum working example):

\documentclass{article}
\usepackage[dvipsnames,svgnames,x11names]{xcolor} % for lots of predefined color names
\newcommand\coloremph[2][blue]{\textcolor{#1}{\emph{#2}}}
%\renewcommand\eminnershape{\upshape\color{black}} % optional

\begin{document}
Hello, World.

\coloremph{Once upon a \emph{very strange} time, \dots}

\coloremph[Coral3]{Once upon a \emph{very strange} time, \dots}

\coloremph[MediumPurple]{Once upon a \emph{very strange} time, \dots}

Hello World.
\end{document}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .