Text Formatting ⇒ One command for "bold" both in text and math mode
One command for "bold" both in text and math mode
How can I define one new command to have the text formatted in bold both in math and in text mode?
Last edited by Alextorm on Tue Nov 23, 2010 7:17 pm, edited 1 time in total.
- svend_tveskaeg
- Posts: 478
- Joined: Sun Jul 12, 2009 5:31 am
One command for "bold" both in text and math mode
Why a single command? I would simply use \textbf for bold text and \mathbf for bold mathematics.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
-- Zapp Brannigan, Futurama (season 1, episode 4)
One command for "bold" both in text and math mode
I agree it can be useful sometimes. I sometimes put the following in my preamble:
This code adds an additional \boldmath call to the \textbf command, making all math within a \textbf{} bold. Of course, if you don't want to overwrite \textbf, you can define a new command:
Yori
Code: Select all
\let\oldtextbf=\textbf
\renewcommand\textbf[1]{{\boldmath\oldtextbf{#1}}}
Code: Select all
\newcommand\allbold[1]{{\boldmath\textbf{#1}}}
Re: One command for "bold" both in text and math mode
I had in mind something like an "if-then" construction ("if math environment do math bold, if text environment do text bold"), but yoriz solution is just perfect for me.
Thanks to all.
Thanks to all.
- localghost
- Site Moderator
- Posts: 9201
- Joined: Fri Feb 02, 2007 12:06 pm
One command for "bold" both in text and math mode
You can implement it in exactly that way.Alextorm wrote:I had in mind something like an "if-then" construction ("if math environment do math bold, if text environment do text bold"), but yoriz solution is just perfect for me.[…]
Code: Select all
\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\newcommand*{\genbf}[1]{\ifmmode\mathbf{#1}\else\textbf{#1}\fi}
\begin{document}
\genbf{In-line text}
\[
\genbf{Math}
\]
\end{document}
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]
¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
Board Rules
Avoidable Mistakes[/size]
¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1