Text Formatting ⇒ One command for "bold" both in text and math mode
One command for "bold" both in text and math mode
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
- svend_tveskaeg
- Posts: 478
- Joined: Sun Jul 12, 2009 5:31 am
One command for "bold" both in text and math mode
-- Zapp Brannigan, Futurama (season 1, episode 4)
One command for "bold" both in text and math mode
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
Thanks to all.
- localghost
- Site Moderator
- Posts: 9202
- 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}
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10