重新定義格式化命令以新增顏色

重新定義格式化命令以新增顏色

我正在編寫一份文檔,我希望所有粗體文字都是紅色。我想知道如何才能將renewcommand命令textbf包含在 中\textcolor{red}

謝謝

答案1

預設定義textbf

\DeclareTextFontCommand{\textbf}{\bfseries}

要添加新功能,您可以簡單地添加\color{red}

\DeclareTextFontCommand{\textbf}{\bfseries\color{red}}

\DeclareTextFontCommand覆蓋原始定義而不會出現錯誤。您只能透過以下方式獲得資訊\@latex@info

這是完整的 MWE:

\documentclass[]{article}

\usepackage[T1]{fontenc}
\usepackage{xcolor}
\DeclareTextFontCommand{\textbf}{\bfseries\color{red}}
\begin{document}
text \textbf{foo} bar
\end{document}

在此輸入影像描述

相關內容