Text FormattingDefining new commands

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
dearleader
Posts: 3
Joined: Fri Nov 27, 2009 10:19 pm

Defining new commands

Post by dearleader »

Hello,

I was wondering if someone could help me with the following problem. I am trying to define a new command \bf so that \bf{a} gives \textcolor{red}{\textbf{a}}. So far I have defined

\renewcommand{\bf}{\textbf} so that \bf{a} gives \textbf{a}.

but i don't know how to incorporate the \textcolor into this. Since I used \bf{a} extensively throughout my document already, i was hoping someone knows a way to incorporate the \textcolor into this without me having to chance \bf{a} to something else througout my document.

Thank you in advance,

Jong-il

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Defining new commands

Post by frabjous »

\textbf, unlike \bf, has an argument. Thus, you should use the following syntax:

\renewcommand{\bf}[1]{\textbf{#1}}

I think you'd be better served, however, by using a new name, to avoid conflicts... pick any name you haven't used yet:

\newcommand{\mybf}[1]{\textbf{#1}}

Color is not hard. Load the xcolor package:

\usepackage{xcolor}

And then you can use:

\newcommand{\redbf}[1]{\textcolor{red}{\textbf{#1}}}

(Or use renewcommand if needed, etc.)

I'm using red, but change that to whatever, as specified in the xcolor documentation.

I don't see the problem with your having already used \bf throughout the document. Doesn't your editor have a Find and Replace command?
Post Reply