Question
Is it possible to write a conditional statement for commands that change them based on where they appear in the document?
Example Situation
When command appears in the body, it should be
- bold and black in color.
When it appears in a heading/title (sectioning commands: \section \subsection, \paragraph
etc.),
- make it bold and red.
In the following code, I use the command \keyword
in the heading \section
and in the body. I would like to appearance of the text to change based on where it is found. This means I would need access to two conditions:
- for any type of sectioning command
- for the body
Sample Code
\documentclass{article}
\usepackage{fontspec}
\usepackage{xcolor}
\newcommand{\keyword}[1]{\textbf{#1}}
\begin{document}
\section{Product \keyword{rabunza}}
You can find the information about \keyword{rabunza} on our website.
\end{document}
Question Extension
I have extended this question here to include titlesec/titletoc/tocloft
compatibility.